Re: [Mesa-dev] Lets talk about autotools
On Thu, 2018-09-20 at 15:56 +0100, Eric Engestrom wrote: > On Thursday, 2018-09-20 15:28:09 +0100, Emil Velikov wrote: > > Hi Chuck, > > > > On 18 September 2018 at 16:00, Chuck Atkins < > > chuck.atk...@kitware.com> wrote: > > > First, I'm fully in support of killing off autotools woo-hoo to > > > that. And > > > given the substantial investment already put into the meson build > > > that > > > certainly seems like a good direction to go. > > > > > > That being said, the way "auto" is currently implemented leaves > > > quite a bit > > > to be desired. One of the nice features of the Autotools build > > > was how > > > auto-enabled options were treated in that the dependencies were > > > searched for > > > and if they were all found and met then the option would be > > > enabled. My > > > experience so far with the meson build has shown this not to be > > > the case and > > > a "configure" with no options has yet to be successful for > > > me. Many of the > > > 'auto' options are treated as 'set to true if your platform > > > supports it' > > > regardless of whether your system has the requisite dependencies > > > available. > > > For example" > > > > > > The 'gallium-va' option defaults to 'auto' but the implementation > > > ends up > > > setting the '_va' option to true if the other option conditions > > > are met, > > > long before libva is searched for. So then when libva isn't > > > found one gets > > > an error. > > > > > > if set to auto then missing the libva dependencies should be a > > > failure, it > > > should just disable the gallium va state tracker > > > > > > The platform options set to 'auto' has a set of checks to > > > determine which > > > platforms are enabled as required. If the system_has_kms_drm > > > check is true > > > then Wayland is enabled as required. Later if the check for > > > wayland > > > dependencies fails, an error occurs. > > > > > > If platforms are set to auto then a failure to locate > > > dependencies for a > > > given platform should disable the platform. > > > > > > I realize these are just two specific examples, each of which can > > > be readily > > > dealt with in their own specific way so I'm not asking "how to I > > > address #1 > > > and #2?" because I can certainly do that. These are just two > > > instances of > > > many though in the way "auto" is dealt with. My point is really > > > a broader > > > one that before meson becomes the primary build then the behavior > > > of "auto" > > > should create a successful configure out of the box without > > > additional > > > options. > > > > > > > I would like to revive an idea from a few years ago: > > Drop the "auto" all-together. > > > > It adds a _ton_ of complexity while making the build semi- > > magical/not > > as deterministic. > > IIRC the Gnome people have been actively working for removing such > > autodetection in their packages. > > > > The only downside is that we may need to tweak our scripts _once_ > > to > > list exactly what we want to build ;-) > > _Once_ for you, because you have everything already set up, but for > all > the new users this means that nothing will work out of the box, > they'll > need to understand each and every options and figure out what they > need > them set to, before they can even start. > > That sounds like a huge step backwards to me :/ Meson has a great feature called… "features". The way it works is you have options which can be either enabled, disabled or "auto". This way, those optional parts of the build can be built automatically by default if the required dependencies are present, or skipped if not, which seems to be what you want. However, meson then has a --auto-features option which allows build integrators to get deterministic, reproducible builds by removing the automatic enabling/disabling based on dependencies. Which seems like it can reconcile what you and Emil want? :) More details here: http://mesonbuild.com/Build-options.html#features As a build integrator myself at the Freedesktop SDK project, I would love Mesa to make good use of this. We regularly have issues due to this automatic behaviour, because we forgot a dependency or added one by mistake. -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] Lets talk about autotools
On Mon, 2018-09-17 at 20:56 -0400, Ilia Mirkin wrote: > I'd also encourage writing a new "configure" script which > echo's instructions on how to operate meson -- it's really not > obvious, with alternating --prefix=bla -Dfoo=bla argument styles. > People know how to use autotools, but meson is a fairly new thing. During its (still unfinished) transition to Meson, the GNOME project has successfully used configure scripts for compatibility with the autotools build API. See this one for example: https://gitlab.gnome.org/GNOME/json-glib/blob/8b6c216d60e1d54d9314c00931131fbfa7d15563/configure With this, you can keep doing the usual ./configure; make; make install dance and it uses Meson and Ninja under the hood (configure options are translated to meson options, some work might be needed for custom options) It was used to not block the migration to Meson, yet keep building on those platforms which didn't have Meson yet. Maybe a similar transition could work for Mesa, temporarily? Hope that helps, -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] Lets talk about autotools
desOn Mon, 2018-09-17 at 10:11 -0700, Matt Turner wrote: > On Mon, Sep 17, 2018 at 9:46 AM Dylan Baker > wrote: > > > > I feel like for !windows meson is in good enough shape at this > > point that we can start having the discussion about deleting the > > autotools build. > > So, is there anything left that autotools can do that meson cannot > > (that we actually want to implement)? And, what is a reasonable > > time-table to remove the autotools build? > > I think we could reasonably remove it as soon as 18.3 if others > > felt confident that it would work for them. > > Deleting autotools after 18.3 seems like a safe choice to me. > > Gentoo has successfully switched to building Mesa with Meson in > 18.2.0. For what it's worth, over at Freedesktop Sdk [1] we have been building Mesa with Meson successfully since the very beginning. (we started with 18.1.5) We're not going to miss the Autotools. (we're just looking forward to 18.3 so we can build Mesa without Python 2. :) ) [1] https://gitlab.com/freedesktop-sdk/freedesktop-sdk/ -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/3] configure: allow building with python3
Hi, On Thu, 2018-08-23 at 23:23 -0400, Ilia Mirkin wrote: > This breaks the build for me. It selects python3 instead of python2, > and gen_xmlpool.py bails out when trying to print \xf3 to stdout with > a LANG=C locale. In general though, Python 3 works very badly with LANG=C. Upstream Python recommends just not using LANG=C at all, and instead using a UTF8 locale, like C.UTF-8 instead. In fact, starting with 3.7, Python will emit a big warning when it is run on a non-UTF8 locale, and try to fallback to C.UTF-8 if it can. There might be something to fix in this case (I haven't had time to look at it yet), but I'd still advise you try and use a UTF8 locale when running Python scripts in the future, if at all possible. -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH] python: Remove shebang and executable bit
Since the script is never executed directly, but launched by Meson as an argument to the Python interpreter, those are not needed any more. In addition, they are the reason this script was missed when I moved the Meson buildsystem to Python 3, so removing them helps avoiding future confusion. --- bin/install_megadrivers.py | 1 - 1 file changed, 1 deletion(-) mode change 100755 => 100644 bin/install_megadrivers.py diff --git a/bin/install_megadrivers.py b/bin/install_megadrivers.py old mode 100755 new mode 100644 index 551e385d1a5..d29b1911218 --- a/bin/install_megadrivers.py +++ b/bin/install_megadrivers.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # encoding=utf-8 # Copyright © 2017-2018 Intel Corporation -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] meson: Run the install script with Python 3
On Wed, 2018-08-22 at 16:18 +0100, Emil Velikov wrote: > On 22 August 2018 at 15:42, Mathieu Bridon > wrote: > > On Wed, 2018-08-22 at 15:17 +0100, Emil Velikov wrote: > > > On 22 August 2018 at 13:09, Mathieu Bridon > > > wrote: > > > > The script was being run directly as an executable, and it has > > > > a > > > > Python 2 shebang. > > > > > > Please drop the execute bit and shebang - be that with this or a > > > separate patch. > > > > That would require modifying the other build systems as well, so > > it's probably better to wait for your AM_PATH_PYTHON patches to be > > merged. > > > > Not quite - the script is used solely by meson, and the > AM_PATH_PYTHON stuff is for autoconf ;-) You're right, a quick grep revealed the script appearing in Makefile.am, and I assumed it was used by the autotools. However, that's only to add it to the dist, so yeah, it's meson-only. I'll send a followup patch. -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] meson: Run the install script with Python 3
On Wed, 2018-08-22 at 15:17 +0100, Emil Velikov wrote: > On 22 August 2018 at 13:09, Mathieu Bridon > wrote: > > The script was being run directly as an executable, and it has a > > Python 2 shebang. > > Please drop the execute bit and shebang - be that with this or a > separate patch. That would require modifying the other build systems as well, so it's probably better to wait for your AM_PATH_PYTHON patches to be merged. -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH v3 2/2] meson: Use python3 to run glsl tests
Reviewed-by: Mathieu Bridon On Fri, 2018-08-17 at 11:07 -0700, Dylan Baker wrote: > --- > src/compiler/glsl/tests/meson.build | 11 --- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/src/compiler/glsl/tests/meson.build > b/src/compiler/glsl/tests/meson.build > index fc7b863a278..2a41e30a28d 100644 > --- a/src/compiler/glsl/tests/meson.build > +++ b/src/compiler/glsl/tests/meson.build > @@ -84,8 +84,10 @@ test( > ) > > test( > - 'glsl compiler warnings', find_program('warnings_test.py'), > + 'glsl compiler warnings', > + prog_python, >args : [ > +join_paths(meson.current_source_dir(), 'warnings_test.py'), > '--glsl-compiler', glsl_compiler, > '--test-directory', join_paths( >meson.source_root(), 'src', 'compiler', 'glsl', 'tests', > 'warnings' > @@ -94,6 +96,9 @@ test( > ) > test( >'glsl optimization', > - find_program('optimization_test.py'), > - args : ['--test-runner', glsl_test], > + prog_python, > + args : [ > +join_paths(meson.current_source_dir(), 'optimization_test.py'), > +'--test-runner', glsl_test > + ], > ) ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH v3 1/2] compiler/glsl/tests: Make tests python3 safe
I just learned I was supposed to send this :) Reviewed-by: Mathieu Bridon On Fri, 2018-08-17 at 11:07 -0700, Dylan Baker wrote: > v2: - explicitly decode the output of subprocesses > - handle bytes and string types consistently rather than relying > on > python 2's coercion for bytes and ignoring them in python 3 > v3: - explicitly set encode as well as decode > - python 2.7 and 3.x `bytes` instead of defining an alias > --- > src/compiler/glsl/tests/lower_jump_cases.py | 2 +- > src/compiler/glsl/tests/optimization_test.py | 6 -- > src/compiler/glsl/tests/sexps.py | 11 +-- > 3 files changed, 14 insertions(+), 5 deletions(-) > > diff --git a/src/compiler/glsl/tests/lower_jump_cases.py > b/src/compiler/glsl/tests/lower_jump_cases.py > index b50ab734798..1977f3a9b4f 100644 > --- a/src/compiler/glsl/tests/lower_jump_cases.py > +++ b/src/compiler/glsl/tests/lower_jump_cases.py > @@ -54,7 +54,7 @@ def make_test_case(f_name, ret_type, body): > else: > make_declarations(s, already_declared) > make_declarations(body) > -return declarations.values() + \ > +return list(declarations.values()) + \ > [['function', f_name, ['signature', ret_type, > ['parameters'], body]]] > > > diff --git a/src/compiler/glsl/tests/optimization_test.py > b/src/compiler/glsl/tests/optimization_test.py > index 577d2dfc20f..b3147ed08fc 100755 > --- a/src/compiler/glsl/tests/optimization_test.py > +++ b/src/compiler/glsl/tests/optimization_test.py > @@ -1,4 +1,4 @@ > -#!/usr/bin/env python2 > +#!/usr/bin/env python > # encoding=utf-8 > # Copyright © 2018 Intel Corporation > > @@ -71,7 +71,9 @@ def main(): > stdout=subprocess.PIPE, > stderr=subprocess.PIPE, > stdin=subprocess.PIPE) > -out, err = proc.communicate(source) > +out, err = proc.communicate(source.encode('utf-8')) > +out = out.decode('utf-8') > +err = err.decode('utf-8') > if err: > print('FAIL') > print('Unexpected output on stderr: {}'.format(err), > diff --git a/src/compiler/glsl/tests/sexps.py > b/src/compiler/glsl/tests/sexps.py > index a714af8d236..7939b42f9a2 100644 > --- a/src/compiler/glsl/tests/sexps.py > +++ b/src/compiler/glsl/tests/sexps.py > @@ -28,6 +28,11 @@ > # as ['constant', 'float', ['1.00']]. > > import re > +import sys > +if sys.version_info >= (3, 0, 0): > +STRING_TYPE = str > +else: > +STRING_TYPE = unicode > > def check_sexp(sexp): > """Verify that the argument is a proper sexp. > @@ -39,7 +44,7 @@ def check_sexp(sexp): > if isinstance(sexp, list): > for s in sexp: > check_sexp(s) > -elif not isinstance(sexp, basestring): > +elif not isinstance(sexp, (STRING_TYPE, bytes)): > raise Exception('Not a sexp: {0!r}'.format(sexp)) > > def parse_sexp(sexp): > @@ -70,8 +75,10 @@ def sexp_to_string(sexp): > """Convert a sexp, represented as nested lists containing > strings, > into a single string of the form parseable by mesa. > """ > -if isinstance(sexp, basestring): > +if isinstance(sexp, STRING_TYPE): > return sexp > +if isinstance(sexp, bytes): > +return sexp.encode('utf-8') > assert isinstance(sexp, list) > result = '' > for s in sexp: ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH] meson: Run the install script with Python 3
The script was being run directly as an executable, and it has a Python 2 shebang. --- src/gallium/targets/dri/meson.build | 1 + src/gallium/targets/va/meson.build| 1 + src/gallium/targets/vdpau/meson.build | 1 + src/gallium/targets/xvmc/meson.build | 1 + src/mesa/drivers/dri/meson.build | 1 + 5 files changed, 5 insertions(+) diff --git a/src/gallium/targets/dri/meson.build b/src/gallium/targets/dri/meson.build index e3202c99678..51940a2f350 100644 --- a/src/gallium/targets/dri/meson.build +++ b/src/gallium/targets/dri/meson.build @@ -84,6 +84,7 @@ foreach d : [[with_gallium_pl111, 'pl111_dri.so'], endforeach meson.add_install_script( + prog_python.path(), join_paths(meson.source_root(), 'bin/install_megadrivers.py'), libgallium_dri.full_path(), dri_drivers_path, diff --git a/src/gallium/targets/va/meson.build b/src/gallium/targets/va/meson.build index 57d267e5b6e..ded689b464d 100644 --- a/src/gallium/targets/va/meson.build +++ b/src/gallium/targets/va/meson.build @@ -62,6 +62,7 @@ foreach d : [[with_gallium_r600, 'r600'], endforeach meson.add_install_script( + prog_python.path(), join_paths(meson.source_root(), 'bin/install_megadrivers.py'), libva_gallium.full_path(), va_drivers_path, diff --git a/src/gallium/targets/vdpau/meson.build b/src/gallium/targets/vdpau/meson.build index 93969d8399b..005cf642498 100644 --- a/src/gallium/targets/vdpau/meson.build +++ b/src/gallium/targets/vdpau/meson.build @@ -65,6 +65,7 @@ foreach d : [[with_gallium_r300, 'r300'], endforeach meson.add_install_script( + prog_python.path(), join_paths(meson.source_root(), 'bin/install_megadrivers.py'), libvdpau_gallium.full_path(), vdpau_drivers_path, diff --git a/src/gallium/targets/xvmc/meson.build b/src/gallium/targets/xvmc/meson.build index 2bf5ea23091..0af5b6477ce 100644 --- a/src/gallium/targets/xvmc/meson.build +++ b/src/gallium/targets/xvmc/meson.build @@ -56,6 +56,7 @@ foreach d : [[with_gallium_r600, 'r600'], [with_gallium_nouveau, 'nouveau']] endforeach meson.add_install_script( + prog_python.path(), join_paths(meson.source_root(), 'bin/install_megadrivers.py'), libxvmc_gallium.full_path(), xvmc_drivers_path, diff --git a/src/mesa/drivers/dri/meson.build b/src/mesa/drivers/dri/meson.build index 943727b662a..d98c823f5fe 100644 --- a/src/mesa/drivers/dri/meson.build +++ b/src/mesa/drivers/dri/meson.build @@ -57,6 +57,7 @@ if dri_drivers != [] ) meson.add_install_script( +prog_python.path(), join_paths(meson.source_root(), 'bin/install_megadrivers.py'), libmesa_dri_drivers.full_path(), dri_drivers_path, -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 3/3] meson: Run the test with Python 3
On Fri, 2018-08-17 at 12:54 -0700, Dylan Baker wrote: > Quoting Mathieu Bridon (2018-08-17 12:32:18) > > --- > > src/compiler/glsl/glcpp/meson.build | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/src/compiler/glsl/glcpp/meson.build > > b/src/compiler/glsl/glcpp/meson.build > > index 09d44ddd687..769406f5331 100644 > > --- a/src/compiler/glsl/glcpp/meson.build > > +++ b/src/compiler/glsl/glcpp/meson.build > > @@ -64,8 +64,9 @@ if with_tests > >foreach m : modes > > test( > >'glcpp test (@0@)'.format(m), > > - find_program('tests/glcpp_test.py'), > > + prog_python, > >args : [ > > +join_paths(meson.current_source_dir(), > > 'tests/glcpp_test.py'), > > glcpp, join_paths(meson.current_source_dir(), 'tests'), > > '--@0@'.format(m), > >], > > -- > > 2.17.1 > > > > Is it okay with you if I just squash this patch and the one in my > series into a > single patch? Sure, no problem. -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 3/3] meson: Run the test with Python 3
--- src/compiler/glsl/glcpp/meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/glsl/glcpp/meson.build b/src/compiler/glsl/glcpp/meson.build index 09d44ddd687..769406f5331 100644 --- a/src/compiler/glsl/glcpp/meson.build +++ b/src/compiler/glsl/glcpp/meson.build @@ -64,8 +64,9 @@ if with_tests foreach m : modes test( 'glcpp test (@0@)'.format(m), - find_program('tests/glcpp_test.py'), + prog_python, args : [ +join_paths(meson.current_source_dir(), 'tests/glcpp_test.py'), glcpp, join_paths(meson.current_source_dir(), 'tests'), '--@0@'.format(m), ], -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 2/3] python: Disable universal newlines
We are testing the behaviour of a tool, for different input files, each one using a different newline sequence. ('\n' on UNIX, '\r\n' on Windows, …) Unfortunately, when opening a file in text mode, Python 3 will by default enable the "universal newlines" mode, which means it replaces all the known newline sequences by '\n'. This (usually useful) behaviour breaks the tests, which are specifically trying to handle files with newline sequences different from '\n'. Disabling the universal newlines mode fixes the tests. However, to keep the script compatible with both Python 2 and 3, we must use the io.open() function instead of the open() builtin, as the latter only knows about the `newline` argument on Python 3. --- src/compiler/glsl/glcpp/tests/glcpp_test.py | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/compiler/glsl/glcpp/tests/glcpp_test.py b/src/compiler/glsl/glcpp/tests/glcpp_test.py index e27391093cf..1481eed6188 100755 --- a/src/compiler/glsl/glcpp/tests/glcpp_test.py +++ b/src/compiler/glsl/glcpp/tests/glcpp_test.py @@ -46,7 +46,10 @@ def arg_parser(): def parse_test_file(filename, nl_format): """Check for any special arguments and return them as a list.""" -with open(filename) as f: +# Disable "universal newlines" mode; we can't directly use `nl_format` as +# the `newline` argument, because the "bizarro" test uses something Python +# considers invalid. +with io.open(filename, newline='') as f: for l in f.read().split(nl_format): if 'glcpp-args:' in l: return l.split('glcpp-args:')[1].strip().split() -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 1/3] python: difflib prefers unicode strings
Python 3 does not automatically convert from bytes to unicode strings like Python 2 used to do. This commit makes sure we pass unicode strings to difflib.unified_diff, so that the script works on both Python 2 and 3. --- src/compiler/glsl/glcpp/tests/glcpp_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/glsl/glcpp/tests/glcpp_test.py b/src/compiler/glsl/glcpp/tests/glcpp_test.py index 8ac5d7cb0a1..e27391093cf 100755 --- a/src/compiler/glsl/glcpp/tests/glcpp_test.py +++ b/src/compiler/glsl/glcpp/tests/glcpp_test.py @@ -64,8 +64,9 @@ def test_output(glcpp, filename, expfile, nl_format='\n'): stderr=subprocess.STDOUT, stdin=subprocess.PIPE) actual, _ = proc.communicate(f.read()) +actual = actual.decode('utf-8') -with open(expfile, 'rb') as f: +with open(expfile, 'r') as f: expected = f.read() if actual == expected: -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 1/2] compiler/glsl/tests: Make tests python3 safe
On Fri, 2018-08-17 at 10:45 -0700, Dylan Baker wrote: > Quoting Mathieu Bridon (2018-08-16 15:00:39) > > On Thu, 2018-08-16 at 14:21 -0700, Dylan Baker wrote: > > > --- > > > > > > I didn't see any patches from anyone else, so I wrote some real > > > quick. Please > > > point to them if other patches already exist. > > > > I was about to send mine, but you were faster. >_< > > > > They ar every similar though, except that you missed glcpp_test.py, > > which requires a few more changes. (I have them ready, and can send > > them separately) > > > > > diff --git a/src/compiler/glsl/tests/optimization_test.py > > > b/src/compiler/glsl/tests/optimization_test.py > > > index 577d2dfc20f..f40d0cee6bd 100755 > > > --- a/src/compiler/glsl/tests/optimization_test.py > > > +++ b/src/compiler/glsl/tests/optimization_test.py > > > @@ -1,4 +1,4 @@ > > > -#!/usr/bin/env python2 > > > +#!/usr/bin/env python > > > # encoding=utf-8 > > > # Copyright © 2018 Intel Corporation > > > > > > @@ -71,7 +71,9 @@ def main(): > > > stdout=subprocess.PIPE, > > > stderr=subprocess.PIPE, > > > stdin=subprocess.PIPE) > > > -out, err = proc.communicate(source) > > > +out, err = proc.communicate(source.encode()) > > > +out = out.decode() > > > +err = err.decode() > > > > I usually find it too unpredictable to use the default encoding, > > and > > prefer always specifying 'utf-8'. (even on Python 3, you can't be > > sure > > that will always be the default) > > That's true I guess. I've never seen anyone build python with utf-8 > as not the default, but they can so we should do the right thing. That's not a build-time thing though: $ python3 -c 'print("é".encode())' b'\xc3\xa9' $ LC_ALL=C python3 -c 'print("é".encode())' Unable to decode the command from the command line: UnicodeEncodeError: 'utf-8' codec can't encode characters in position 7-8: surrogates not allowed This happens regularly in some containers-like environment or SSH-ing to a server which doesn't have your client locale. -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH v2 1/2] compiler/glsl/tests: Make tests python3 safe
On Fri, 2018-08-17 at 10:51 -0700, Dylan Baker wrote: > diff --git a/src/compiler/glsl/tests/optimization_test.py > b/src/compiler/glsl/tests/optimization_test.py > index 577d2dfc20f..65bac676963 100755 > --- a/src/compiler/glsl/tests/optimization_test.py > +++ b/src/compiler/glsl/tests/optimization_test.py > @@ -1,4 +1,4 @@ > -#!/usr/bin/env python2 > +#!/usr/bin/env python > # encoding=utf-8 > # Copyright © 2018 Intel Corporation > > @@ -71,7 +71,9 @@ def main(): > stdout=subprocess.PIPE, > stderr=subprocess.PIPE, > stdin=subprocess.PIPE) > -out, err = proc.communicate(source) > +out, err = proc.communicate(source.encode()) > +out = out.decode('utf-8') > +err = err.decode('utf-8') Shouldn't you also specify the encoding for the source.encode() bit? > diff --git a/src/compiler/glsl/tests/sexps.py > b/src/compiler/glsl/tests/sexps.py > index a714af8d236..09ca96e3be5 100644 > --- a/src/compiler/glsl/tests/sexps.py > +++ b/src/compiler/glsl/tests/sexps.py > @@ -28,6 +28,13 @@ > # as ['constant', 'float', ['1.00']]. > > import re > +import sys > +if sys.version_info >= (3, 0, 0): > +STRING_TYPE = str > +BYTES_TYPE = bytes > +else: > +STRING_TYPE = unicode > +BYTES_TYPE = str Note that "bytes" exists on Python 2 and is an alias to "str": >>> bytes So you don't actually need BYTES_TYPE at all. :) -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] Fix the build on Windows
On Fri, 2018-08-17 at 09:23 -0600, Brian Paul wrote: > On 08/17/2018 09:16 AM, Mathieu Bridon wrote: > > This is follow up to my recent patches which made the Python build > > scripts compatible with both Python 2 and 3, then moved the Meson > > build > > system to using Python 3 for them. > > > > Unfortunately, one thing I hadn't tested was running them on > > Windows, > > where the changes broke the build. > > > > See the exchange with Jose for the details: > > > > https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Farchives%2Fmesa-dev%2F2018-August%2F202847.html&data=02%7C01%7Cbrianp%40vmware.com%7C01cd239cdd5b4b9c156608d604547cd7%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636701158254371166&sdata=nLN%2FkP37AyHSV3z4XwjdhUN3suDGUlfZDxWRWn39WhI%3D&reserved=0 > > > > These 2 patches have already been tested by Jose, who confirms they > > fix > > the issue he countered. > > Do you need one of us to push the patches for you? I do, yes. -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 1/2] python: Help Python 2 print the line
Reviewed-by: Jose Fonseca --- src/util/xmlpool/gen_xmlpool.py | 5 + 1 file changed, 5 insertions(+) diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py index 327709c7f8d..12177dc50f5 100644 --- a/src/util/xmlpool/gen_xmlpool.py +++ b/src/util/xmlpool/gen_xmlpool.py @@ -218,6 +218,11 @@ for line in template: assert len(descMatches) == 0 descMatches = [matchDESC_BEGIN] else: +# In Python 2, stdout expects encoded byte strings, or else it will +# encode them with the ascii 'codec' +if sys.version_info.major == 2: +line = line.encode('utf-8') + print(line, end='') template.close() -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 2/2] python: Open the template as text, with an explicit encoding
In commit bd27203f4d808763ac24ac94eb677cacf3e7cb99 we changed this to open in binary mode, to then explicitly decode the lines with the right encoding. Unfortunately, that broke the build on Windows, where the template file can have '\r\n' as line terminators: opening in binary mode would keep those terminators and break the regexp. We need to go back to text mode, where the "universal newlines" mode takes care of this. However, to fix the initial issue, let's specify the encoding explicitly when opening the file, and make sure it is open in text mode, so we only get unicode strings. Reviewed-by: Jose Fonseca --- src/util/xmlpool/gen_xmlpool.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py index 12177dc50f5..b85df234e70 100644 --- a/src/util/xmlpool/gen_xmlpool.py +++ b/src/util/xmlpool/gen_xmlpool.py @@ -9,6 +9,7 @@ from __future__ import print_function +import io import sys import gettext import re @@ -187,11 +188,9 @@ print("/***\ # Process the options template and generate options.h with all # translations. -template = open (template_header_path, "rb") +template = io.open (template_header_path, mode="rt", encoding='utf-8') descMatches = [] for line in template: -line = line.decode('utf-8') - if len(descMatches) > 0: matchENUM = reENUM.match (line) matchDESC_END = reDESC_END.match (line) -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] Fix the build on Windows
This is follow up to my recent patches which made the Python build scripts compatible with both Python 2 and 3, then moved the Meson build system to using Python 3 for them. Unfortunately, one thing I hadn't tested was running them on Windows, where the changes broke the build. See the exchange with Jose for the details: https://lists.freedesktop.org/archives/mesa-dev/2018-August/202847.html These 2 patches have already been tested by Jose, who confirms they fix the issue he countered. ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] python: Help Python 2 print the line
On Fri, 2018-08-17 at 15:30 +0100, Jose Fonseca wrote: > On 17/08/18 15:26, Mathieu Bridon wrote: > > On Fri, 2018-08-17 at 15:08 +0100, Jose Fonseca wrote: > > > On 17/08/18 15:06, Jose Fonseca wrote: > > > > On 17/08/18 14:52, Jose Fonseca wrote: > > > > > On 17/08/18 14:30, Jose Fonseca wrote: > > > > > > On 17/08/18 14:22, Mathieu Bridon wrote: > > > > > > > --- > > > > > > > Jose, can you test whether this patch fixes your build > > > > > > > issues? > > > > > > > > > > > > > > I don't have access to a Windows machine, and I can't > > > > > > > reproduce your > > > > > > > problem on Linux. > > > > > > > > > > > > > >src/util/xmlpool/gen_xmlpool.py | 5 + > > > > > > >1 file changed, 5 insertions(+) > > > > > > > > > > > > > > diff --git a/src/util/xmlpool/gen_xmlpool.py > > > > > > > b/src/util/xmlpool/gen_xmlpool.py > > > > > > > index 327709c7f8d..12177dc50f5 100644 > > > > > > > --- a/src/util/xmlpool/gen_xmlpool.py > > > > > > > +++ b/src/util/xmlpool/gen_xmlpool.py > > > > > > > @@ -218,6 +218,11 @@ for line in template: > > > > > > >assert len(descMatches) == 0 > > > > > > >descMatches = [matchDESC_BEGIN] > > > > > > >else: > > > > > > > +# In Python 2, stdout expects encoded byte > > > > > > > strings, > > > > > > > or else > > > > > > > it will > > > > > > > +# encode them with the ascii 'codec' > > > > > > > +if sys.version_info.major == 2: > > > > > > > +line = line.encode('utf-8') > > > > > > > + > > > > > > >print(line, end='') > > > > > > >template.close() > > > > > > > > > > > > > > > > > > > It fixes the UnicodeEncodeError. I need to do more testing > > > > > > to > > > > > > see if > > > > > > it fixes all errors. > > > > > > > > > > > > > > > > > > I think we should fix the print(end ..) statemet. In > > > > > > fact, it > > > > > > might > > > > > > be easier to have an helper function (e.g., write() > > > > > > ) which > > > > > > does the > > > > > > sys.version check , utf8 encoding, and print, and use it > > > > > > everywhere > > > > > > print is used now. > > > > > > > > > > > > > > > > > > Jose > > > > > > > > > > > > > > > Unfortunately I still get build failures with your change: > > > > > > > > > > Compiling src\gallium\auxiliary\pipe-loader\pipe_loader.c > > > > > ... > > > > > pipe_loader.c > > > > > c:\hudson\workspace\mesa-msvc\src\gallium\auxiliary\pipe- > > > > > loader\driinfo_gallium.h(2): > > > > > error C2146: syntax error: missing ';' before identifier > > > > > 'gettext' > > > > > c:\hudson\workspace\mesa-msvc\src\gallium\auxiliary\pipe- > > > > > loader\driinfo_gallium.h(2): > > > > > error C2143: syntax error: missing ')' before 'string' > > > > > c:\hudson\workspace\mesa-msvc\src\gallium\auxiliary\pipe- > > > > > loader\driinfo_gallium.h(2): > > > > > error C2143: syntax error: missing '{' before 'string' > > > > > c:\hudson\workspace\mesa-msvc\src\gallium\auxiliary\pipe- > > > > > loader\driinfo_gallium.h(2): > > > > > error C2059: syntax error: 'string' > > > > > c:\hudson\workspace\mesa-msvc\src\gallium\auxiliary\pipe- > > > > > loader\driinfo_gallium.h(2): > > > > > error C2059: syntax error: ')' > > > > > > > > > > whereas if I just revert your > > > > > bd27203f4d808763ac24ac94eb677cacf3e7cb99 > > > > > change these errors go away. > > > > > > > > > > I
Re: [Mesa-dev] [PATCH] python: Help Python 2 print the line
On Fri, 2018-08-17 at 15:08 +0100, Jose Fonseca wrote: > On 17/08/18 15:06, Jose Fonseca wrote: > > On 17/08/18 14:52, Jose Fonseca wrote: > > > On 17/08/18 14:30, Jose Fonseca wrote: > > > > On 17/08/18 14:22, Mathieu Bridon wrote: > > > > > --- > > > > > Jose, can you test whether this patch fixes your build > > > > > issues? > > > > > > > > > > I don't have access to a Windows machine, and I can't > > > > > reproduce your > > > > > problem on Linux. > > > > > > > > > > src/util/xmlpool/gen_xmlpool.py | 5 + > > > > > 1 file changed, 5 insertions(+) > > > > > > > > > > diff --git a/src/util/xmlpool/gen_xmlpool.py > > > > > b/src/util/xmlpool/gen_xmlpool.py > > > > > index 327709c7f8d..12177dc50f5 100644 > > > > > --- a/src/util/xmlpool/gen_xmlpool.py > > > > > +++ b/src/util/xmlpool/gen_xmlpool.py > > > > > @@ -218,6 +218,11 @@ for line in template: > > > > > assert len(descMatches) == 0 > > > > > descMatches = [matchDESC_BEGIN] > > > > > else: > > > > > +# In Python 2, stdout expects encoded byte strings, > > > > > or else > > > > > it will > > > > > +# encode them with the ascii 'codec' > > > > > +if sys.version_info.major == 2: > > > > > +line = line.encode('utf-8') > > > > > + > > > > > print(line, end='') > > > > > template.close() > > > > > > > > > > > > > It fixes the UnicodeEncodeError. I need to do more testing to > > > > see if > > > > it fixes all errors. > > > > > > > > > > > > I think we should fix the print(end ..) statemet. In fact, it > > > > might > > > > be easier to have an helper function (e.g., write() ) which > > > > does the > > > > sys.version check , utf8 encoding, and print, and use it > > > > everywhere > > > > print is used now. > > > > > > > > > > > > Jose > > > > > > > > > Unfortunately I still get build failures with your change: > > > > > >Compiling src\gallium\auxiliary\pipe-loader\pipe_loader.c ... > > > pipe_loader.c > > > c:\hudson\workspace\mesa-msvc\src\gallium\auxiliary\pipe- > > > loader\driinfo_gallium.h(2): > > > error C2146: syntax error: missing ';' before identifier > > > 'gettext' > > > c:\hudson\workspace\mesa-msvc\src\gallium\auxiliary\pipe- > > > loader\driinfo_gallium.h(2): > > > error C2143: syntax error: missing ')' before 'string' > > > c:\hudson\workspace\mesa-msvc\src\gallium\auxiliary\pipe- > > > loader\driinfo_gallium.h(2): > > > error C2143: syntax error: missing '{' before 'string' > > > c:\hudson\workspace\mesa-msvc\src\gallium\auxiliary\pipe- > > > loader\driinfo_gallium.h(2): > > > error C2059: syntax error: 'string' > > > c:\hudson\workspace\mesa-msvc\src\gallium\auxiliary\pipe- > > > loader\driinfo_gallium.h(2): > > > error C2059: syntax error: ')' > > > > > > whereas if I just revert your > > > bd27203f4d808763ac24ac94eb677cacf3e7cb99 > > > change these errors go away. > > > > > > I compared the generated options.h, before/after your change, and > > > it > > > seems the problem is that we're now emitting `gettext(...)` > > > function > > > calls which don't exist on Windows: > > > > > > --- options.h.old 2018-08-17 14:48:09.0 +0100 > > > +++ options.h.new 2018-08-17 14:41:36.0 +0100 > > > @@ -57,101 +57,101 @@ > > >*/ > > > #define DRI_CONF_SECTION_DEBUG \ > > > DRI_CONF_SECTION_BEGIN \ > > > - DRI_CONF_DESC(en,"Debugging") > > > + DRI_CONF_DESC(en,gettext("Debugging")) > > > > > > #define DRI_CONF_NO_RAST(def) \ > > > DRI_CONF_OPT_BEGIN_B(no_rast, def) \ > > > > > > [...] > > > > > > > > > Jose > > > > > > Ok, I have a strong hunch to what's the problem, with your change > > you're > > reading the input as bytes > > > > template = open (template_header_path, "rb") <= > > > > which means that on Windows the lines will have "\r\n" which then > > causes > > all regular expressions to fail (as $ won't match) > > > > And this finally explains why this afeccts some systems but not > > others: > > it depends on whether git clones t_options.h with CRLF or LF The thing is, the old code would do: template = open (template_header_path, "r") for line in template: … In my testing, with Python 2 the lines **already** end with "\r\n", so I don't see how this could have worked before. :-/ -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH] python: Help Python 2 print the line
--- Jose, can you test whether this patch fixes your build issues? I don't have access to a Windows machine, and I can't reproduce your problem on Linux. src/util/xmlpool/gen_xmlpool.py | 5 + 1 file changed, 5 insertions(+) diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py index 327709c7f8d..12177dc50f5 100644 --- a/src/util/xmlpool/gen_xmlpool.py +++ b/src/util/xmlpool/gen_xmlpool.py @@ -218,6 +218,11 @@ for line in template: assert len(descMatches) == 0 descMatches = [matchDESC_BEGIN] else: +# In Python 2, stdout expects encoded byte strings, or else it will +# encode them with the ascii 'codec' +if sys.version_info.major == 2: +line = line.encode('utf-8') + print(line, end='') template.close() -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH v3] python: Rework bytes/unicode string handling
On Fri, 2018-08-17 at 13:29 +0100, Jose Fonseca wrote: > This change caused one of our MSVC build machines to fail with > > scons: Building targets ... >Generating build\windows-x86-debug\util\xmlpool\options.h ... > Traceback (most recent call last): >File "src\util\xmlpool\gen_xmlpool.py", line 221, in > print(line, end='') > UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' > in > position 68: ordinal not in range(128) > scons: *** [build\windows-x86-debug\util\xmlpool\options.h] Error 1 Argh! I think that's because we're now printing a unicode string. On Python 3 that's the right thing to do, if we printed the encoded byte string we'd get the "b'…'" representation, which we certainly don't want: >>> print(u'août') août >>> print(u'août'.encode('utf-8')) b'ao\xc3\xbbt' But on Python 2, we should really print the byte string though. Python 2 helpfully tries to encode the unicode string automatically, using its default encoding: ASCII. That obviously fails when the string contains non-ascii character. I'll send a patch ASAP. > Setting PYTHONIOENCODING=utf-8 helps, but then bad things still > happen when the output is loaded src/gallium/auxiliary/pipe-loader/ > > > But the fact is that everything was working before. > > > Perhaps a solution is to just start using Python 3 for the > generation scripts, as it might yield more consistent results. That's a possibility, but then it means you need both Python 2 (for Scons) and Python 3 (for the scripts). Requiring 2 Python stacks to build a C codebase is pretty terrible. :-/ -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 1/2] compiler/glsl/tests: Make tests python3 safe
On Thu, 2018-08-16 at 14:21 -0700, Dylan Baker wrote: > --- > > I didn't see any patches from anyone else, so I wrote some real > quick. Please > point to them if other patches already exist. I was about to send mine, but you were faster. >_< They ar every similar though, except that you missed glcpp_test.py, which requires a few more changes. (I have them ready, and can send them separately) > diff --git a/src/compiler/glsl/tests/optimization_test.py > b/src/compiler/glsl/tests/optimization_test.py > index 577d2dfc20f..f40d0cee6bd 100755 > --- a/src/compiler/glsl/tests/optimization_test.py > +++ b/src/compiler/glsl/tests/optimization_test.py > @@ -1,4 +1,4 @@ > -#!/usr/bin/env python2 > +#!/usr/bin/env python > # encoding=utf-8 > # Copyright © 2018 Intel Corporation > > @@ -71,7 +71,9 @@ def main(): > stdout=subprocess.PIPE, > stderr=subprocess.PIPE, > stdin=subprocess.PIPE) > -out, err = proc.communicate(source) > +out, err = proc.communicate(source.encode()) > +out = out.decode() > +err = err.decode() I usually find it too unpredictable to use the default encoding, and prefer always specifying 'utf-8'. (even on Python 3, you can't be sure that will always be the default) > diff --git a/src/compiler/glsl/tests/sexps.py > b/src/compiler/glsl/tests/sexps.py > index a714af8d236..b69d3a5e5d7 100644 > --- a/src/compiler/glsl/tests/sexps.py > +++ b/src/compiler/glsl/tests/sexps.py > @@ -28,6 +28,11 @@ > # as ['constant', 'float', ['1.00']]. > > import re > +import sys > +if sys.version_info >= (3, 0, 0): > +STRINGS = str > +else: > +STRINGS = (str, unicode) > > def check_sexp(sexp): > """Verify that the argument is a proper sexp. > @@ -39,7 +44,7 @@ def check_sexp(sexp): > if isinstance(sexp, list): > for s in sexp: > check_sexp(s) > -elif not isinstance(sexp, basestring): > +elif not isinstance(sexp, STRINGS): > raise Exception('Not a sexp: {0!r}'.format(sexp)) > > def parse_sexp(sexp): > @@ -70,7 +75,7 @@ def sexp_to_string(sexp): > """Convert a sexp, represented as nested lists containing > strings, > into a single string of the form parseable by mesa. > """ > -if isinstance(sexp, basestring): > +if isinstance(sexp, STRINGS): > return sexp Someone on this list ( :P ) once told me to avoid mising bytes and strings. In this case, I believe the patch would be better as follows: -if isinstance(sexp, basestring): +if isinstance(sexp, bytes): +return sexp.decode('utf-8') +if isinstance(sexp, string_type): return sexp And then the previous hunks can be: +if sys.version_info < (3, 0): +string_type = unicode +else: +string_type = str … -elif not isinstance(sexp, basestring): +elif not isinstance(sexp, (string_type, bytes)): -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH v2 9/9] meson: Build with Python 3
Hi Emil, On Thu, 2018-08-16 at 17:11 +0100, Emil Velikov wrote: > On 9 August 2018 at 09:27, Mathieu Bridon > wrote: > > Now that all the build scripts are compatible with both Python 2 > > and 3, we can flip the switch and tell Meson to use the latter. > > > > Since Meson already depends on Python 3 anyway, this means we don't > > need two different Python stacks to build Mesa. > > Just did a quick test of enabling python3 for the autoconf build and > noticed that some parts are not converted to python2+3. > Namely, invoking the following fail. > glsl/tests/optimization-test.sh > glsl/glcpp/tests/glcpp-test.sh > > I'm concerned that this didn't flag as failure with meson Those Bash scripts aren't used anywhere by the meson build. However, the Python scripts that they run are: * src/compiler/glsl/tests/optimization_test.py * src/compiler/glsl/glcpp/tests/glcpp_test.py Both are run directly (they are executables), and their shebang is Python 2. :-/ They just aren't hooked up using prog_python like all the build scripts, so I indeed completely missed them. Are you already porting them over? Otherwise I'll try to have a look ASAP. Thanks, -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH v2 2/5] meson: use python3 module to find python3
On Thu, 2018-08-16 at 11:00 +0100, Eric Engestrom wrote: > On Wednesday, 2018-08-15 09:18:05 -0700, Dylan Baker wrote: > > This handy helper is nice for OSes that are not linux or BSD like > > (mac > > and windows) as it knows how to find python3 in odd places. > > --- > > meson.build | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/meson.build b/meson.build > > index 5dc9b45eb42..c8bac35659f 100644 > > --- a/meson.build > > +++ b/meson.build > > @@ -697,7 +697,7 @@ if with_platform_haiku > >pre_args += '-DHAVE_HAIKU_PLATFORM' > > endif > > > > -prog_python = find_program('python3') > > +prog_python = import('python3').find_python() > > You'll need to bump meson_version to 0.46 if you want to do that; > otherwise you can use the patch I sent last month ;) Unless I missed something, the "python3" module and its find_python() method were added in 0.38.0: http://mesonbuild.com/Python-3-module.html Are you confusing this with the "python" module, which was added in 0.46.0? http://mesonbuild.com/Python-module.html -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH v3] python: Rework bytes/unicode string handling
In both Python 2 and 3, opening a file without specifying the mode will open it for reading in text mode ('r'). On Python 2, the read() method of a file object opened in mode 'r' will return byte strings, while on Python 3 it will return unicode strings. Explicitly specifying the binary mode ('rb') then decoding the byte string means we always handle unicode strings on both Python 2 and 3. Which in turns means all re.match(line) will return unicode strings as well. If we also make expandCString return unicode strings, we don't need the call to the unicode() constructor any more. We were using the ugettext() method because it always returns unicode strings in Python 2, contrarily to the gettext() one which returns byte strings. The ugettext() method doesn't exist on Python 3, so we must use the right method on each version of Python. The last hurdles are that Python 3 doesn't let us concatenate unicode and byte strings directly, and that Python 2's stdout wants encoded byte strings while Python 3's want unicode strings. With these changes, the script gives the same output on both Python 2 and 3. Signed-off-by: Mathieu Bridon --- src/util/xmlpool/gen_xmlpool.py | 41 + 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py index b0db183854..327709c7f8 100644 --- a/src/util/xmlpool/gen_xmlpool.py +++ b/src/util/xmlpool/gen_xmlpool.py @@ -13,6 +13,12 @@ import sys import gettext import re + +if sys.version_info < (3, 0): +gettext_method = 'ugettext' +else: +gettext_method = 'gettext' + # Path to t_options.h template_header_path = sys.argv[1] @@ -60,7 +66,7 @@ def expandCString (s): octa = False num = 0 digits = 0 -r = '' +r = u'' while i < len(s): if not escape: if s[i] == '\\': @@ -128,16 +134,29 @@ def expandMatches (matches, translations, end=None): if len(matches) == 1 and i < len(translations) and \ not matches[0].expand (r'\7').endswith('\\'): suffix = ' \\' -# Expand the description line. Need to use ugettext in order to allow -# non-ascii unicode chars in the original English descriptions. -text = escapeCString (trans.ugettext (unicode (expandCString ( -matches[0].expand (r'\5')), "utf-8"))).encode("utf-8") -print(matches[0].expand (r'\1' + lang + r'\3"' + text + r'"\7') + suffix) +text = escapeCString (getattr(trans, gettext_method) (expandCString ( +matches[0].expand (r'\5' +text = (matches[0].expand (r'\1' + lang + r'\3"' + text + r'"\7') + suffix) + +# In Python 2, stdout expects encoded byte strings, or else it will +# encode them with the ascii 'codec' +if sys.version_info.major == 2: +text = text.encode('utf-8') + +print(text) + # Expand any subsequent enum lines for match in matches[1:]: -text = escapeCString (trans.ugettext (unicode (expandCString ( -match.expand (r'\3')), "utf-8"))).encode("utf-8") -print(match.expand (r'\1"' + text + r'"\5')) +text = escapeCString (getattr(trans, gettext_method) (expandCString ( +match.expand (r'\3' +text = match.expand (r'\1"' + text + r'"\5') + +# In Python 2, stdout expects encoded byte strings, or else it will +# encode them with the ascii 'codec' +if sys.version_info.major == 2: +text = text.encode('utf-8') + +print(text) # Expand description end if end: @@ -168,9 +187,11 @@ print("/***\ # Process the options template and generate options.h with all # translations. -template = open (template_header_path, "r") +template = open (template_header_path, "rb") descMatches = [] for line in template: +line = line.decode('utf-8') + if len(descMatches) > 0: matchENUM = reENUM.match (line) matchDESC_END = reDESC_END.match (line) -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH v2 9/9] meson: Build with Python 3
Now that all the build scripts are compatible with both Python 2 and 3, we can flip the switch and tell Meson to use the latter. Since Meson already depends on Python 3 anyway, this means we don't need two different Python stacks to build Mesa. Signed-off-by: Mathieu Bridon Reviewed-by: Eric Engestrom --- meson.build | 6 ++--- src/amd/common/meson.build| 2 +- src/amd/vulkan/meson.build| 10 +++ src/broadcom/cle/meson.build | 4 +-- src/compiler/glsl/meson.build | 4 +-- src/compiler/meson.build | 2 +- src/compiler/nir/meson.build | 14 +- src/compiler/spirv/meson.build| 4 +-- src/egl/meson.build | 4 +-- src/gallium/auxiliary/meson.build | 6 ++--- src/gallium/drivers/freedreno/meson.build | 2 +- src/gallium/drivers/r600/meson.build | 2 +- src/gallium/drivers/radeonsi/meson.build | 2 +- .../swr/rasterizer/codegen/meson.build| 8 +++--- .../swr/rasterizer/core/backends/meson.build | 4 +-- .../drivers/swr/rasterizer/jitter/meson.build | 6 ++--- src/intel/compiler/meson.build| 2 +- src/intel/genxml/meson.build | 6 ++--- src/intel/isl/meson.build | 2 +- src/intel/vulkan/meson.build | 10 +++ src/mapi/es1api/meson.build | 2 +- src/mapi/es2api/meson.build | 2 +- src/mapi/glapi/gen/meson.build| 26 +-- src/mapi/shared-glapi/meson.build | 2 +- src/mesa/drivers/dri/i965/meson.build | 2 +- src/mesa/main/meson.build | 6 ++--- src/mesa/meson.build | 6 ++--- src/meson.build | 2 +- src/util/meson.build | 2 +- src/util/xmlpool/meson.build | 2 +- src/vulkan/util/meson.build | 2 +- 31 files changed, 77 insertions(+), 77 deletions(-) diff --git a/meson.build b/meson.build index 334cf96ae7..7436164946 100644 --- a/meson.build +++ b/meson.build @@ -697,10 +697,10 @@ if with_platform_haiku pre_args += '-DHAVE_HAIKU_PLATFORM' endif -prog_python2 = find_program('python2') -has_mako = run_command(prog_python2, '-c', 'import mako') +prog_python = find_program('python3') +has_mako = run_command(prog_python, '-c', 'import mako') if has_mako.returncode() != 0 - error('Python (2.x) mako module required to build mesa.') + error('Python (3.x) mako module required to build mesa.') endif if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6') diff --git a/src/amd/common/meson.build b/src/amd/common/meson.build index 0967b1adb7..6827a02094 100644 --- a/src/amd/common/meson.build +++ b/src/amd/common/meson.build @@ -22,7 +22,7 @@ sid_tables_h = custom_target( 'sid_tables_h', input : ['sid_tables.py', 'sid.h', 'gfx9d.h'], output : 'sid_tables.h', - command : [prog_python2, '@INPUT@'], + command : [prog_python, '@INPUT@'], capture : true, ) diff --git a/src/amd/vulkan/meson.build b/src/amd/vulkan/meson.build index 9f2842182e..9ceaeb6f00 100644 --- a/src/amd/vulkan/meson.build +++ b/src/amd/vulkan/meson.build @@ -23,7 +23,7 @@ radv_entrypoints = custom_target( input : ['radv_entrypoints_gen.py', vk_api_xml], output : ['radv_entrypoints.h', 'radv_entrypoints.c'], command : [ -prog_python2, '@INPUT0@', '--xml', '@INPUT1@', '--outdir', +prog_python, '@INPUT0@', '--xml', '@INPUT1@', '--outdir', meson.current_build_dir() ], depend_files : files('radv_extensions.py'), @@ -34,7 +34,7 @@ radv_extensions_c = custom_target( input : ['radv_extensions.py', vk_api_xml], output : ['radv_extensions.c', 'radv_extensions.h'], command : [ -prog_python2, '@INPUT0@', '--xml', '@INPUT1@', '--out-c', '@OUTPUT0@', +prog_python, '@INPUT0@', '--xml', '@INPUT1@', '--out-c', '@OUTPUT0@', '--out-h', '@OUTPUT1@' ], ) @@ -43,7 +43,7 @@ vk_format_table_c = custom_target( 'vk_format_table.c', input : ['vk_format_table.py', 'vk_format_layout.csv'], output : 'vk_format_table.c', - command : [prog_python2, '@INPUT@'], + command : [prog_python, '@INPUT@'], depend_files : files('vk_format_parse.py'), capture : true, ) @@ -153,7 +153,7 @@ radeon_icd = custom_targe
[Mesa-dev] [PATCH v2 6/9] python: Use key-functions when sorting containers
In Python 2, the traditional way to sort containers was to use a comparison function (which returned either -1, 0 or 1 when passed two objects) and pass that as the "cmp" argument to the container's sort() method. Python 2.4 introduced key-functions, which instead only operate on a given item, and return a sorting key for this item. In general, this runs faster, because the cmp-function has to get run multiple times for each item of the container. Python 3 removed the cmp-function, enforcing usage of key-functions instead. This change makes the script compatible with Python 2 and Python 3. Signed-off-by: Mathieu Bridon --- src/mapi/mapi_abi.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mapi/mapi_abi.py b/src/mapi/mapi_abi.py index e4ce2b6caf..d4c48ec430 100644 --- a/src/mapi/mapi_abi.py +++ b/src/mapi/mapi_abi.py @@ -32,6 +32,7 @@ import os GLAPI = os.path.join(".", os.path.dirname(sys.argv[0]), "glapi/gen") sys.path.append(GLAPI) +from operator import attrgetter import re from optparse import OptionParser import gl_XML @@ -291,7 +292,7 @@ class ABIPrinter(object): # sort entries by their names self.entries_sorted_by_names = self.entries[:] -self.entries_sorted_by_names.sort(lambda x, y: cmp(x.name, y.name)) +self.entries_sorted_by_names.sort(key=attrgetter('name')) self.indent = ' ' * 3 self.noop_warn = 'noop_warn' @@ -441,7 +442,7 @@ class ABIPrinter(object): """Return the string pool for use by stubs.""" # sort entries by their names sorted_entries = self.entries[:] -sorted_entries.sort(lambda x, y: cmp(x.name, y.name)) +sorted_entries.sort(key=attrgetter('name')) pool = [] offsets = {} -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH v2 5/9] python: Better check for integer types
Python 3 lost the long type: now everything is an int, with the right size. This commit makes the script compatible with Python 2 (where we check for both int and long) and Python 3 (where we only check for int). Signed-off-by: Mathieu Bridon --- src/compiler/nir/nir_algebraic.py | 8 +--- src/gallium/auxiliary/util/u_format_pack.py | 13 +++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index 5baeea88af..3055937029 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -36,9 +36,11 @@ import traceback from nir_opcodes import opcodes if sys.version_info < (3, 0): +integer_types = (int, long) string_type = unicode else: +integer_types = (int, ) string_type = str _type_re = re.compile(r"(?Pint|uint|bool|float)?(?P\d+)?") @@ -81,7 +83,7 @@ class Value(object): return val elif isinstance(val, string_type): return Variable(val, name_base, varset) - elif isinstance(val, (bool, int, long, float)): + elif isinstance(val, (bool, float) + integer_types): return Constant(val, name_base) __template = mako.template.Template(""" @@ -145,7 +147,7 @@ class Constant(Value): def hex(self): if isinstance(self.value, (bool)): return 'NIR_TRUE' if self.value else 'NIR_FALSE' - if isinstance(self.value, (int, long)): + if isinstance(self.value, integer_types): return hex(self.value) elif isinstance(self.value, float): i = struct.unpack('Q', struct.pack('d', self.value))[0] @@ -164,7 +166,7 @@ class Constant(Value): def type(self): if isinstance(self.value, (bool)): return "nir_type_bool32" - elif isinstance(self.value, (int, long)): + elif isinstance(self.value, integer_types): return "nir_type_int" elif isinstance(self.value, float): return "nir_type_float" diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index ad2e49281f..c1307d30c2 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -38,9 +38,18 @@ from __future__ import division, print_function +import sys + from u_format_parse import * +if sys.version_info < (3, 0): +integer_types = (int, long) + +else: +integer_types = (int, ) + + def inv_swizzles(swizzles): '''Return an array[4] of inverse swizzle terms''' '''Only pick the first matching value to avoid l8 getting blue and i8 getting alpha''' @@ -212,7 +221,7 @@ def truncate_mantissa(x, bits): '''Truncate an integer so it can be represented exactly with a floating point mantissa''' -assert isinstance(x, (int, long)) +assert isinstance(x, integer_types) s = 1 if x < 0: @@ -236,7 +245,7 @@ def value_to_native(type, value): '''Get the value of unity for this type.''' if type.type == FLOAT: if type.size <= 32 \ -and isinstance(value, (int, long)): +and isinstance(value, integer_types): return truncate_mantissa(value, 23) return value if type.type == FIXED: -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH v2 4/9] python: Do not mix bytes and unicode strings
Mixing the two is a long-standing recipe for errors in Python 2, so much so that Python 3 now completely separates them. This commit stops treating both as if they were the same, and in the process makes the script compatible with both Python 2 and 3. Signed-off-by: Mathieu Bridon --- src/compiler/nir/nir_algebraic.py | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index a84c41a78f..5baeea88af 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -35,6 +35,12 @@ import traceback from nir_opcodes import opcodes +if sys.version_info < (3, 0): +string_type = unicode + +else: +string_type = str + _type_re = re.compile(r"(?Pint|uint|bool|float)?(?P\d+)?") def type_bits(type_str): @@ -66,11 +72,14 @@ class VarSet(object): class Value(object): @staticmethod def create(val, name_base, varset): + if isinstance(val, bytes): + val = val.decode('utf-8') + if isinstance(val, tuple): return Expression(val, name_base, varset) elif isinstance(val, Expression): return val - elif isinstance(val, (str, unicode)): + elif isinstance(val, string_type): return Variable(val, name_base, varset) elif isinstance(val, (bool, int, long, float)): return Constant(val, name_base) -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH v2 2/9] python: Use the right function for the job
The code was just reimplementing itertools.combinations_with_replacement in a less efficient way. This does change the order of the results slightly, but it should be ok. Signed-off-by: Mathieu Bridon --- src/compiler/nir/nir_opt_algebraic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index ac53d77383..e770a61d9f 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -723,7 +723,7 @@ optimizations = [ invert = OrderedDict([('feq', 'fne'), ('fne', 'feq'), ('fge', 'flt'), ('flt', 'fge')]) -for left, right in list(itertools.combinations(invert.keys(), 2)) + zip(invert.keys(), invert.keys()): +for left, right in itertools.combinations_with_replacement(invert.keys(), 2): optimizations.append((('inot', ('ior(is_used_once)', (left, a, b), (right, c, d))), ('iand', (invert[left], a, b), (invert[right], c, d optimizations.append((('inot', ('iand(is_used_once)', (left, a, b), (right, c, d))), -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH v2 8/9] python: Rework bytes/unicode string handling
In both Python 2 and 3, opening a file without specifying the mode will open it for reading in text mode ('r'). On Python 2, the read() method of a file object opened in mode 'r' will return byte strings, while on Python 3 it will return unicode strings. Explicitly specifying the binary mode ('rb') then decoding the byte string means we always handle unicode strings on both Python 2 and 3. Which in turns means all re.match(line) will return unicode strings as well. If we also make expandCString return unicode strings, we don't need the call to the unicode() constructor any more. We were using the ugettext() method because it always returns unicode strings in Python 2, contrarily to the gettext() one which returns strings in the same type as its input. The ugettext() method doesn't exist on Python 3, so we must use the gettext() one. This is fine now that we know we only pass unicode strings to gettext(). (the return values of expandCString) The last hurdles are that Python 3 doesn't let us concatenate unicode and byte strings directly, and that Python 2's stdout wants encoded byte strings while Python 3's want unicode strings. With these changes, the script gives the same output on both Python 2 and 3. Signed-off-by: Mathieu Bridon --- src/util/xmlpool/gen_xmlpool.py | 35 +++-- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py index b0db183854..db20e2767f 100644 --- a/src/util/xmlpool/gen_xmlpool.py +++ b/src/util/xmlpool/gen_xmlpool.py @@ -60,7 +60,7 @@ def expandCString (s): octa = False num = 0 digits = 0 -r = '' +r = u'' while i < len(s): if not escape: if s[i] == '\\': @@ -128,16 +128,29 @@ def expandMatches (matches, translations, end=None): if len(matches) == 1 and i < len(translations) and \ not matches[0].expand (r'\7').endswith('\\'): suffix = ' \\' -# Expand the description line. Need to use ugettext in order to allow -# non-ascii unicode chars in the original English descriptions. -text = escapeCString (trans.ugettext (unicode (expandCString ( -matches[0].expand (r'\5')), "utf-8"))).encode("utf-8") -print(matches[0].expand (r'\1' + lang + r'\3"' + text + r'"\7') + suffix) +text = escapeCString (trans.gettext (expandCString ( +matches[0].expand (r'\5' +text = (matches[0].expand (r'\1' + lang + r'\3"' + text + r'"\7') + suffix) + +# In Python 2, stdout expects encoded byte strings, or else it will +# encode them with the ascii 'codec' +if sys.version_info.major == 2: +text = text.encode('utf-8') + +print(text) + # Expand any subsequent enum lines for match in matches[1:]: -text = escapeCString (trans.ugettext (unicode (expandCString ( -match.expand (r'\3')), "utf-8"))).encode("utf-8") -print(match.expand (r'\1"' + text + r'"\5')) +text = escapeCString (trans.gettext (expandCString ( +match.expand (r'\3' +text = match.expand (r'\1"' + text + r'"\5') + +# In Python 2, stdout expects encoded byte strings, or else it will +# encode them with the ascii 'codec' +if sys.version_info.major == 2: +text = text.encode('utf-8') + +print(text) # Expand description end if end: @@ -168,9 +181,11 @@ print("/***\ # Process the options template and generate options.h with all # translations. -template = open (template_header_path, "r") +template = open (template_header_path, "rb") descMatches = [] for line in template: +line = line.decode('utf-8') + if len(descMatches) > 0: matchENUM = reENUM.match (line) matchDESC_END = reDESC_END.match (line) -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH v2 7/9] python: Simplify list sorting
Instead of copying the list, then sorting the copy in-place, we can just get a new sorted copy directly. Signed-off-by: Mathieu Bridon --- src/mapi/mapi_abi.py | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/mapi/mapi_abi.py b/src/mapi/mapi_abi.py index d4c48ec430..dc48fa5935 100644 --- a/src/mapi/mapi_abi.py +++ b/src/mapi/mapi_abi.py @@ -291,8 +291,7 @@ class ABIPrinter(object): self.entries = entries # sort entries by their names -self.entries_sorted_by_names = self.entries[:] -self.entries_sorted_by_names.sort(key=attrgetter('name')) +self.entries_sorted_by_names = sorted(self.entries, key=attrgetter('name')) self.indent = ' ' * 3 self.noop_warn = 'noop_warn' @@ -441,8 +440,7 @@ class ABIPrinter(object): def c_stub_string_pool(self): """Return the string pool for use by stubs.""" # sort entries by their names -sorted_entries = self.entries[:] -sorted_entries.sort(key=attrgetter('name')) +sorted_entries = sorted(self.entries, key=attrgetter('name')) pool = [] offsets = {} -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH v2 3/9] python: Explicitly use a list
On Python 2, the builtin functions filter() returns a list. On Python 3, it returns an iterator. Since we want to use those objects in contexts where we need lists, we need to explicitly turn them into lists. This makes the code compatible with both Python 2 and Python 3. Signed-off-by: Mathieu Bridon --- src/mesa/main/get_hash_generator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mesa/main/get_hash_generator.py b/src/mesa/main/get_hash_generator.py index facdccd8a5..37dae45e0b 100644 --- a/src/mesa/main/get_hash_generator.py +++ b/src/mesa/main/get_hash_generator.py @@ -117,8 +117,8 @@ def print_tables(tables): def merge_tables(tables): merged_tables = [] for api, indices in sorted(tables.items()): - matching_table = filter(lambda mt:mt["indices"] == indices, - merged_tables) + matching_table = list(filter(lambda mt:mt["indices"] == indices, + merged_tables)) if matching_table: matching_table[0]["apis"].append(api) else: -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH v2 1/9] python: Fix inequality comparisons
On Python 3, executing `foo != bar` will first try to call foo.__ne__(bar), and fallback on the opposite result of foo.__eq__(bar). Python 2 does not do that. As a result, those __eq__ methods were never called, when we were testing for inequality. Expliclty adding the __ne__ methods fixes this issue, in a way that is compatible with both Python 2 and 3. However, this means the __eq__ methods are now called when testing for `foo != None`, so they need to be guarded correctly. Signed-off-by: Mathieu Bridon --- src/amd/vulkan/vk_format_parse.py| 6 ++ src/gallium/auxiliary/util/u_format_parse.py | 6 ++ src/mesa/main/format_parser.py | 6 ++ 3 files changed, 18 insertions(+) diff --git a/src/amd/vulkan/vk_format_parse.py b/src/amd/vulkan/vk_format_parse.py index 00cf1adf5a..ba730388a7 100644 --- a/src/amd/vulkan/vk_format_parse.py +++ b/src/amd/vulkan/vk_format_parse.py @@ -73,8 +73,14 @@ class Channel: return s def __eq__(self, other): +if other is None: +return False + return self.type == other.type and self.norm == other.norm and self.pure == other.pure and self.size == other.size and self.scaled == other.scaled +def __ne__(self, other): +return not self == other + def max(self): '''Maximum representable number.''' if self.type == FLOAT: diff --git a/src/gallium/auxiliary/util/u_format_parse.py b/src/gallium/auxiliary/util/u_format_parse.py index d3874cd895..48cc012cd2 100644 --- a/src/gallium/auxiliary/util/u_format_parse.py +++ b/src/gallium/auxiliary/util/u_format_parse.py @@ -72,8 +72,14 @@ class Channel: return s def __eq__(self, other): +if other is None: +return False + return self.type == other.type and self.norm == other.norm and self.pure == other.pure and self.size == other.size +def __ne__(self, other): +return not self == other + def max(self): '''Maximum representable number.''' if self.type == FLOAT: diff --git a/src/mesa/main/format_parser.py b/src/mesa/main/format_parser.py index 3321ad33ff..c0d73c9d22 100644 --- a/src/mesa/main/format_parser.py +++ b/src/mesa/main/format_parser.py @@ -61,8 +61,14 @@ class Channel: return s def __eq__(self, other): + if other is None: + return False + return self.type == other.type and self.norm == other.norm and self.size == other.size + def __ne__(self, other): + return not self.__eq__(other) + def max(self): """Returns the maximum representable number.""" if self.type == FLOAT: -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH v3 10/26] python: Use explicit integer divisions
In Python 2, divisions of integers return an integer: >>> 32 / 4 8 In Python 3 though, they return floats: >>> 32 / 4 8.0 However, Python 3 has an explicit integer division operator: >>> 32 // 4 8 That operator exists on Python >= 2.2, so let's use it everywhere to make the scripts compatible with both Python 2 and 3. In addition, using __future__.division tells Python 2 to behave the same way as Python 3, which helps ensure the scripts produce the same output in both versions of Python. Signed-off-by: Mathieu Bridon Reviewed-by: Eric Engestrom (v2) --- src/gallium/auxiliary/util/u_format_pack.py | 4 ++-- src/gallium/auxiliary/util/u_format_parse.py | 7 +-- src/mapi/glapi/gen/glX_proto_send.py | 4 ++-- src/mesa/main/format_info.py | 4 ++-- src/mesa/main/format_pack.py | 8 src/mesa/main/format_unpack.py | 8 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index 7a952a48b3..ad2e49281f 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -36,7 +36,7 @@ ''' -from __future__ import print_function +from __future__ import division, print_function from u_format_parse import * @@ -240,7 +240,7 @@ def value_to_native(type, value): return truncate_mantissa(value, 23) return value if type.type == FIXED: -return int(value * (1 << (type.size/2))) +return int(value * (1 << (type.size // 2))) if not type.norm: return int(value) if type.type == UNSIGNED: diff --git a/src/gallium/auxiliary/util/u_format_parse.py b/src/gallium/auxiliary/util/u_format_parse.py index c0456f6d15..d3874cd895 100644 --- a/src/gallium/auxiliary/util/u_format_parse.py +++ b/src/gallium/auxiliary/util/u_format_parse.py @@ -29,6 +29,9 @@ ''' +from __future__ import division + + VOID, UNSIGNED, SIGNED, FIXED, FLOAT = range(5) SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W, SWIZZLE_0, SWIZZLE_1, SWIZZLE_NONE, = range(7) @@ -76,7 +79,7 @@ class Channel: if self.type == FLOAT: return VERY_LARGE if self.type == FIXED: -return (1 << (self.size/2)) - 1 +return (1 << (self.size // 2)) - 1 if self.norm: return 1 if self.type == UNSIGNED: @@ -90,7 +93,7 @@ class Channel: if self.type == FLOAT: return -VERY_LARGE if self.type == FIXED: -return -(1 << (self.size/2)) +return -(1 << (self.size // 2)) if self.type == UNSIGNED: return 0 if self.norm: diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py index a920ecc012..03067d8a3c 100644 --- a/src/mapi/glapi/gen/glX_proto_send.py +++ b/src/mapi/glapi/gen/glX_proto_send.py @@ -26,7 +26,7 @@ #Ian Romanick #Jeremy Kolb -from __future__ import print_function +from __future__ import division, print_function import argparse @@ -809,7 +809,7 @@ generic_%u_byte( GLint rop, const void * ptr ) # Dividing by the array size (1 for # non-arrays) gives us this. -s = p.size() / p.get_element_count() +s = p.size() // p.get_element_count() print(" %s __glXReadReply(dpy, %s, %s, %s);" % (return_str, s, p.name, aa)) got_reply = 1 diff --git a/src/mesa/main/format_info.py b/src/mesa/main/format_info.py index bbecaa2451..00e27b3fba 100644 --- a/src/mesa/main/format_info.py +++ b/src/mesa/main/format_info.py @@ -21,7 +21,7 @@ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -from __future__ import print_function +from __future__ import division, print_function import format_parser as parser import sys @@ -198,7 +198,7 @@ for fmat in formats: chan = fmat.array_element() norm = chan.norm or chan.type == parser.FLOAT print(' .ArrayFormat = MESA_ARRAY_FORMAT({0}),'.format(', '.join([ - str(chan.size / 8), + str(chan.size // 8), str(int(chan.sign)), str(int(chan.type == parser.FLOAT)), str(int(norm)), diff --git a/src/mesa/main/format_pack.py b/src/mesa/main/format_pack.py index d3c8d24acd..0b9e0d424d 100644 --- a/src/mesa/main/format_pack.py +++ b/src/mesa/main/format_pack.py @@ -356,7 +356,7 @@ _mesa_pack_ubyte_rgba_row(mesa_format format, GLuint n, case ${f.name}: for (i = 0; i < n; ++i) { pack_ubyte_${f.short_name()}(src[i], d); - d += ${f.block_size() / 8}; + d += ${f.block_size() // 8}; } b
[Mesa-dev] [PATCH v2 11/26] python: Fix rich comparisons
Python 3 doesn't call objects __cmp__() methods any more to compare them. Instead, it requires implementing the rich comparison methods explicitly: __eq__(), __ne(), __lt__(), __le__(), __gt__() and __ge__(). Fortunately Python 2 also supports those. This commit only implements the comparison methods which are actually used by the build scripts. Signed-off-by: Mathieu Bridon --- src/amd/vulkan/radv_extensions.py | 5 +++-- src/intel/vulkan/anv_extensions.py | 5 +++-- src/mapi/mapi_abi.py | 15 +++ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/amd/vulkan/radv_extensions.py b/src/amd/vulkan/radv_extensions.py index a0f1038110..55e14b811a 100644 --- a/src/amd/vulkan/radv_extensions.py +++ b/src/amd/vulkan/radv_extensions.py @@ -143,14 +143,15 @@ class VkVersion: patch = self.patch if self.patch is not None else 0 return (self.major << 22) | (self.minor << 12) | patch -def __cmp__(self, other): +def __gt__(self, other): # If only one of them has a patch version, "ignore" it by making # other's patch version match self. if (self.patch is None) != (other.patch is None): other = copy.copy(other) other.patch = self.patch -return self.__int_ver().__cmp__(other.__int_ver()) +return self.__int_ver() > other.__int_ver() + MAX_API_VERSION = VkVersion(MAX_API_VERSION) diff --git a/src/intel/vulkan/anv_extensions.py b/src/intel/vulkan/anv_extensions.py index 0f99f58ecb..56b1ebf96d 100644 --- a/src/intel/vulkan/anv_extensions.py +++ b/src/intel/vulkan/anv_extensions.py @@ -155,14 +155,15 @@ class VkVersion: patch = self.patch if self.patch is not None else 0 return (self.major << 22) | (self.minor << 12) | patch -def __cmp__(self, other): +def __gt__(self, other): # If only one of them has a patch version, "ignore" it by making # other's patch version match self. if (self.patch is None) != (other.patch is None): other = copy.copy(other) other.patch = self.patch -return self.__int_ver().__cmp__(other.__int_ver()) +return self.__int_ver() > other.__int_ver() + MAX_API_VERSION = VkVersion('0.0.0') diff --git a/src/mapi/mapi_abi.py b/src/mapi/mapi_abi.py index be1d15d922..e4ce2b6caf 100644 --- a/src/mapi/mapi_abi.py +++ b/src/mapi/mapi_abi.py @@ -121,19 +121,18 @@ class ABIEntry(object): def __str__(self): return self.c_prototype() -def __cmp__(self, other): +def __lt__(self, other): # compare slot, alias, and then name -res = cmp(self.slot, other.slot) -if not res: +if self.slot == other.slot: if not self.alias: -res = -1 +return True elif not other.alias: -res = 1 +return False -if not res: -res = cmp(self.name, other.name) +return self.name < other.name + +return self.slot < other.slot -return res def abi_parse_xml(xml): """Parse a GLAPI XML file for ABI entries.""" -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 11/26] python: Fix rich comparisons
Python 3 lost the cmp() builtin, and doesn't call objects __cmp__() methods any more to compare them. Instead, Python 3 requires implementing the rich comparison methods explicitly: __eq__(), __ne(), __lt__(), __le__(), __gt__() and __ge__(). Fortunately those are trivial to implement by just calling the existing __cmp__() method, which makes the code compatible with both Python 2 and Python 3. This commit only implements the comparison methods which are actually used by the build scripts. In addition, this commit brings back to Python 3 the cmp() builtin method as required. Signed-off-by: Mathieu Bridon --- src/amd/vulkan/radv_extensions.py | 6 +- src/intel/vulkan/anv_extensions.py | 6 +- src/mapi/mapi_abi.py | 13 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/amd/vulkan/radv_extensions.py b/src/amd/vulkan/radv_extensions.py index c36559f48e..13a05fa21d 100644 --- a/src/amd/vulkan/radv_extensions.py +++ b/src/amd/vulkan/radv_extensions.py @@ -151,7 +151,11 @@ class VkVersion: other = copy.copy(other) other.patch = self.patch -return self.__int_ver().__cmp__(other.__int_ver()) +return self.__int_ver() - other.__int_ver() + +def __gt__(self, other): +return self.__cmp__(other) > 0 + MAX_API_VERSION = VkVersion(MAX_API_VERSION) diff --git a/src/intel/vulkan/anv_extensions.py b/src/intel/vulkan/anv_extensions.py index adc1d75898..47dba164ef 100644 --- a/src/intel/vulkan/anv_extensions.py +++ b/src/intel/vulkan/anv_extensions.py @@ -166,7 +166,11 @@ class VkVersion: other = copy.copy(other) other.patch = self.patch -return self.__int_ver().__cmp__(other.__int_ver()) +return self.__int_ver() - other.__int_ver() + +def __gt__(self, other): +return self.__cmp__(other) > 0 + MAX_API_VERSION = VkVersion('0.0.0') diff --git a/src/mapi/mapi_abi.py b/src/mapi/mapi_abi.py index be1d15d922..67fdb10650 100644 --- a/src/mapi/mapi_abi.py +++ b/src/mapi/mapi_abi.py @@ -38,6 +38,15 @@ import gl_XML import glX_XML +try: +cmp + +except NameError: +# Python 3 does not have cmp() +def cmp(a, b): +return ((a > b) - (a < b)) + + # number of dynamic entries ABI_NUM_DYNAMIC_ENTRIES = 256 @@ -135,6 +144,10 @@ class ABIEntry(object): return res +def __lt__(self, other): +return self.__cmp__(other) < 0 + + def abi_parse_xml(xml): """Parse a GLAPI XML file for ABI entries.""" api = gl_XML.parse_GL_API(xml, glX_XML.glx_item_factory()) -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH v2 10/26] python: Use explicit integer divisions
In Python 2, divisions return an integer: >>> 32 / 4 8 In Python 3 though, they return floats: >>> 32 / 4 8.0 However, Python 3 has an explicit integer division operator: >>> 32 // 4 8 That operator exists on Python >= 2.2, so let's use it everywhere to make the scripts compatible with both Python 2 and 3. In addition, using __future__.division tells Python 2 to behave the same way as Python 3, which helps ensure the scripts produce the same output in both versions of Python. Signed-off-by: Mathieu Bridon --- src/gallium/auxiliary/util/u_format_pack.py | 4 ++-- src/gallium/auxiliary/util/u_format_parse.py | 7 +-- src/mapi/glapi/gen/glX_proto_send.py | 4 ++-- src/mesa/main/format_info.py | 4 ++-- src/mesa/main/format_pack.py | 8 src/mesa/main/format_unpack.py | 8 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index 7a952a48b3..ad2e49281f 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -36,7 +36,7 @@ ''' -from __future__ import print_function +from __future__ import division, print_function from u_format_parse import * @@ -240,7 +240,7 @@ def value_to_native(type, value): return truncate_mantissa(value, 23) return value if type.type == FIXED: -return int(value * (1 << (type.size/2))) +return int(value * (1 << (type.size // 2))) if not type.norm: return int(value) if type.type == UNSIGNED: diff --git a/src/gallium/auxiliary/util/u_format_parse.py b/src/gallium/auxiliary/util/u_format_parse.py index c0456f6d15..d3874cd895 100644 --- a/src/gallium/auxiliary/util/u_format_parse.py +++ b/src/gallium/auxiliary/util/u_format_parse.py @@ -29,6 +29,9 @@ ''' +from __future__ import division + + VOID, UNSIGNED, SIGNED, FIXED, FLOAT = range(5) SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W, SWIZZLE_0, SWIZZLE_1, SWIZZLE_NONE, = range(7) @@ -76,7 +79,7 @@ class Channel: if self.type == FLOAT: return VERY_LARGE if self.type == FIXED: -return (1 << (self.size/2)) - 1 +return (1 << (self.size // 2)) - 1 if self.norm: return 1 if self.type == UNSIGNED: @@ -90,7 +93,7 @@ class Channel: if self.type == FLOAT: return -VERY_LARGE if self.type == FIXED: -return -(1 << (self.size/2)) +return -(1 << (self.size // 2)) if self.type == UNSIGNED: return 0 if self.norm: diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py index a920ecc012..03067d8a3c 100644 --- a/src/mapi/glapi/gen/glX_proto_send.py +++ b/src/mapi/glapi/gen/glX_proto_send.py @@ -26,7 +26,7 @@ #Ian Romanick #Jeremy Kolb -from __future__ import print_function +from __future__ import division, print_function import argparse @@ -809,7 +809,7 @@ generic_%u_byte( GLint rop, const void * ptr ) # Dividing by the array size (1 for # non-arrays) gives us this. -s = p.size() / p.get_element_count() +s = p.size() // p.get_element_count() print(" %s __glXReadReply(dpy, %s, %s, %s);" % (return_str, s, p.name, aa)) got_reply = 1 diff --git a/src/mesa/main/format_info.py b/src/mesa/main/format_info.py index bbecaa2451..00e27b3fba 100644 --- a/src/mesa/main/format_info.py +++ b/src/mesa/main/format_info.py @@ -21,7 +21,7 @@ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -from __future__ import print_function +from __future__ import division, print_function import format_parser as parser import sys @@ -198,7 +198,7 @@ for fmat in formats: chan = fmat.array_element() norm = chan.norm or chan.type == parser.FLOAT print(' .ArrayFormat = MESA_ARRAY_FORMAT({0}),'.format(', '.join([ - str(chan.size / 8), + str(chan.size // 8), str(int(chan.sign)), str(int(chan.type == parser.FLOAT)), str(int(norm)), diff --git a/src/mesa/main/format_pack.py b/src/mesa/main/format_pack.py index d3c8d24acd..05262efb5b 100644 --- a/src/mesa/main/format_pack.py +++ b/src/mesa/main/format_pack.py @@ -1,4 +1,4 @@ -from __future__ import print_function +from __future__ import division, print_function from mako.template import Template from sys import argv @@ -356,7 +356,7 @@ _mesa_pack_ubyte_rgba_row(mesa_format format, GLuint n, case ${f.name}: for (i = 0; i < n; ++i) { pack_ubyte_${f.
[Mesa-dev] [PATCH 09/26] python: Use range() instead of xrange()
Python 2 has a range() function which returns a list, and an xrange() one which returns an iterator. Python 3 lost the function returning a list, and renamed the function returning an iterator as range(). As a result, using range() makes the scripts compatible with both Python versions 2 and 3. Signed-off-by: Mathieu Bridon --- src/amd/vulkan/radv_entrypoints_gen.py | 2 +- src/broadcom/cle/gen_pack_header.py | 2 +- src/compiler/glsl/ir_expression_operation.py | 2 +- src/compiler/nir/nir_opcodes.py | 4 ++-- src/intel/vulkan/anv_entrypoints_gen.py | 2 +- src/mapi/glapi/gen/glX_proto_send.py | 2 +- src/mapi/glapi/gen/gl_gentable.py| 4 ++-- src/mapi/mapi_abi.py | 2 +- src/mesa/main/format_parser.py | 4 ++-- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/amd/vulkan/radv_entrypoints_gen.py b/src/amd/vulkan/radv_entrypoints_gen.py index 9c4dfd02a0..ca022bcbb0 100644 --- a/src/amd/vulkan/radv_entrypoints_gen.py +++ b/src/amd/vulkan/radv_entrypoints_gen.py @@ -136,7 +136,7 @@ static const struct string_map_entry string_map_entries[] = { /* Hash table stats: * size ${len(strmap.sorted_strings)} entries * collisions entries: -% for i in xrange(10): +% for i in range(10): * ${i}${'+' if i == 9 else ' '} ${strmap.collisions[i]} % endfor */ diff --git a/src/broadcom/cle/gen_pack_header.py b/src/broadcom/cle/gen_pack_header.py index c6e1c564e6..8ad54464cb 100644 --- a/src/broadcom/cle/gen_pack_header.py +++ b/src/broadcom/cle/gen_pack_header.py @@ -216,7 +216,7 @@ class Group(object): first_byte = field.start // 8 last_byte = field.end // 8 -for b in xrange(first_byte, last_byte + 1): +for b in range(first_byte, last_byte + 1): if not b in bytes: bytes[b] = self.Byte() diff --git a/src/compiler/glsl/ir_expression_operation.py b/src/compiler/glsl/ir_expression_operation.py index b3dac3da3f..16b98690a6 100644 --- a/src/compiler/glsl/ir_expression_operation.py +++ b/src/compiler/glsl/ir_expression_operation.py @@ -116,7 +116,7 @@ constant_template_common = mako.template.Template("""\ constant_template_vector_scalar = mako.template.Template("""\ case ${op.get_enum_name()}: % if "mixed" in op.flags: -% for i in xrange(op.num_operands): +% for i in range(op.num_operands): assert(op[${i}]->type->base_type == ${op.source_types[0].glsl_type} || % for src_type in op.source_types[1:-1]: op[${i}]->type->base_type == ${src_type.glsl_type} || diff --git a/src/compiler/nir/nir_opcodes.py b/src/compiler/nir/nir_opcodes.py index 3c3316dcaa..b03c5da2ea 100644 --- a/src/compiler/nir/nir_opcodes.py +++ b/src/compiler/nir/nir_opcodes.py @@ -367,8 +367,8 @@ for (unsigned bit = 0; bit < bit_size; bit++) { """) -for i in xrange(1, 5): - for j in xrange(1, 5): +for i in range(1, 5): + for j in range(1, 5): unop_horiz("fnoise{0}_{1}".format(i, j), i, tfloat, j, tfloat, "0.0f") diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py index 8a37336496..5e2cd0740a 100644 --- a/src/intel/vulkan/anv_entrypoints_gen.py +++ b/src/intel/vulkan/anv_entrypoints_gen.py @@ -145,7 +145,7 @@ static const struct string_map_entry string_map_entries[] = { /* Hash table stats: * size ${len(strmap.sorted_strings)} entries * collisions entries: -% for i in xrange(10): +% for i in range(10): * ${i}${'+' if i == 9 else ' '} ${strmap.collisions[i]} % endfor */ diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py index fba2f0cc1e..a920ecc012 100644 --- a/src/mapi/glapi/gen/glX_proto_send.py +++ b/src/mapi/glapi/gen/glX_proto_send.py @@ -392,7 +392,7 @@ static const struct proc_pair _glapi_proc proc; } proc_pairs[%d] = {""" % len(procs)) names = sorted(procs.keys()) -for i in xrange(len(names)): +for i in range(len(names)): comma = ',' if i < len(names) - 1 else '' print(' { "%s", (_glapi_proc) gl%s }%s' % (names[i], procs[names[i]], comma)) print("""}; diff --git a/src/mapi/glapi/gen/gl_gentable.py b/src/mapi/glapi/gen/gl_gentable.py index 49206b1167..9d8923cf8d 100644 --- a/src/mapi/glapi/gen/gl_gentable.py +++ b/src/mapi/glapi/gen/gl_gentable.py @@ -216,13 +216,13 @@ class PrintCode(gl_XML.gl_print_base): # Check that the table has no gaps. We expect a function at every offset, # and the code which generates the table relies on this. -for i in xrange(0, func_count): +for i in range(0, func_count): if funcnames[i] is None:
[Mesa-dev] [PATCH 06/26] python: Better iterate over dictionaries
In Python 2, dictionaries have 2 sets of methods to iterate over their keys and values: keys()/values()/items() and iterkeys()/itervalues()/iteritems(). The former return lists while the latter return iterators. Python 3 dropped the method which return lists, and renamed the methods returning iterators to keys()/values()/items(). Using those names makes the scripts compatible with both Python 2 and 3. Signed-off-by: Mathieu Bridon --- src/amd/vulkan/radv_entrypoints_gen.py | 2 +- src/compiler/nir/nir_algebraic.py| 2 +- src/compiler/nir/nir_builder_opcodes_h.py| 4 ++-- src/compiler/nir/nir_constant_expressions.py | 4 ++-- src/compiler/nir/nir_intrinsics_c.py | 2 +- src/compiler/nir/nir_opcodes_c.py| 2 +- src/compiler/nir/nir_opcodes_h.py| 2 +- src/intel/genxml/gen_bits_header.py | 10 +- src/intel/vulkan/anv_entrypoints_gen.py | 2 +- src/mapi/glapi/gen/gl_XML.py | 14 +++--- src/mapi/glapi/gen/gl_gentable.py| 4 ++-- src/mesa/drivers/dri/i965/brw_oa.py | 4 ++-- 12 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/amd/vulkan/radv_entrypoints_gen.py b/src/amd/vulkan/radv_entrypoints_gen.py index bef0c447f6..9c4dfd02a0 100644 --- a/src/amd/vulkan/radv_entrypoints_gen.py +++ b/src/amd/vulkan/radv_entrypoints_gen.py @@ -433,7 +433,7 @@ def get_entrypoints(doc, entrypoints_to_defines, start_index): e_clone.name = e.name entrypoints[e.name] = e_clone -return [e for e in entrypoints.itervalues() if e.enabled] +return [e for e in entrypoints.values() if e.enabled] def get_entrypoints_defines(doc): diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index 847c59dbd8..8c0b530f69 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -512,7 +512,7 @@ struct transform { #endif -% for (opcode, xform_list) in xform_dict.iteritems(): +% for (opcode, xform_list) in xform_dict.items(): % for xform in xform_list: ${xform.search.render()} ${xform.replace.render()} diff --git a/src/compiler/nir/nir_builder_opcodes_h.py b/src/compiler/nir/nir_builder_opcodes_h.py index 72cf5b4549..e600093e9f 100644 --- a/src/compiler/nir/nir_builder_opcodes_h.py +++ b/src/compiler/nir/nir_builder_opcodes_h.py @@ -34,7 +34,7 @@ def src_list(num_srcs): return ', '.join('src' + str(i) if i < num_srcs else 'NULL' for i in range(4)) %> -% for name, opcode in sorted(opcodes.iteritems()): +% for name, opcode in sorted(opcodes.items()): static inline nir_ssa_def * nir_${name}(nir_builder *build, ${src_decl_list(opcode.num_inputs)}) { @@ -55,7 +55,7 @@ nir_load_system_value(nir_builder *build, nir_intrinsic_op op, int index) return &load->dest.ssa; } -% for name, opcode in filter(lambda v: v[1].sysval, sorted(INTR_OPCODES.iteritems())): +% for name, opcode in filter(lambda v: v[1].sysval, sorted(INTR_OPCODES.items())): static inline nir_ssa_def * nir_${name}(nir_builder *build) { diff --git a/src/compiler/nir/nir_constant_expressions.py b/src/compiler/nir/nir_constant_expressions.py index 35dffe70ce..118af9f781 100644 --- a/src/compiler/nir/nir_constant_expressions.py +++ b/src/compiler/nir/nir_constant_expressions.py @@ -387,7 +387,7 @@ struct bool32_vec { % endif -% for name, op in sorted(opcodes.iteritems()): +% for name, op in sorted(opcodes.items()): static nir_const_value evaluate_${name}(MAYBE_UNUSED unsigned num_components, ${"UNUSED" if op_bit_sizes(op) is None else ""} unsigned bit_size, @@ -420,7 +420,7 @@ nir_eval_const_opcode(nir_op op, unsigned num_components, unsigned bit_width, nir_const_value *src) { switch (op) { -% for name in sorted(opcodes.iterkeys()): +% for name in sorted(opcodes.keys()): case nir_op_${name}: return evaluate_${name}(num_components, bit_width, src); % endfor diff --git a/src/compiler/nir/nir_intrinsics_c.py b/src/compiler/nir/nir_intrinsics_c.py index 9604fcdf62..98af67c38a 100644 --- a/src/compiler/nir/nir_intrinsics_c.py +++ b/src/compiler/nir/nir_intrinsics_c.py @@ -25,7 +25,7 @@ template = """\ #include "nir.h" const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics] = { -% for name, opcode in sorted(INTR_OPCODES.iteritems()): +% for name, opcode in sorted(INTR_OPCODES.items()): { .name = "${name}", .num_srcs = ${opcode.num_srcs}, diff --git a/src/compiler/nir/nir_opcodes_c.py b/src/compiler/nir/nir_opcodes_c.py index 108e144b5f..4603cd3d74 100644 --- a/src/compiler/nir/nir_opcodes_c.py +++ b/src/compiler/nir/nir_opcodes_c.py @@ -116,7 +116,7 @@ nir_type_conversion_op(nir_alu_type src, nir_alu_type dst, nir_rounding_mode rnd } const nir_op_info nir_op_infos[nir_num_opcodes] = { -% for name, opcode in s
[Mesa-dev] [PATCH 07/26] python: Better sort dictionary keys/values
In Python 2, dict.keys() and dict.values() both return a list, which can be sorted in two ways: * l.sort() modifies the list in-place; * sorted(l) returns a new, sorted list; In Python 3, dict.keys() and dict.values() do not return lists any more, but iterators. Iterators do not have a .sort() method. This commit moves the build scripts to using sorted() on dict keys and values, which makes them compatible with both Python 2 and Python 3. Signed-off-by: Mathieu Bridon --- src/mapi/glapi/gen/glX_proto_send.py | 3 +-- src/mapi/glapi/gen/glX_proto_size.py | 6 ++ src/mapi/glapi/gen/gl_XML.py | 12 src/mapi/glapi/gen/gl_procs.py | 3 +-- src/mapi/mapi_abi.py | 6 ++ 5 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py index c389872044..fba2f0cc1e 100644 --- a/src/mapi/glapi/gen/glX_proto_send.py +++ b/src/mapi/glapi/gen/glX_proto_send.py @@ -391,8 +391,7 @@ static const struct proc_pair const char *name; _glapi_proc proc; } proc_pairs[%d] = {""" % len(procs)) -names = procs.keys() -names.sort() +names = sorted(procs.keys()) for i in xrange(len(names)): comma = ',' if i < len(names) - 1 else '' print(' { "%s", (_glapi_proc) gl%s }%s' % (names[i], procs[names[i]], comma)) diff --git a/src/mapi/glapi/gen/glX_proto_size.py b/src/mapi/glapi/gen/glX_proto_size.py index 18a6f2e502..2a843c3e24 100644 --- a/src/mapi/glapi/gen/glX_proto_size.py +++ b/src/mapi/glapi/gen/glX_proto_size.py @@ -208,8 +208,7 @@ class glx_enum_function(object): for enum_obj in self.enums[e]: list[ enum_obj.priority() ] = enum_obj.name -keys = list.keys() -keys.sort() +keys = sorted(list.keys()) for k in keys: j = list[k] if first: @@ -275,8 +274,7 @@ class glx_server_enum_function(glx_enum_function): o = f.offset_of( param_name ) foo[o] = param_name -keys = foo.keys() -keys.sort() +keys = sorted(foo.keys()) for o in keys: p = f.parameters_by_name[ foo[o] ] diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py index 20057cf9c4..7bd5a1f4e4 100644 --- a/src/mapi/glapi/gen/gl_XML.py +++ b/src/mapi/glapi/gen/gl_XML.py @@ -988,12 +988,10 @@ class gl_api(object): functions = [] for func_cat_type in range(0,4): -keys = lists[func_cat_type].keys() -keys.sort() +keys = sorted(lists[func_cat_type].keys()) for key in keys: -names = lists[func_cat_type][key].keys() -names.sort() +names = sorted(lists[func_cat_type][key].keys()) for name in names: functions.append(lists[func_cat_type][key][name]) @@ -1027,8 +1025,7 @@ class gl_api(object): def enumIterateByName(self): -keys = self.enums_by_name.keys() -keys.sort() +keys = sorted(self.enums_by_name.keys()) list = [] for enum in keys: @@ -1047,8 +1044,7 @@ class gl_api(object): list = [] for cat_type in range(0,4): -keys = self.categories[cat_type].keys() -keys.sort() +keys = sorted(self.categories[cat_type].keys()) for key in keys: list.append(self.categories[cat_type][key]) diff --git a/src/mapi/glapi/gen/gl_procs.py b/src/mapi/glapi/gen/gl_procs.py index 5718f42ab6..4bd3321610 100644 --- a/src/mapi/glapi/gen/gl_procs.py +++ b/src/mapi/glapi/gen/gl_procs.py @@ -144,8 +144,7 @@ typedef struct { print('') print('/* OpenGL ES specific prototypes */') print('') -keys = categories.keys() -keys.sort() +keys = sorted(categories.keys()) for key in keys: print('/* category %s */' % key) print("\n".join(categories[key])) diff --git a/src/mapi/mapi_abi.py b/src/mapi/mapi_abi.py index e3f65547bf..826721479d 100644 --- a/src/mapi/mapi_abi.py +++ b/src/mapi/mapi_abi.py @@ -180,8 +180,7 @@ def abi_parse_xml(xml): ent = ABIEntry(cols, attrs, func) entry_dict[ent.name] = ent -entries = entry_dict.values() -entries.sort() +entries = sorted(entry_dict.values()) return entries @@ -250,8 +249,7 @@ def abi_parse(filename): raise Exception('%s is duplicated' % (ent.name)) entry_dict[ent.name] = ent -entries = entry_dict.values() -entries.sort() +entries = sorted(entry_dict.values()) return entries
[Mesa-dev] [PATCH 04/26] python: Better check for keys in dicts
Python 3 lost the dict.has_key() method. Instead it requires using the "in" operator. This is also compatible with Python 2. Signed-off-by: Mathieu Bridon --- src/mapi/glapi/gen/glX_XML.py| 2 +- src/mapi/glapi/gen/glX_proto_send.py | 2 +- src/mapi/glapi/gen/glX_proto_size.py | 18 +- src/mapi/glapi/gen/gl_XML.py | 6 +++--- src/mapi/glapi/gen/gl_procs.py | 2 +- src/mapi/mapi_abi.py | 4 ++-- src/util/xmlpool/gen_xmlpool.py | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/mapi/glapi/gen/glX_XML.py b/src/mapi/glapi/gen/glX_XML.py index d09370a508..e10c8b0a09 100644 --- a/src/mapi/glapi/gen/glX_XML.py +++ b/src/mapi/glapi/gen/glX_XML.py @@ -64,7 +64,7 @@ class glx_enum(gl_XML.gl_enum): else: mode = 1 -if not self.functions.has_key(n): +if n not in self.functions: self.functions[ n ] = [c, mode] return diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py index f199e9a0a1..7ab1eb4a70 100644 --- a/src/mapi/glapi/gen/glX_proto_send.py +++ b/src/mapi/glapi/gen/glX_proto_send.py @@ -842,7 +842,7 @@ generic_%u_byte( GLint rop, const void * ptr ) def printPixelFunction(self, f): -if self.pixel_stubs.has_key( f.name ): +if f.name in self.pixel_stubs: # Normally gl_function::get_parameter_string could be # used. However, this call needs to have the missing # dimensions (e.g., a fake height value for diff --git a/src/mapi/glapi/gen/glX_proto_size.py b/src/mapi/glapi/gen/glX_proto_size.py index 284ee70e61..18a6f2e502 100644 --- a/src/mapi/glapi/gen/glX_proto_size.py +++ b/src/mapi/glapi/gen/glX_proto_size.py @@ -71,7 +71,7 @@ class glx_enum_function(object): for enum_name in enum_dict: e = enum_dict[ enum_name ] -if e.functions.has_key( match_name ): +if match_name in e.functions: [count, mode] = e.functions[ match_name ] if mode_set and mode != self.mode: @@ -79,11 +79,11 @@ class glx_enum_function(object): self.mode = mode -if self.enums.has_key( e.value ): +if e.value in self.enums: if e.name not in self.enums[ e.value ]: self.enums[ e.value ].append( e ) else: -if not self.count.has_key( count ): +if count not in self.count: self.count[ count ] = [] self.enums[ e.value ] = [ e ] @@ -131,7 +131,7 @@ class glx_enum_function(object): for a in self.enums: count += 1 -if self.count.has_key(-1): +if -1 in self.count: return 0 # Determine if there is some mask M, such that M = (2^N) - 1, @@ -356,7 +356,7 @@ class PrintGlxSizeStubs_c(PrintGlxSizeStubs_common): if (ef.is_set() and self.emit_set) or (not ef.is_set() and self.emit_get): sig = ef.signature() -if enum_sigs.has_key( sig ): +if sig in enum_sigs: aliases.append( [func.name, enum_sigs[ sig ]] ) else: enum_sigs[ sig ] = func.name @@ -477,10 +477,10 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common): sig = ef.signature() -if not enum_functions.has_key(func.name): +if func.name not in enum_functions: enum_functions[ func.name ] = sig -if not enum_sigs.has_key( sig ): +if sig not in enum_sigs: enum_sigs[ sig ] = ef @@ -496,7 +496,7 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common): if func.server_handcode: continue if not func.has_variable_size_request(): continue -if enum_functions.has_key(func.name): +if func.name in enum_functions: sig = enum_functions[func.name] ef = enum_sigs[ sig ] @@ -621,7 +621,7 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common): # already be emitted, don't emit this function. Instead, add # it to the list of function aliases. -if self.counter_sigs.has_key(sig): +if sig in self.counter_sigs: n = self.counter_sigs[sig]; alias = [f.name, n] else: diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py index bfeacf1386..bea6801db3 100644 --- a/src/mapi/glapi/gen/gl_XML.py +++ b/src/mapi/glapi/gen/gl_XML.py @@ -943,7 +943,7 @@ class gl_api(object): temp_name = child.get( "name" ) self.category_dict[ temp_name ] = [cat_name, cat_number] -if self.functions_by_name.has_key( func_name ): +if func_name
[Mesa-dev] [PATCH 03/26] python: Stop using the Python 2 exception syntax
We could have made this compatible with Python 3 by using: except Exception as e: But since none of this code actually uses the exception objects, let's just drop them entirely. Signed-off-by: Mathieu Bridon --- src/mapi/glapi/gen/glX_XML.py | 2 +- src/mapi/glapi/gen/gl_XML.py| 6 +++--- src/mapi/glapi/gen/gl_marshal.py| 2 +- src/mapi/glapi/gen/gl_marshal_h.py | 2 +- src/mesa/main/get_hash_generator.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mapi/glapi/gen/glX_XML.py b/src/mapi/glapi/gen/glX_XML.py index b6d305c879..d09370a508 100644 --- a/src/mapi/glapi/gen/glX_XML.py +++ b/src/mapi/glapi/gen/glX_XML.py @@ -470,7 +470,7 @@ class glx_function(gl_XML.gl_function): def needs_reply(self): try: x = self._needs_reply -except Exception, e: +except Exception: x = 0 if self.return_type != 'void': x = 1 diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py index 3a191abe0d..bfeacf1386 100644 --- a/src/mapi/glapi/gen/gl_XML.py +++ b/src/mapi/glapi/gen/gl_XML.py @@ -284,7 +284,7 @@ def classify_category(name, number): try: core_version = float(name) -except Exception,e: +except Exception: core_version = 0.0 if core_version > 0.0: @@ -365,7 +365,7 @@ class gl_enum( gl_item ): else: try: c = int(temp) -except Exception,e: +except Exception: raise RuntimeError('Invalid count value "%s" for enum "%s" in function "%s" when an integer was expected.' % (temp, self.name, n)) self.default_count = c @@ -426,7 +426,7 @@ class gl_parameter(object): count = int(c) self.count = count self.counter = None -except Exception,e: +except Exception: count = 1 self.count = 0 self.counter = c diff --git a/src/mapi/glapi/gen/gl_marshal.py b/src/mapi/glapi/gen/gl_marshal.py index e9dd2c4f78..5b35357ac5 100644 --- a/src/mapi/glapi/gen/gl_marshal.py +++ b/src/mapi/glapi/gen/gl_marshal.py @@ -353,7 +353,7 @@ if __name__ == '__main__': try: (args, trail) = getopt.getopt(sys.argv[1:], 'm:f:') -except Exception,e: +except Exception: show_usage() for (arg,val) in args: diff --git a/src/mapi/glapi/gen/gl_marshal_h.py b/src/mapi/glapi/gen/gl_marshal_h.py index 6490595a00..a7a9eda573 100644 --- a/src/mapi/glapi/gen/gl_marshal_h.py +++ b/src/mapi/glapi/gen/gl_marshal_h.py @@ -74,7 +74,7 @@ if __name__ == '__main__': try: (args, trail) = getopt.getopt(sys.argv[1:], 'm:f:') -except Exception,e: +except Exception: show_usage() for (arg,val) in args: diff --git a/src/mesa/main/get_hash_generator.py b/src/mesa/main/get_hash_generator.py index 86c6771066..facdccd8a5 100644 --- a/src/mesa/main/get_hash_generator.py +++ b/src/mesa/main/get_hash_generator.py @@ -201,7 +201,7 @@ def show_usage(): if __name__ == '__main__': try: (opts, args) = getopt.getopt(sys.argv[1:], "f:") - except Exception,e: + except Exception: show_usage() if len(args) != 0: -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 16/26] python: Explicitly use lists
On Thu, 2018-07-05 at 09:31 -0700, Dylan Baker wrote: > Quoting Mathieu Bridon (2018-07-05 06:17:47) > > On Python 2, the builtin functions filter() and zip() would return > > lists. > > > > On Python 3, they return iterators. > > > > Since we want to use those objects in contexts where we need lists, > > we > > need to explicitly turn them into lists. > > > > This makes the code compatible with both Python 2 and Python 3. > > > > Signed-off-by: Mathieu Bridon > > --- > > src/compiler/nir/nir_opt_algebraic.py | 2 +- > > src/mesa/main/get_hash_generator.py | 4 ++-- > > 2 files changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/src/compiler/nir/nir_opt_algebraic.py > > b/src/compiler/nir/nir_opt_algebraic.py > > index 5e07d662b0..7b2ba56990 100644 > > --- a/src/compiler/nir/nir_opt_algebraic.py > > +++ b/src/compiler/nir/nir_opt_algebraic.py > > @@ -633,7 +633,7 @@ optimizations = [ > > > > invert = OrderedDict([('feq', 'fne'), ('fne', 'feq'), ('fge', > > 'flt'), ('flt', 'fge')]) > > > > -for left, right in list(itertools.combinations(invert.keys(), 2)) > > + zip(invert.keys(), invert.keys()): > > +for left, right in list(itertools.combinations(invert.keys(), 2)) > > + list(zip(invert.keys(), invert.keys())): > > Isn't this just a really expenisve re-implementation of: > itertools.combinations_with_replacement(invert.keys(), 2) It seems to be, yes. (I was so focused on fixing the "can't concatenate list with zip" error that I completely missed it) However, since dict.keys() isn't guaranteed to always be in the same order, it is theoretically possible that: >>> zip(invert.keys(), invert.keys()) doesn't always return the same thing. That is, the following could happen: >>> d = {'A': …, 'B': …} >>> zip(d.keys(), d.keys()) ['AB', 'BA'] Which would make the whole line not equivalent to `itertools.combinations_with_replacement()` any more. In practice it probably doesn't happen though, but that means if the intention behind the code was what you suspect, then by using `itertools.combinations_with_replacement()` we'd be fixing an actual bug, not just making the script compatible with Python 3. :) -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 15/26] python: Specify the template output encoding
On Thu, 2018-07-05 at 09:14 -0700, Dylan Baker wrote: > Does it make more sense to encode, or to use io.open and open the > file in text mode? I've gone back and forth on this myself several > times. Same here, both seem equally valid and I can't really make my mind up on which one to pick. The general recommendation with Python 3 is to use unicode strings everywhere, and only encode/decode at the boundaries. I guess the boundary is actually writing to the file, so opening it in text mode and handling unicode strings (not encode them ourselves) fits that a bit better? It seems like a very weak argument though in this specific case, since we're not really doing anything with the byte-string other than just writing it directly to the file. Do you want me to do a v2 with that change? -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 12/26] python: Fix unequality comparisons
On Thu, 2018-07-05 at 09:10 -0700, Dylan Baker wrote: > Quoting Mathieu Bridon (2018-07-05 06:17:43) > > +def __ne__(self, other): > > +return not self.__eq__(other) > > This can be written as "not (self == other)", right? It can, yes. The `==` operator is going to end up calling the `__eq__` method defined just above anyway, and we're already in the implementation details of `__ne__`. So it felt more natural to me to have `__ne__` be the opposite of `__eq__` rather than the opposite of `==`. Also, `not (… == …)` feels weird, it screams "replace me by `… != …`". Which I'm worried someone not paying attention might do in the future. I don't feel very strongly about it though, so I'll change it if you do. -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 06/26] python: Better iterate over dictionaries
On Thu, 2018-07-05 at 08:48 -0700, Dylan Baker wrote: > I've asked a couple of people who have (in the past at least) had a > hard requirement on python 2.x if moving to 3.x will be okay for > them. If it's not then we may need to do something else here. I've > used six in the past (although I know a lot of other pythonistas > don't like six), so that would be an option I think. > > While this works fine, it's going to create a lot of overhead for > anyone using python 2, since some of these data structures are huge, > and returning a copy (or copy of a copy) is going to be fairly > expensive. If we can drop python 2 support that of course isn't a > problem. I tested the scripts with Python 2 as well, and they didn't seem to take significantly more time to complete. (I didn't look at memory consumption though, which is a bit hard for scripts running so fast) Are some of those platforms that require Python 2 very low-performance ones, where it would have an actual impact? I have a very slow ARM machine handy, I can try and see whether the patches make a big difference there if it helps? > Assuming that those people are okay with python 3, If everyone is ok moving fully to Python 3, then the patch series could be quite different and simpler. ^_^ -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 01/26] python: Use the print function
On Thu, 2018-07-05 at 08:40 -0700, Dylan Baker wrote: > This is a really big patch that should be mostly mechanical, It's mostly me running `2to3 --fix=print` on all those Python scripts, and adding the `from __future__ import print_function` so that it's compatible with Python 2. In a few rare instances I had to manually fix some things (e.g 2to3 had used `end=' '` and I had to replace it by `end=''`) so that the generated code would be identical to the one generated on master. -- Mathieu ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 26/26] meson: Build with Python 3
Now that all the build scripts are compatible with both Python 2 and 3, we can flip the switch and tell Meson to use the latter. Since Meson already depends on Python 3 anyway, this means we don't need two different Python stacks to build Mesa. Signed-off-by: Mathieu Bridon --- meson.build | 6 ++--- src/amd/common/meson.build| 2 +- src/amd/vulkan/meson.build| 10 +++ src/broadcom/cle/meson.build | 4 +-- src/compiler/glsl/meson.build | 4 +-- src/compiler/meson.build | 2 +- src/compiler/nir/meson.build | 14 +- src/compiler/spirv/meson.build| 4 +-- src/egl/meson.build | 4 +-- src/gallium/auxiliary/meson.build | 6 ++--- src/gallium/drivers/freedreno/meson.build | 2 +- src/gallium/drivers/r600/meson.build | 2 +- src/gallium/drivers/radeonsi/meson.build | 2 +- .../swr/rasterizer/codegen/meson.build| 8 +++--- .../swr/rasterizer/core/backends/meson.build | 4 +-- .../drivers/swr/rasterizer/jitter/meson.build | 6 ++--- src/intel/compiler/meson.build| 2 +- src/intel/genxml/meson.build | 6 ++--- src/intel/isl/meson.build | 2 +- src/intel/vulkan/meson.build | 10 +++ src/mapi/es1api/meson.build | 2 +- src/mapi/es2api/meson.build | 2 +- src/mapi/glapi/gen/meson.build| 26 +-- src/mapi/shared-glapi/meson.build | 2 +- src/mesa/drivers/dri/i965/meson.build | 2 +- src/mesa/main/meson.build | 6 ++--- src/mesa/meson.build | 6 ++--- src/meson.build | 2 +- src/util/meson.build | 2 +- src/util/xmlpool/meson.build | 2 +- src/vulkan/util/meson.build | 2 +- 31 files changed, 77 insertions(+), 77 deletions(-) diff --git a/meson.build b/meson.build index b2722c71e5..1b41373793 100644 --- a/meson.build +++ b/meson.build @@ -693,10 +693,10 @@ if with_platform_haiku pre_args += '-DHAVE_HAIKU_PLATFORM' endif -prog_python2 = find_program('python2') -has_mako = run_command(prog_python2, '-c', 'import mako') +prog_python = find_program('python3') +has_mako = run_command(prog_python, '-c', 'import mako') if has_mako.returncode() != 0 - error('Python (2.x) mako module required to build mesa.') + error('Python (3.x) mako module required to build mesa.') endif if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6') diff --git a/src/amd/common/meson.build b/src/amd/common/meson.build index 0967b1adb7..6827a02094 100644 --- a/src/amd/common/meson.build +++ b/src/amd/common/meson.build @@ -22,7 +22,7 @@ sid_tables_h = custom_target( 'sid_tables_h', input : ['sid_tables.py', 'sid.h', 'gfx9d.h'], output : 'sid_tables.h', - command : [prog_python2, '@INPUT@'], + command : [prog_python, '@INPUT@'], capture : true, ) diff --git a/src/amd/vulkan/meson.build b/src/amd/vulkan/meson.build index 22857926fa..c5c9b308c6 100644 --- a/src/amd/vulkan/meson.build +++ b/src/amd/vulkan/meson.build @@ -23,7 +23,7 @@ radv_entrypoints = custom_target( input : ['radv_entrypoints_gen.py', vk_api_xml], output : ['radv_entrypoints.h', 'radv_entrypoints.c'], command : [ -prog_python2, '@INPUT0@', '--xml', '@INPUT1@', '--outdir', +prog_python, '@INPUT0@', '--xml', '@INPUT1@', '--outdir', meson.current_build_dir() ], depend_files : files('radv_extensions.py'), @@ -34,7 +34,7 @@ radv_extensions_c = custom_target( input : ['radv_extensions.py', vk_api_xml], output : ['radv_extensions.c', 'radv_extensions.h'], command : [ -prog_python2, '@INPUT0@', '--xml', '@INPUT1@', '--out-c', '@OUTPUT0@', +prog_python, '@INPUT0@', '--xml', '@INPUT1@', '--out-c', '@OUTPUT0@', '--out-h', '@OUTPUT1@' ], ) @@ -43,7 +43,7 @@ vk_format_table_c = custom_target( 'vk_format_table.c', input : ['vk_format_table.py', 'vk_format_layout.csv'], output : 'vk_format_table.c', - command : [prog_python2, '@INPUT@'], + command : [prog_python, '@INPUT@'], depend_files : files('vk_format_parse.py'), capture : true, ) @@ -151,7 +151,7 @@ radeon_icd = custom_target( input : 'radv_i
[Mesa-dev] [PATCH 23/26] python: Rework bytes/unicode string handling
In both Python 2 and 3, opening a file without specifying the mode will open it for reading in text mode ('r'). On Python 2, the read() method of a file object opened in mode 'r' will return byte strings, while on Python 3 it will return unicode strings. Explicitly specifying the binary mode ('rb') then decoding the byte string means we always handle unicode strings on both Python 2 and 3. Which in turns means all re.match(line) will return unicode strings as well. If we also make expandCString return unicode strings, we don't need the call to the unicode() constructor any more. We were using the ugettext() method because it always returns unicode strings in Python 2, contrarily to the gettext() one which returns strings in the same type as its input. The ugettext() method doesn't exist on Python 3, so we must use the gettext() one. This is fine now that we know we only pass unicode strings to gettext(). (the return values of expandCString) The last hurdles are that Python 3 doesn't let us concatenate unicode and byte strings directly, and that Python 2's stdout wants encoded byte strings while Python 3's want unicode strings. With these changes, the script gives the same output on both Python 2 and 3. Signed-off-by: Mathieu Bridon --- src/util/xmlpool/gen_xmlpool.py | 35 +++-- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py index b0db183854..db20e2767f 100644 --- a/src/util/xmlpool/gen_xmlpool.py +++ b/src/util/xmlpool/gen_xmlpool.py @@ -60,7 +60,7 @@ def expandCString (s): octa = False num = 0 digits = 0 -r = '' +r = u'' while i < len(s): if not escape: if s[i] == '\\': @@ -128,16 +128,29 @@ def expandMatches (matches, translations, end=None): if len(matches) == 1 and i < len(translations) and \ not matches[0].expand (r'\7').endswith('\\'): suffix = ' \\' -# Expand the description line. Need to use ugettext in order to allow -# non-ascii unicode chars in the original English descriptions. -text = escapeCString (trans.ugettext (unicode (expandCString ( -matches[0].expand (r'\5')), "utf-8"))).encode("utf-8") -print(matches[0].expand (r'\1' + lang + r'\3"' + text + r'"\7') + suffix) +text = escapeCString (trans.gettext (expandCString ( +matches[0].expand (r'\5' +text = (matches[0].expand (r'\1' + lang + r'\3"' + text + r'"\7') + suffix) + +# In Python 2, stdout expects encoded byte strings, or else it will +# encode them with the ascii 'codec' +if sys.version_info.major == 2: +text = text.encode('utf-8') + +print(text) + # Expand any subsequent enum lines for match in matches[1:]: -text = escapeCString (trans.ugettext (unicode (expandCString ( -match.expand (r'\3')), "utf-8"))).encode("utf-8") -print(match.expand (r'\1"' + text + r'"\5')) +text = escapeCString (trans.gettext (expandCString ( +match.expand (r'\3' +text = match.expand (r'\1"' + text + r'"\5') + +# In Python 2, stdout expects encoded byte strings, or else it will +# encode them with the ascii 'codec' +if sys.version_info.major == 2: +text = text.encode('utf-8') + +print(text) # Expand description end if end: @@ -168,9 +181,11 @@ print("/***\ # Process the options template and generate options.h with all # translations. -template = open (template_header_path, "r") +template = open (template_header_path, "rb") descMatches = [] for line in template: +line = line.decode('utf-8') + if len(descMatches) > 0: matchENUM = reENUM.match (line) matchDESC_END = reDESC_END.match (line) -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 19/26] python: Don't abuse hex()
The hex() builtin returns a string containing the hexa-decimal representation of an integer. When the argument is not an integer, then the function calls that object's __hex__() method, if one is defined. That method is supposed to return a string. While that's not explicitly documented, that string is supposed to be a valid hexa-decimal representation for a number. Python 2 doesn't enforce this though, which is why we got away with returning things like 'NIR_TRUE' which are not numbers. In Python 3, the hex() builtin instead calls an object's __index__() method, which itself must return an integer. That integer is then automatically converted to a string with its hexa-decimal representation by the rest of the hex() function. As a result, we really can't make this compatible with Python 3 as it is. The solution is to stop using the hex() builtin, and instead use a hex() object method, which can return whatever we want, in Python 2 and 3. Signed-off-by: Mathieu Bridon --- src/compiler/nir/nir_algebraic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index 63a7cb5ad1..d53a9869de 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -88,7 +88,7 @@ class Value(object): static const ${val.c_type} ${val.name} = { { ${val.type_enum}, ${val.bit_size} }, % if isinstance(val, Constant): - ${val.type()}, { ${hex(val)} /* ${val.value} */ }, + ${val.type()}, { ${val.hex()} /* ${val.value} */ }, % elif isinstance(val, Variable): ${val.index}, /* ${val.var_name} */ ${'true' if val.is_constant else 'false'}, @@ -142,7 +142,7 @@ class Constant(Value): assert self.bit_size == 0 or self.bit_size == 32 self.bit_size = 32 - def __hex__(self): + def hex(self): if isinstance(self.value, (bool)): return 'NIR_TRUE' if self.value else 'NIR_FALSE' if isinstance(self.value, integer_types): -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 16/26] python: Explicitly use lists
On Python 2, the builtin functions filter() and zip() would return lists. On Python 3, they return iterators. Since we want to use those objects in contexts where we need lists, we need to explicitly turn them into lists. This makes the code compatible with both Python 2 and Python 3. Signed-off-by: Mathieu Bridon --- src/compiler/nir/nir_opt_algebraic.py | 2 +- src/mesa/main/get_hash_generator.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 5e07d662b0..7b2ba56990 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -633,7 +633,7 @@ optimizations = [ invert = OrderedDict([('feq', 'fne'), ('fne', 'feq'), ('fge', 'flt'), ('flt', 'fge')]) -for left, right in list(itertools.combinations(invert.keys(), 2)) + zip(invert.keys(), invert.keys()): +for left, right in list(itertools.combinations(invert.keys(), 2)) + list(zip(invert.keys(), invert.keys())): optimizations.append((('inot', ('ior(is_used_once)', (left, a, b), (right, c, d))), ('iand', (invert[left], a, b), (invert[right], c, d optimizations.append((('inot', ('iand(is_used_once)', (left, a, b), (right, c, d))), diff --git a/src/mesa/main/get_hash_generator.py b/src/mesa/main/get_hash_generator.py index facdccd8a5..37dae45e0b 100644 --- a/src/mesa/main/get_hash_generator.py +++ b/src/mesa/main/get_hash_generator.py @@ -117,8 +117,8 @@ def print_tables(tables): def merge_tables(tables): merged_tables = [] for api, indices in sorted(tables.items()): - matching_table = filter(lambda mt:mt["indices"] == indices, - merged_tables) + matching_table = list(filter(lambda mt:mt["indices"] == indices, + merged_tables)) if matching_table: matching_table[0]["apis"].append(api) else: -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 24/26] python: Use the unicode_escape codec
Python 2 had string_escape and unicode_escape codecs. Python 3 only has the latter. These work the same as far as we're concerned, so let's use the future-proof one. However, the reste of the code expects unicode strings, so we need to decode them again. Signed-off-by: Mathieu Bridon --- src/amd/common/sid_tables.py | 2 +- src/gallium/drivers/r600/egd_tables.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/amd/common/sid_tables.py b/src/amd/common/sid_tables.py index 421c2a1335..7b5e626e3e 100644 --- a/src/amd/common/sid_tables.py +++ b/src/amd/common/sid_tables.py @@ -65,7 +65,7 @@ class StringTable: """ fragments = [ '"%s\\0" /* %s */' % ( -te[0].encode('string_escape'), +te[0].encode('unicode_escape').decode(), ', '.join(str(idx) for idx in sorted(te[2])) ) for te in self.table diff --git a/src/gallium/drivers/r600/egd_tables.py b/src/gallium/drivers/r600/egd_tables.py index 7489649ec7..8a60a6229a 100644 --- a/src/gallium/drivers/r600/egd_tables.py +++ b/src/gallium/drivers/r600/egd_tables.py @@ -61,7 +61,7 @@ class StringTable: """ fragments = [ '"%s\\0" /* %s */' % ( -te[0].encode('string_escape'), +te[0].encode('unicode_escape').decode(), ', '.join(str(idx) for idx in te[2]) ) for te in self.table -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 22/26] python: Use open(), not file()
The latter is a constructor for file objects, but when actually opening a file, using the former is more idiomatic. In addition, file() is not a builtin any more in Python 3, so this makes the script compatible with both Python 2 and Python 3. Signed-off-by: Mathieu Bridon --- src/util/xmlpool/gen_xmlpool.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py index 886c1854f3..b0db183854 100644 --- a/src/util/xmlpool/gen_xmlpool.py +++ b/src/util/xmlpool/gen_xmlpool.py @@ -168,7 +168,7 @@ print("/***\ # Process the options template and generate options.h with all # translations. -template = file (template_header_path, "r") +template = open (template_header_path, "r") descMatches = [] for line in template: if len(descMatches) > 0: @@ -199,6 +199,8 @@ for line in template: else: print(line, end='') +template.close() + if len(descMatches) > 0: sys.stderr.write ("Warning: unterminated description at end of file.\n") expandMatches (descMatches, translations) -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 21/26] python: Use key-functions when sorting containers
In Python 2, the traditional way to sort containers was to use a comparison function (which returned either -1, 0 or 1 when passed two objects) and pass that as the "cmp" argument to the container's sort() method. Python 2.4 introduced key-functions, which instead only operate on a given item, and return a sorting key for this item. In general, this runs faster, because the cmp-function has to get run multiple times for each item of the container. Python 3 removed the cmp-function, enforcing usage of key-functions instead. This change makes the script compatible with Python 2 and Python 3. Signed-off-by: Mathieu Bridon --- src/mapi/mapi_abi.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mapi/mapi_abi.py b/src/mapi/mapi_abi.py index 67fdb10650..19fdc4572a 100644 --- a/src/mapi/mapi_abi.py +++ b/src/mapi/mapi_abi.py @@ -32,6 +32,7 @@ import os GLAPI = os.path.join(".", os.path.dirname(sys.argv[0]), "glapi/gen") sys.path.append(GLAPI) +from operator import attrgetter import re from optparse import OptionParser import gl_XML @@ -305,7 +306,7 @@ class ABIPrinter(object): # sort entries by their names self.entries_sorted_by_names = self.entries[:] -self.entries_sorted_by_names.sort(lambda x, y: cmp(x.name, y.name)) +self.entries_sorted_by_names.sort(key=attrgetter('name')) self.indent = ' ' * 3 self.noop_warn = 'noop_warn' @@ -455,7 +456,7 @@ class ABIPrinter(object): """Return the string pool for use by stubs.""" # sort entries by their names sorted_entries = self.entries[:] -sorted_entries.sort(lambda x, y: cmp(x.name, y.name)) +sorted_entries.sort(key=attrgetter('name')) pool = [] offsets = {} -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 25/26] python: Explicitly add the 'L' suffix on Python 3
Python 2 had two integer types: int and long. Python 3 dropped the latter, as it made the int type automatically support bigger numbers. As a result, Python 3 lost the 'L' suffix on integer litterals. This probably doesn't make much difference when compiling the generated C code, but adding it explicitly means that both Python 2 and 3 generate the exact same C code anyway, which makes it easier to compare and check for discrepencies when moving to Python 3. Signed-off-by: Mathieu Bridon --- src/compiler/nir/nir_algebraic.py | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index d53a9869de..2081c29034 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -148,7 +148,16 @@ class Constant(Value): if isinstance(self.value, integer_types): return hex(self.value) elif isinstance(self.value, float): - return hex(struct.unpack('Q', struct.pack('d', self.value))[0]) + i = struct.unpack('Q', struct.pack('d', self.value))[0] + h = hex(i) + + # On Python 2 this 'L' suffix is automatically added, but not on Python 3 + # Adding it explicitly makes the generated file identical, regardless + # of the Python version running this script. + if h[-1] != 'L' and i > sys.maxsize: +h += 'L' + + return h else: assert False -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 14/26] python: Better get character ordinals
In Python 2, iterating over a byte-string yields single-byte strings, and we can pass them to ord() to get the corresponding integer. In Python 3, iterating over a byte-string directly yields those integers. Transforming the byte string into a bytearray gives us a list of the integers corresponding to each byte in the string, removing the need to call ord(). This makes the script compatible with both Python 2 and 3. Signed-off-by: Mathieu Bridon --- src/intel/genxml/gen_zipped_file.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/intel/genxml/gen_zipped_file.py b/src/intel/genxml/gen_zipped_file.py index 6d8daf4d69..616409183f 100644 --- a/src/intel/genxml/gen_zipped_file.py +++ b/src/intel/genxml/gen_zipped_file.py @@ -62,8 +62,8 @@ def main(): print("") print("static const uint8_t compress_genxmls[] = {") print(" ", end='') -for i, c in enumerate(compressed_data, start=1): -print("0x%.2x, " % ord(c), end='\n ' if not i % 12 else '') +for i, c in enumerate(bytearray(compressed_data), start=1): +print("0x%.2x, " % c, end='\n ' if not i % 12 else '') print('\n};') -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 18/26] python: Better check for integer types
Python 3 lost the long type: now everything is an int, with the right size. This commit makes the script compatible with Python 2 (where we check for both int and long) and Python 3 (where we only check for int). Signed-off-by: Mathieu Bridon --- src/compiler/nir/nir_algebraic.py | 8 +--- src/gallium/auxiliary/util/u_format_pack.py | 12 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index e17e2d26b9..63a7cb5ad1 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -36,10 +36,12 @@ import traceback from nir_opcodes import opcodes try: +integer_types = (int, long) string_types = (str, unicode) except NameError: # This is Python 3 +integer_types = (int, ) string_types = (bytes, str) _type_re = re.compile(r"(?Pint|uint|bool|float)?(?P\d+)?") @@ -79,7 +81,7 @@ class Value(object): return val elif isinstance(val, string_types): return Variable(val, name_base, varset) - elif isinstance(val, (bool, int, long, float)): + elif isinstance(val, (bool, float) + integer_types): return Constant(val, name_base) __template = mako.template.Template(""" @@ -143,7 +145,7 @@ class Constant(Value): def __hex__(self): if isinstance(self.value, (bool)): return 'NIR_TRUE' if self.value else 'NIR_FALSE' - if isinstance(self.value, (int, long)): + if isinstance(self.value, integer_types): return hex(self.value) elif isinstance(self.value, float): return hex(struct.unpack('Q', struct.pack('d', self.value))[0]) @@ -153,7 +155,7 @@ class Constant(Value): def type(self): if isinstance(self.value, (bool)): return "nir_type_bool32" - elif isinstance(self.value, (int, long)): + elif isinstance(self.value, integer_types): return "nir_type_int" elif isinstance(self.value, float): return "nir_type_float" diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index 1cfd85fb7f..c753336a84 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -41,6 +41,14 @@ from __future__ import print_function from u_format_parse import * +try: +integer_types = (int, long) + +except NameError: +# This is Python 3 +integer_types = (int, ) + + def inv_swizzles(swizzles): '''Return an array[4] of inverse swizzle terms''' '''Only pick the first matching value to avoid l8 getting blue and i8 getting alpha''' @@ -212,7 +220,7 @@ def truncate_mantissa(x, bits): '''Truncate an integer so it can be represented exactly with a floating point mantissa''' -assert isinstance(x, (int, long)) +assert isinstance(x, integer_types) s = 1 if x < 0: @@ -236,7 +244,7 @@ def value_to_native(type, value): '''Get the value of unity for this type.''' if type.type == FLOAT: if type.size <= 32 \ -and isinstance(value, (int, long)): +and isinstance(value, integer_types): return truncate_mantissa(value, 23) return value if type.type == FIXED: -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 11/26] python: Fix rich comparisons
Python 3 lost the cmp() builtin, and doesn't call objects __cmp__() methods any more to compare them. Instead, Python 3 requires implementing the rich comparison methods explicitly: __eq__(), __ne(), __lt__(), __le__(), __gt__() and __ge__(). Fortunately those are trivial to implement by just calling the existing __cmp__() method, which makes the code compatible with both Python 2 and Python 3. This commit only implements the comparison methods which are actually used by the build scripts. In addition, this commit brings back to Python 3 the cmp() builtin method as required. Signed-off-by: Mathieu Bridon --- src/amd/vulkan/radv_extensions.py | 6 +- src/intel/vulkan/anv_extensions.py | 6 +- src/mapi/mapi_abi.py | 13 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/amd/vulkan/radv_extensions.py b/src/amd/vulkan/radv_extensions.py index a0f1038110..7f48d77629 100644 --- a/src/amd/vulkan/radv_extensions.py +++ b/src/amd/vulkan/radv_extensions.py @@ -150,7 +150,11 @@ class VkVersion: other = copy.copy(other) other.patch = self.patch -return self.__int_ver().__cmp__(other.__int_ver()) +return self.__int_ver() - other.__int_ver() + +def __gt__(self, other): +return self.__cmp__(other) > 0 + MAX_API_VERSION = VkVersion(MAX_API_VERSION) diff --git a/src/intel/vulkan/anv_extensions.py b/src/intel/vulkan/anv_extensions.py index 0f99f58ecb..213cfdc551 100644 --- a/src/intel/vulkan/anv_extensions.py +++ b/src/intel/vulkan/anv_extensions.py @@ -162,7 +162,11 @@ class VkVersion: other = copy.copy(other) other.patch = self.patch -return self.__int_ver().__cmp__(other.__int_ver()) +return self.__int_ver() - other.__int_ver() + +def __gt__(self, other): +return self.__cmp__(other) > 0 + MAX_API_VERSION = VkVersion('0.0.0') diff --git a/src/mapi/mapi_abi.py b/src/mapi/mapi_abi.py index be1d15d922..67fdb10650 100644 --- a/src/mapi/mapi_abi.py +++ b/src/mapi/mapi_abi.py @@ -38,6 +38,15 @@ import gl_XML import glX_XML +try: +cmp + +except NameError: +# Python 3 does not have cmp() +def cmp(a, b): +return ((a > b) - (a < b)) + + # number of dynamic entries ABI_NUM_DYNAMIC_ENTRIES = 256 @@ -135,6 +144,10 @@ class ABIEntry(object): return res +def __lt__(self, other): +return self.__cmp__(other) < 0 + + def abi_parse_xml(xml): """Parse a GLAPI XML file for ABI entries.""" api = gl_XML.parse_GL_API(xml, glX_XML.glx_item_factory()) -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 20/26] python: Open file in binary mode
The XML parser wants byte strings, not unicode strings. In both Python 2 and 3, opening a file without specifying the mode will open it for reading in text mode ('r'). On Python 2, the read() method of the file object will return byte strings, while on Python 3 it will return unicode strings. Explicitly specifying the binary mode ('rb') makes the behaviour identical in both Python 2 and 3, returning what the XML parser expects. Signed-off-by: Mathieu Bridon --- src/intel/genxml/gen_bits_header.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/intel/genxml/gen_bits_header.py b/src/intel/genxml/gen_bits_header.py index e31e9ff103..dcd6ccb7d9 100644 --- a/src/intel/genxml/gen_bits_header.py +++ b/src/intel/genxml/gen_bits_header.py @@ -282,7 +282,7 @@ class XmlParser(object): self.container = None def parse(self, filename): -with open(filename) as f: +with open(filename, 'rb') as f: self.parser.ParseFile(f) def start_element(self, name, attrs): -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 08/26] python: Better use iterators
In Python 2, iterators had a .next() method. In Python 3, instead they have a .__next__() method, which is automatically called by the next() builtin. In addition, it is better to use the iter() builtin to create an iterator, rather than calling its __iter__() method. These were also introduced in Python 2.6, so using it makes the script compatible with Python 2 and 3. Signed-off-by: Mathieu Bridon --- src/compiler/glsl/ir_expression_operation.py | 4 +++- src/compiler/nir/nir_algebraic.py| 4 ++-- src/mapi/glapi/gen/glX_XML.py| 17 + src/mapi/glapi/gen/gl_XML.py | 12 ++-- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/compiler/glsl/ir_expression_operation.py b/src/compiler/glsl/ir_expression_operation.py index d8542925a0..b3dac3da3f 100644 --- a/src/compiler/glsl/ir_expression_operation.py +++ b/src/compiler/glsl/ir_expression_operation.py @@ -62,7 +62,7 @@ class type_signature_iter(object): def __iter__(self): return self - def next(self): + def __next__(self): if self.i < len(self.source_types): i = self.i self.i += 1 @@ -76,6 +76,8 @@ class type_signature_iter(object): else: raise StopIteration() + next = __next__ + uint_type = type("unsigned", "u", "GLSL_TYPE_UINT") int_type = type("int", "i", "GLSL_TYPE_INT") diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index 8c0b530f69..fda72d3c69 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -56,7 +56,7 @@ class VarSet(object): def __getitem__(self, name): if name not in self.names: assert not self.immutable, "Unknown replacement variable: " + name - self.names[name] = self.ids.next() + self.names[name] = next(self.ids) return self.names[name] @@ -468,7 +468,7 @@ condition_list = ['true'] class SearchAndReplace(object): def __init__(self, transform): - self.id = _optimization_ids.next() + self.id = next(_optimization_ids) search = transform[0] replace = transform[1] diff --git a/src/mapi/glapi/gen/glX_XML.py b/src/mapi/glapi/gen/glX_XML.py index bbcecd6023..4ec8cd766f 100644 --- a/src/mapi/glapi/gen/glX_XML.py +++ b/src/mapi/glapi/gen/glX_XML.py @@ -296,7 +296,7 @@ class glx_function(gl_XML.gl_function): parameters.extend( temp[1] ) if include_variable_parameters: parameters.extend( temp[2] ) -return parameters.__iter__() +return iter(parameters) def parameterIterateCounters(self): @@ -304,7 +304,7 @@ class glx_function(gl_XML.gl_function): for name in self.counter_list: temp.append( self.parameters_by_name[ name ] ) -return temp.__iter__() +return iter(temp) def parameterIterateOutputs(self): @@ -547,13 +547,14 @@ class glx_function_iterator(object): return self -def next(self): -f = self.iterator.next() +def __next__(self): +while True: +f = next(self.iterator) -if f.client_supported_for_indirect(): -return f -else: -return self.next() +if f.client_supported_for_indirect(): +return f + +next = __next__ class glx_api(gl_XML.gl_api): diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py index 3a4f59221e..bfbb1ec6e0 100644 --- a/src/mapi/glapi/gen/gl_XML.py +++ b/src/mapi/glapi/gen/gl_XML.py @@ -782,9 +782,9 @@ class gl_function( gl_item ): def parameterIterator(self, name = None): if name is not None: -return self.entry_point_parameters[name].__iter__(); +return iter(self.entry_point_parameters[name]); else: -return self.parameters.__iter__(); +return iter(self.parameters); def get_parameter_string(self, entrypoint = None): @@ -996,7 +996,7 @@ class gl_api(object): for name in names: functions.append(lists[func_cat_type][key][name]) -return functions.__iter__() +return iter(functions) def functionIterateByOffset(self): @@ -1017,7 +1017,7 @@ class gl_api(object): if temp[i]: list.append(temp[i]) -return list.__iter__(); +return iter(list); def functionIterateAll(self): @@ -1031,7 +1031,7 @@ class gl_api(object): for enum in keys: list.append( self.enums_by_name[ enum ] ) -return list.__iter__() +return iter(list) def categoryIterate(self): @@ -1049,7 +1049,7 @@ class gl_api(object): for key in keys: list.append(self.categories[cat_type][key]) -return list.__iter__() +
[Mesa-dev] [PATCH 15/26] python: Specify the template output encoding
We're trying to write a unicode string (i.e decoded) to a file opened in binary (i.e encoded) mode. In Python 2 this works, because of the automatic conversion between byte and unicode strings. In Python 3 this fails though, as no automatic conversion is attempted. This change makes the scripts compatible with both versions of Python. Signed-off-by: Mathieu Bridon --- src/compiler/nir/nir_intrinsics_c.py | 2 +- src/compiler/nir/nir_intrinsics_h.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_intrinsics_c.py b/src/compiler/nir/nir_intrinsics_c.py index 98af67c38a..ac45b94d49 100644 --- a/src/compiler/nir/nir_intrinsics_c.py +++ b/src/compiler/nir/nir_intrinsics_c.py @@ -64,7 +64,7 @@ def main(): path = os.path.join(args.outdir, 'nir_intrinsics.c') with open(path, 'wb') as f: -f.write(Template(template).render(INTR_OPCODES=INTR_OPCODES)) +f.write(Template(template, output_encoding='utf-8').render(INTR_OPCODES=INTR_OPCODES)) if __name__ == '__main__': main() diff --git a/src/compiler/nir/nir_intrinsics_h.py b/src/compiler/nir/nir_intrinsics_h.py index 8a4f0d501e..8abc6a8626 100644 --- a/src/compiler/nir/nir_intrinsics_h.py +++ b/src/compiler/nir/nir_intrinsics_h.py @@ -53,7 +53,7 @@ def main(): path = os.path.join(args.outdir, 'nir_intrinsics.h') with open(path, 'wb') as f: -f.write(Template(template).render(INTR_OPCODES=INTR_OPCODES)) +f.write(Template(template, output_encoding='utf-8').render(INTR_OPCODES=INTR_OPCODES)) if __name__ == '__main__': main() -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 17/26] python: Better check for string types
Python 2 byte strings were called "str", and its unicode strings were called "unicode". In Python 3, they are called "bytes" and "str". This commit makes the script compatible with Python 2 and Python 3, checking for the right types on both. Signed-off-by: Mathieu Bridon --- src/compiler/nir/nir_algebraic.py | 9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index fda72d3c69..e17e2d26b9 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -35,6 +35,13 @@ import traceback from nir_opcodes import opcodes +try: +string_types = (str, unicode) + +except NameError: +# This is Python 3 +string_types = (bytes, str) + _type_re = re.compile(r"(?Pint|uint|bool|float)?(?P\d+)?") def type_bits(type_str): @@ -70,7 +77,7 @@ class Value(object): return Expression(val, name_base, varset) elif isinstance(val, Expression): return val - elif isinstance(val, (str, unicode)): + elif isinstance(val, string_types): return Variable(val, name_base, varset) elif isinstance(val, (bool, int, long, float)): return Constant(val, name_base) -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 07/26] python: Better sort dictionary keys/values
In Python 2, dict.keys() and dict.values() both return a list, which can be sorted in two ways: * l.sort() modifies the list in-place; * sorted(l) returns a new, sorted list; In Python 3, dict.keys() and dict.values() do not return lists any more, but iterators. Iterators do not have a .sort() method. This commit moves the build scripts to using sorted() on dict keys and values, which makes them compatible with both Python 2 and Python 3. Signed-off-by: Mathieu Bridon --- src/mapi/glapi/gen/glX_proto_send.py | 3 +-- src/mapi/glapi/gen/glX_proto_size.py | 6 ++ src/mapi/glapi/gen/gl_XML.py | 12 src/mapi/glapi/gen/gl_procs.py | 3 +-- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py index c389872044..fba2f0cc1e 100644 --- a/src/mapi/glapi/gen/glX_proto_send.py +++ b/src/mapi/glapi/gen/glX_proto_send.py @@ -391,8 +391,7 @@ static const struct proc_pair const char *name; _glapi_proc proc; } proc_pairs[%d] = {""" % len(procs)) -names = procs.keys() -names.sort() +names = sorted(procs.keys()) for i in xrange(len(names)): comma = ',' if i < len(names) - 1 else '' print(' { "%s", (_glapi_proc) gl%s }%s' % (names[i], procs[names[i]], comma)) diff --git a/src/mapi/glapi/gen/glX_proto_size.py b/src/mapi/glapi/gen/glX_proto_size.py index 18a6f2e502..2a843c3e24 100644 --- a/src/mapi/glapi/gen/glX_proto_size.py +++ b/src/mapi/glapi/gen/glX_proto_size.py @@ -208,8 +208,7 @@ class glx_enum_function(object): for enum_obj in self.enums[e]: list[ enum_obj.priority() ] = enum_obj.name -keys = list.keys() -keys.sort() +keys = sorted(list.keys()) for k in keys: j = list[k] if first: @@ -275,8 +274,7 @@ class glx_server_enum_function(glx_enum_function): o = f.offset_of( param_name ) foo[o] = param_name -keys = foo.keys() -keys.sort() +keys = sorted(foo.keys()) for o in keys: p = f.parameters_by_name[ foo[o] ] diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py index fcf8e62d3f..3a4f59221e 100644 --- a/src/mapi/glapi/gen/gl_XML.py +++ b/src/mapi/glapi/gen/gl_XML.py @@ -988,12 +988,10 @@ class gl_api(object): functions = [] for func_cat_type in range(0,4): -keys = lists[func_cat_type].keys() -keys.sort() +keys = sorted(lists[func_cat_type].keys()) for key in keys: -names = lists[func_cat_type][key].keys() -names.sort() +names = sorted(lists[func_cat_type][key].keys()) for name in names: functions.append(lists[func_cat_type][key][name]) @@ -1027,8 +1025,7 @@ class gl_api(object): def enumIterateByName(self): -keys = self.enums_by_name.keys() -keys.sort() +keys = sorted(self.enums_by_name.keys()) list = [] for enum in keys: @@ -1047,8 +1044,7 @@ class gl_api(object): list = [] for cat_type in range(0,4): -keys = self.categories[cat_type].keys() -keys.sort() +keys = sorted(self.categories[cat_type].keys()) for key in keys: list.append(self.categories[cat_type][key]) diff --git a/src/mapi/glapi/gen/gl_procs.py b/src/mapi/glapi/gen/gl_procs.py index 5718f42ab6..4bd3321610 100644 --- a/src/mapi/glapi/gen/gl_procs.py +++ b/src/mapi/glapi/gen/gl_procs.py @@ -144,8 +144,7 @@ typedef struct { print('') print('/* OpenGL ES specific prototypes */') print('') -keys = categories.keys() -keys.sort() +keys = sorted(categories.keys()) for key in keys: print('/* category %s */' % key) print("\n".join(categories[key])) -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 09/26] python: Use range() instead of xrange()
Python 2 has a range() function which returns a list, and an xrange() one which returns an iterator. Python 3 lost the function returning a list, and renamed the function returning an iterator as range(). As a result, using range() makes the scripts compatible with both Python versions 2 and 3. Signed-off-by: Mathieu Bridon --- src/amd/vulkan/radv_entrypoints_gen.py | 2 +- src/broadcom/cle/gen_pack_header.py | 2 +- src/compiler/glsl/ir_expression_operation.py | 2 +- src/compiler/nir/nir_opcodes.py | 4 ++-- src/intel/vulkan/anv_entrypoints_gen.py | 2 +- src/mapi/glapi/gen/glX_proto_send.py | 2 +- src/mapi/glapi/gen/gl_XML.py | 2 +- src/mapi/glapi/gen/gl_gentable.py| 4 ++-- src/mapi/mapi_abi.py | 2 +- src/mesa/main/format_parser.py | 4 ++-- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/amd/vulkan/radv_entrypoints_gen.py b/src/amd/vulkan/radv_entrypoints_gen.py index 9c4dfd02a0..ca022bcbb0 100644 --- a/src/amd/vulkan/radv_entrypoints_gen.py +++ b/src/amd/vulkan/radv_entrypoints_gen.py @@ -136,7 +136,7 @@ static const struct string_map_entry string_map_entries[] = { /* Hash table stats: * size ${len(strmap.sorted_strings)} entries * collisions entries: -% for i in xrange(10): +% for i in range(10): * ${i}${'+' if i == 9 else ' '} ${strmap.collisions[i]} % endfor */ diff --git a/src/broadcom/cle/gen_pack_header.py b/src/broadcom/cle/gen_pack_header.py index c6e1c564e6..8ad54464cb 100644 --- a/src/broadcom/cle/gen_pack_header.py +++ b/src/broadcom/cle/gen_pack_header.py @@ -216,7 +216,7 @@ class Group(object): first_byte = field.start // 8 last_byte = field.end // 8 -for b in xrange(first_byte, last_byte + 1): +for b in range(first_byte, last_byte + 1): if not b in bytes: bytes[b] = self.Byte() diff --git a/src/compiler/glsl/ir_expression_operation.py b/src/compiler/glsl/ir_expression_operation.py index b3dac3da3f..16b98690a6 100644 --- a/src/compiler/glsl/ir_expression_operation.py +++ b/src/compiler/glsl/ir_expression_operation.py @@ -116,7 +116,7 @@ constant_template_common = mako.template.Template("""\ constant_template_vector_scalar = mako.template.Template("""\ case ${op.get_enum_name()}: % if "mixed" in op.flags: -% for i in xrange(op.num_operands): +% for i in range(op.num_operands): assert(op[${i}]->type->base_type == ${op.source_types[0].glsl_type} || % for src_type in op.source_types[1:-1]: op[${i}]->type->base_type == ${src_type.glsl_type} || diff --git a/src/compiler/nir/nir_opcodes.py b/src/compiler/nir/nir_opcodes.py index 3c3316dcaa..b03c5da2ea 100644 --- a/src/compiler/nir/nir_opcodes.py +++ b/src/compiler/nir/nir_opcodes.py @@ -367,8 +367,8 @@ for (unsigned bit = 0; bit < bit_size; bit++) { """) -for i in xrange(1, 5): - for j in xrange(1, 5): +for i in range(1, 5): + for j in range(1, 5): unop_horiz("fnoise{0}_{1}".format(i, j), i, tfloat, j, tfloat, "0.0f") diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py index 8a37336496..5e2cd0740a 100644 --- a/src/intel/vulkan/anv_entrypoints_gen.py +++ b/src/intel/vulkan/anv_entrypoints_gen.py @@ -145,7 +145,7 @@ static const struct string_map_entry string_map_entries[] = { /* Hash table stats: * size ${len(strmap.sorted_strings)} entries * collisions entries: -% for i in xrange(10): +% for i in range(10): * ${i}${'+' if i == 9 else ' '} ${strmap.collisions[i]} % endfor */ diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py index fba2f0cc1e..a920ecc012 100644 --- a/src/mapi/glapi/gen/glX_proto_send.py +++ b/src/mapi/glapi/gen/glX_proto_send.py @@ -392,7 +392,7 @@ static const struct proc_pair _glapi_proc proc; } proc_pairs[%d] = {""" % len(procs)) names = sorted(procs.keys()) -for i in xrange(len(names)): +for i in range(len(names)): comma = ',' if i < len(names) - 1 else '' print(' { "%s", (_glapi_proc) gl%s }%s' % (names[i], procs[names[i]], comma)) print("""}; diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py index bfbb1ec6e0..96dc1b3c12 100644 --- a/src/mapi/glapi/gen/gl_XML.py +++ b/src/mapi/glapi/gen/gl_XML.py @@ -834,7 +834,7 @@ class gl_function( gl_item ): versions. """ result = [] -for entry_point, api_to_ver in self.entry_point_api_map.iteritems(): +for entry_point, api_to_ver in self.entry_point_api_map.items(): if api not in api_to_ver:
[Mesa-dev] [PATCH 13/26] python: Explicitly use byte strings
In both Python 2 and 3, zlib.Compress.compress() takes a byte string, and returns a byte string as well. In Python 2, the script was working because: 1. string literalls were byte strings; 2. opening a file in unicode mode, reading from it, then passing the unicode string to compress() would automatically encode to a byte string; On Python 3, the above two points are not valid any more, so: 1. zlib.Compress.compress() refuses the passed unicode string; 2. compressed_data, defined as an empty unicode string literal, can't be concatenated with the byte string returned by compress(); This commit fixes this by explicitly using byte strings where appropriate, so that the script works on both Python 2 and 3. Signed-off-by: Mathieu Bridon --- src/intel/genxml/gen_zipped_file.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/intel/genxml/gen_zipped_file.py b/src/intel/genxml/gen_zipped_file.py index af2008bea0..6d8daf4d69 100644 --- a/src/intel/genxml/gen_zipped_file.py +++ b/src/intel/genxml/gen_zipped_file.py @@ -42,10 +42,10 @@ def main(): print("} genxml_files_table[] = {") xml_offset = 0 -compressed_data = '' +compressed_data = b'' for i in range(1, len(sys.argv)): filename = sys.argv[i] -xml = open(filename).read() +xml = open(filename, "rb").read() xml_length = len(xml) root = et.fromstring(xml) -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 12/26] python: Fix unequality comparisons
On Python 3, executing `foo != bar` will first try to call foo.__ne__(bar), and fallback on the opposite result of foo.__eq__(bar). Python 2 does not do that. As a result, those __eq__ methods were never called, when we were testing for inequality. Expliclty adding the __ne__ methods fixes this issue, in a way that is compatible with both Python 2 and 3. However, this means the __eq__ methods are now called when testing for `foo != None`, so they need to be guarded correctly. Signed-off-by: Mathieu Bridon --- src/amd/vulkan/vk_format_parse.py| 6 ++ src/gallium/auxiliary/util/u_format_parse.py | 6 ++ src/mesa/main/format_parser.py | 6 ++ 3 files changed, 18 insertions(+) diff --git a/src/amd/vulkan/vk_format_parse.py b/src/amd/vulkan/vk_format_parse.py index 00cf1adf5a..778eae61ba 100644 --- a/src/amd/vulkan/vk_format_parse.py +++ b/src/amd/vulkan/vk_format_parse.py @@ -73,8 +73,14 @@ class Channel: return s def __eq__(self, other): +if other is None: +return False + return self.type == other.type and self.norm == other.norm and self.pure == other.pure and self.size == other.size and self.scaled == other.scaled +def __ne__(self, other): +return not self.__eq__(other) + def max(self): '''Maximum representable number.''' if self.type == FLOAT: diff --git a/src/gallium/auxiliary/util/u_format_parse.py b/src/gallium/auxiliary/util/u_format_parse.py index 315c771081..e60b317e08 100644 --- a/src/gallium/auxiliary/util/u_format_parse.py +++ b/src/gallium/auxiliary/util/u_format_parse.py @@ -69,8 +69,14 @@ class Channel: return s def __eq__(self, other): +if other is None: +return False + return self.type == other.type and self.norm == other.norm and self.pure == other.pure and self.size == other.size +def __ne__(self, other): +return not self.__eq__(other) + def max(self): '''Maximum representable number.''' if self.type == FLOAT: diff --git a/src/mesa/main/format_parser.py b/src/mesa/main/format_parser.py index 3321ad33ff..c0d73c9d22 100644 --- a/src/mesa/main/format_parser.py +++ b/src/mesa/main/format_parser.py @@ -61,8 +61,14 @@ class Channel: return s def __eq__(self, other): + if other is None: + return False + return self.type == other.type and self.norm == other.norm and self.size == other.size + def __ne__(self, other): + return not self.__eq__(other) + def max(self): """Returns the maximum representable number.""" if self.type == FLOAT: -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 10/26] python: Use explicit integer divisions
In Python 2, divisions return an integer: >>> 32 / 4 8 In Python 3 though, they return floats: >>> 32 / 4 8.0 Explicitly converting to integers make the scripts compatible with both Python 2 and 3. Signed-off-by: Mathieu Bridon --- src/gallium/auxiliary/util/u_format_pack.py | 2 +- src/gallium/auxiliary/util/u_format_parse.py | 4 ++-- src/mapi/glapi/gen/glX_proto_send.py | 2 +- src/mesa/main/format_info.py | 2 +- src/mesa/main/format_pack.py | 6 +++--- src/mesa/main/format_unpack.py | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py index 7a952a48b3..1cfd85fb7f 100644 --- a/src/gallium/auxiliary/util/u_format_pack.py +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -240,7 +240,7 @@ def value_to_native(type, value): return truncate_mantissa(value, 23) return value if type.type == FIXED: -return int(value * (1 << (type.size/2))) +return int(value * (1 << int(type.size/2))) if not type.norm: return int(value) if type.type == UNSIGNED: diff --git a/src/gallium/auxiliary/util/u_format_parse.py b/src/gallium/auxiliary/util/u_format_parse.py index c0456f6d15..315c771081 100644 --- a/src/gallium/auxiliary/util/u_format_parse.py +++ b/src/gallium/auxiliary/util/u_format_parse.py @@ -76,7 +76,7 @@ class Channel: if self.type == FLOAT: return VERY_LARGE if self.type == FIXED: -return (1 << (self.size/2)) - 1 +return (1 << int(self.size/2)) - 1 if self.norm: return 1 if self.type == UNSIGNED: @@ -90,7 +90,7 @@ class Channel: if self.type == FLOAT: return -VERY_LARGE if self.type == FIXED: -return -(1 << (self.size/2)) +return -(1 << int(self.size/2)) if self.type == UNSIGNED: return 0 if self.norm: diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py index a920ecc012..28f8a0d67b 100644 --- a/src/mapi/glapi/gen/glX_proto_send.py +++ b/src/mapi/glapi/gen/glX_proto_send.py @@ -809,7 +809,7 @@ generic_%u_byte( GLint rop, const void * ptr ) # Dividing by the array size (1 for # non-arrays) gives us this. -s = p.size() / p.get_element_count() +s = int(p.size() / p.get_element_count()) print(" %s __glXReadReply(dpy, %s, %s, %s);" % (return_str, s, p.name, aa)) got_reply = 1 diff --git a/src/mesa/main/format_info.py b/src/mesa/main/format_info.py index bbecaa2451..285bf13e1b 100644 --- a/src/mesa/main/format_info.py +++ b/src/mesa/main/format_info.py @@ -198,7 +198,7 @@ for fmat in formats: chan = fmat.array_element() norm = chan.norm or chan.type == parser.FLOAT print(' .ArrayFormat = MESA_ARRAY_FORMAT({0}),'.format(', '.join([ - str(chan.size / 8), + str(int(chan.size / 8)), str(int(chan.sign)), str(int(chan.type == parser.FLOAT)), str(int(norm)), diff --git a/src/mesa/main/format_pack.py b/src/mesa/main/format_pack.py index d3c8d24acd..3b69580a93 100644 --- a/src/mesa/main/format_pack.py +++ b/src/mesa/main/format_pack.py @@ -356,7 +356,7 @@ _mesa_pack_ubyte_rgba_row(mesa_format format, GLuint n, case ${f.name}: for (i = 0; i < n; ++i) { pack_ubyte_${f.short_name()}(src[i], d); - d += ${f.block_size() / 8}; + d += ${int(f.block_size() / 8)}; } break; %endfor @@ -388,7 +388,7 @@ _mesa_pack_uint_rgba_row(mesa_format format, GLuint n, case ${f.name}: for (i = 0; i < n; ++i) { pack_uint_${f.short_name()}(src[i], d); - d += ${f.block_size() / 8}; + d += ${int(f.block_size() / 8)}; } break; %endfor @@ -418,7 +418,7 @@ _mesa_pack_float_rgba_row(mesa_format format, GLuint n, case ${f.name}: for (i = 0; i < n; ++i) { pack_float_${f.short_name()}(src[i], d); - d += ${f.block_size() / 8}; + d += ${int(f.block_size() / 8)}; } break; %endfor diff --git a/src/mesa/main/format_unpack.py b/src/mesa/main/format_unpack.py index 286c08e621..feddaed5cd 100644 --- a/src/mesa/main/format_unpack.py +++ b/src/mesa/main/format_unpack.py @@ -322,7 +322,7 @@ _mesa_unpack_rgba_row(mesa_format format, GLuint n, case ${f.name}: for (i = 0; i < n; ++i) { unpack_float_${f.short_name()}(s, dst[i]); - s += ${f.block_size() / 8}; + s += ${int(f.block_size() / 8)}; } break; %endfor @@ -355,7 +355,7 @@ _mesa_unpack_ubyte_rgba_row(mesa_format format, GLuint n, case ${f.name}:
[Mesa-dev] meson: Build with Python 3
This patch series allows building Mesa with Python 3. The build scripts are kept compatible with Python 2 as well, for those platforms which don't have Python 3 yet. In fact, only the Meson build system is moved to Python 3, since it is the only one I'm 100% sure has Python 3 available. (Meson itself requires it) I briefly thought about adding an option to the Meson build system to control which version of Python to build with, but decided against. I'm happy to add it if you think it's necessary. I checked (with the `diff` command) that all the scripts output the exact same things when built with Meson on: * master (as of f9b6dfd919 which includes my patches to make the build output reproducible) * the second to last patch in this series (that is, all the scripts changed but still building with Python 2) * the last patch in this series (that is, with Python 3) Each patch fixes a single type of problem in multiple scripts/subsystems. As a result, it should be possible to review and merge each patch independently (but probably not in order), without breaking the build. It's a lot of changes: 86 files changed, 1965 insertions(+), 1833 deletions(-) The end goal is to be able to eventually remove Python 2 from future versions of the Flatpak Freedesktop SDK, Mesa being one of the last few things still requiring it. For those who prefer reviewing a git repo, I have pushed the changes to a fork on the FDO Gitlab: * a branch compatible with both Python 2 and 3, but still building with Python 2: https://gitlab.freedesktop.org/bochecha/mesa/tree/python-2-and-3 * a branch building with Python 3: https://gitlab.freedesktop.org/bochecha/mesa/tree/python3 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 06/26] python: Better iterate over dictionaries
In Python 2, dictionaries have 2 sets of methods to iterate over their keys and values: keys()/values()/items() and iterkeys()/itervalues()/iteritems(). The former return lists while the latter return iterators. Python 3 dropped the method which return lists, and renamed the methods returning iterators to keys()/values()/items(). Using those names makes the scripts compatible with both Python 2 and 3. Signed-off-by: Mathieu Bridon --- src/amd/vulkan/radv_entrypoints_gen.py | 2 +- src/compiler/nir/nir_algebraic.py| 2 +- src/compiler/nir/nir_builder_opcodes_h.py| 4 ++-- src/compiler/nir/nir_constant_expressions.py | 4 ++-- src/compiler/nir/nir_intrinsics_c.py | 2 +- src/compiler/nir/nir_opcodes_c.py| 2 +- src/compiler/nir/nir_opcodes_h.py| 2 +- src/intel/genxml/gen_bits_header.py | 10 +- src/intel/vulkan/anv_entrypoints_gen.py | 2 +- src/mapi/glapi/gen/gl_XML.py | 12 ++-- src/mapi/glapi/gen/gl_gentable.py| 4 ++-- src/mesa/drivers/dri/i965/brw_oa.py | 4 ++-- 12 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/amd/vulkan/radv_entrypoints_gen.py b/src/amd/vulkan/radv_entrypoints_gen.py index bef0c447f6..9c4dfd02a0 100644 --- a/src/amd/vulkan/radv_entrypoints_gen.py +++ b/src/amd/vulkan/radv_entrypoints_gen.py @@ -433,7 +433,7 @@ def get_entrypoints(doc, entrypoints_to_defines, start_index): e_clone.name = e.name entrypoints[e.name] = e_clone -return [e for e in entrypoints.itervalues() if e.enabled] +return [e for e in entrypoints.values() if e.enabled] def get_entrypoints_defines(doc): diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index 847c59dbd8..8c0b530f69 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -512,7 +512,7 @@ struct transform { #endif -% for (opcode, xform_list) in xform_dict.iteritems(): +% for (opcode, xform_list) in xform_dict.items(): % for xform in xform_list: ${xform.search.render()} ${xform.replace.render()} diff --git a/src/compiler/nir/nir_builder_opcodes_h.py b/src/compiler/nir/nir_builder_opcodes_h.py index 72cf5b4549..e600093e9f 100644 --- a/src/compiler/nir/nir_builder_opcodes_h.py +++ b/src/compiler/nir/nir_builder_opcodes_h.py @@ -34,7 +34,7 @@ def src_list(num_srcs): return ', '.join('src' + str(i) if i < num_srcs else 'NULL' for i in range(4)) %> -% for name, opcode in sorted(opcodes.iteritems()): +% for name, opcode in sorted(opcodes.items()): static inline nir_ssa_def * nir_${name}(nir_builder *build, ${src_decl_list(opcode.num_inputs)}) { @@ -55,7 +55,7 @@ nir_load_system_value(nir_builder *build, nir_intrinsic_op op, int index) return &load->dest.ssa; } -% for name, opcode in filter(lambda v: v[1].sysval, sorted(INTR_OPCODES.iteritems())): +% for name, opcode in filter(lambda v: v[1].sysval, sorted(INTR_OPCODES.items())): static inline nir_ssa_def * nir_${name}(nir_builder *build) { diff --git a/src/compiler/nir/nir_constant_expressions.py b/src/compiler/nir/nir_constant_expressions.py index 35dffe70ce..118af9f781 100644 --- a/src/compiler/nir/nir_constant_expressions.py +++ b/src/compiler/nir/nir_constant_expressions.py @@ -387,7 +387,7 @@ struct bool32_vec { % endif -% for name, op in sorted(opcodes.iteritems()): +% for name, op in sorted(opcodes.items()): static nir_const_value evaluate_${name}(MAYBE_UNUSED unsigned num_components, ${"UNUSED" if op_bit_sizes(op) is None else ""} unsigned bit_size, @@ -420,7 +420,7 @@ nir_eval_const_opcode(nir_op op, unsigned num_components, unsigned bit_width, nir_const_value *src) { switch (op) { -% for name in sorted(opcodes.iterkeys()): +% for name in sorted(opcodes.keys()): case nir_op_${name}: return evaluate_${name}(num_components, bit_width, src); % endfor diff --git a/src/compiler/nir/nir_intrinsics_c.py b/src/compiler/nir/nir_intrinsics_c.py index 9604fcdf62..98af67c38a 100644 --- a/src/compiler/nir/nir_intrinsics_c.py +++ b/src/compiler/nir/nir_intrinsics_c.py @@ -25,7 +25,7 @@ template = """\ #include "nir.h" const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics] = { -% for name, opcode in sorted(INTR_OPCODES.iteritems()): +% for name, opcode in sorted(INTR_OPCODES.items()): { .name = "${name}", .num_srcs = ${opcode.num_srcs}, diff --git a/src/compiler/nir/nir_opcodes_c.py b/src/compiler/nir/nir_opcodes_c.py index 108e144b5f..4603cd3d74 100644 --- a/src/compiler/nir/nir_opcodes_c.py +++ b/src/compiler/nir/nir_opcodes_c.py @@ -116,7 +116,7 @@ nir_type_conversion_op(nir_alu_type src, nir_alu_type dst, nir_rounding_mode rnd } const nir_op_info nir_op_infos[nir_num_opcodes] = { -% for name, opcode in s
[Mesa-dev] [PATCH 05/26] python: Stop using the string module
Most functions in the builtin string module also exist as methods of string objects. Since the functions were removed from the string module in Python 3, using the instance methods directly makes the code compatible with both Python 2 and Python 3. Signed-off-by: Mathieu Bridon --- src/mapi/glapi/gen/glX_proto_common.py | 3 +-- src/mapi/glapi/gen/glX_proto_send.py | 8 src/mapi/glapi/gen/gl_XML.py | 8 src/mapi/glapi/gen/typeexpr.py | 4 ++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/mapi/glapi/gen/glX_proto_common.py b/src/mapi/glapi/gen/glX_proto_common.py index adc20dc9f0..0559dd1609 100644 --- a/src/mapi/glapi/gen/glX_proto_common.py +++ b/src/mapi/glapi/gen/glX_proto_common.py @@ -27,7 +27,6 @@ from __future__ import print_function import gl_XML, glX_XML -import string class glx_proto_item_factory(glX_XML.glx_item_factory): @@ -67,7 +66,7 @@ class glx_print_proto(gl_XML.gl_print_base): return compsize elif len(param.count_parameter_list): -parameters = string.join( param.count_parameter_list, "," ) +parameters = ",".join( param.count_parameter_list ) compsize = "__gl%s_size(%s)" % (func.name, parameters) return compsize diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py index 7ab1eb4a70..c389872044 100644 --- a/src/mapi/glapi/gen/glX_proto_send.py +++ b/src/mapi/glapi/gen/glX_proto_send.py @@ -31,7 +31,7 @@ from __future__ import print_function import argparse import gl_XML, glX_XML, glX_proto_common, license -import copy, string +import copy def convertStringForXCB(str): tmp = "" @@ -39,10 +39,10 @@ def convertStringForXCB(str): i = 0 while i < len(str): if str[i:i+3] in special: -tmp = '%s_%s' % (tmp, string.lower(str[i:i+3])) +tmp = '%s_%s' % (tmp, str[i:i+3].lower()) i = i + 2; elif str[i].isupper(): -tmp = '%s_%s' % (tmp, string.lower(str[i])) +tmp = '%s_%s' % (tmp, str[i].lower()) else: tmp = '%s%s' % (tmp, str[i]) i += 1 @@ -662,7 +662,7 @@ generic_%u_byte( GLint rop, const void * ptr ) if len( condition_list ) > 0: if len( condition_list ) > 1: -skip_condition = "(%s)" % (string.join( condition_list, ") && (" )) +skip_condition = "(%s)" % ") && (".join( condition_list ) else: skip_condition = "%s" % (condition_list.pop(0)) diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py index 52e2cab6b9..7cb276ec85 100644 --- a/src/mapi/glapi/gen/gl_XML.py +++ b/src/mapi/glapi/gen/gl_XML.py @@ -29,7 +29,7 @@ from __future__ import print_function from collections import OrderedDict from decimal import Decimal import xml.etree.ElementTree as ET -import re, sys, string +import re, sys import os.path import typeexpr import static_data @@ -320,7 +320,7 @@ def create_parameter_string(parameters, include_names): if len(list) == 0: list = ["void"] -return string.join(list, ", ") +return ", ".join(list) class gl_item(object): @@ -578,9 +578,9 @@ class gl_parameter(object): list.append( str(s) ) if len(list) > 1 and use_parens : -return "safe_mul(%s)" % (string.join(list, ", ")) +return "safe_mul(%s)" % ", ".join(list) else: -return string.join(list, " * ") +return " * ".join(list) elif self.is_image(): return "compsize" diff --git a/src/mapi/glapi/gen/typeexpr.py b/src/mapi/glapi/gen/typeexpr.py index 5ff9798dad..1f710ea9e7 100644 --- a/src/mapi/glapi/gen/typeexpr.py +++ b/src/mapi/glapi/gen/typeexpr.py @@ -26,7 +26,7 @@ from __future__ import print_function -import string, copy +import copy class type_node(object): def __init__(self): @@ -126,7 +126,7 @@ class type_expression(object): # Replace '*' with ' * ' in type_string. Then, split the string # into tokens, separated by spaces. -tokens = string.split( string.replace( type_string, "*", " * " ) ) +tokens = type_string.replace("*", " * ").split() const = 0 t = None -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 02/26] python: Use spaces, not tabs
Python 3 doesn't allow mixing spaces and tabs in a script, contrarily to Python 2. Signed-off-by: Mathieu Bridon --- src/mapi/glapi/gen/glX_proto_size.py | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mapi/glapi/gen/glX_proto_size.py b/src/mapi/glapi/gen/glX_proto_size.py index 2b7cefd235..284ee70e61 100644 --- a/src/mapi/glapi/gen/glX_proto_size.py +++ b/src/mapi/glapi/gen/glX_proto_size.py @@ -612,10 +612,10 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common): if s == 0: s = 1 sig += "(%u,%u)" % (f.offset_of(p.counter), s) - if size == '': - size = p.size_string() - else: - size = "safe_add(%s, %s)" % (size, p.size_string()) +if size == '': +size = p.size_string() +else: +size = "safe_add(%s, %s)" % (size, p.size_string()) # If the calculated signature matches a function that has # already be emitted, don't emit this function. Instead, add -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 03/26] python: Use the Python 3 exception syntax
This is compatible with Python versions >= 2.6. Signed-off-by: Mathieu Bridon --- src/mapi/glapi/gen/glX_XML.py | 2 +- src/mapi/glapi/gen/gl_XML.py| 6 +++--- src/mapi/glapi/gen/gl_marshal.py| 2 +- src/mapi/glapi/gen/gl_marshal_h.py | 2 +- src/mesa/main/get_hash_generator.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mapi/glapi/gen/glX_XML.py b/src/mapi/glapi/gen/glX_XML.py index b6d305c879..e1aa1b3e61 100644 --- a/src/mapi/glapi/gen/glX_XML.py +++ b/src/mapi/glapi/gen/glX_XML.py @@ -470,7 +470,7 @@ class glx_function(gl_XML.gl_function): def needs_reply(self): try: x = self._needs_reply -except Exception, e: +except Exception as e: x = 0 if self.return_type != 'void': x = 1 diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py index 3a191abe0d..330ca0e5a6 100644 --- a/src/mapi/glapi/gen/gl_XML.py +++ b/src/mapi/glapi/gen/gl_XML.py @@ -284,7 +284,7 @@ def classify_category(name, number): try: core_version = float(name) -except Exception,e: +except Exception as e: core_version = 0.0 if core_version > 0.0: @@ -365,7 +365,7 @@ class gl_enum( gl_item ): else: try: c = int(temp) -except Exception,e: +except Exception as e: raise RuntimeError('Invalid count value "%s" for enum "%s" in function "%s" when an integer was expected.' % (temp, self.name, n)) self.default_count = c @@ -426,7 +426,7 @@ class gl_parameter(object): count = int(c) self.count = count self.counter = None -except Exception,e: +except Exception as e: count = 1 self.count = 0 self.counter = c diff --git a/src/mapi/glapi/gen/gl_marshal.py b/src/mapi/glapi/gen/gl_marshal.py index e9dd2c4f78..18d7a7012b 100644 --- a/src/mapi/glapi/gen/gl_marshal.py +++ b/src/mapi/glapi/gen/gl_marshal.py @@ -353,7 +353,7 @@ if __name__ == '__main__': try: (args, trail) = getopt.getopt(sys.argv[1:], 'm:f:') -except Exception,e: +except Exception as e: show_usage() for (arg,val) in args: diff --git a/src/mapi/glapi/gen/gl_marshal_h.py b/src/mapi/glapi/gen/gl_marshal_h.py index 6490595a00..a7a9eda573 100644 --- a/src/mapi/glapi/gen/gl_marshal_h.py +++ b/src/mapi/glapi/gen/gl_marshal_h.py @@ -74,7 +74,7 @@ if __name__ == '__main__': try: (args, trail) = getopt.getopt(sys.argv[1:], 'm:f:') -except Exception,e: +except Exception: show_usage() for (arg,val) in args: diff --git a/src/mesa/main/get_hash_generator.py b/src/mesa/main/get_hash_generator.py index 86c6771066..facdccd8a5 100644 --- a/src/mesa/main/get_hash_generator.py +++ b/src/mesa/main/get_hash_generator.py @@ -201,7 +201,7 @@ def show_usage(): if __name__ == '__main__': try: (opts, args) = getopt.getopt(sys.argv[1:], "f:") - except Exception,e: + except Exception: show_usage() if len(args) != 0: -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 04/26] python: Better check for keys in dicts
Python 3 lost the dict.has_key() method. Instead it requires using the "in" operator. This is also compatible with Python 2. Signed-off-by: Mathieu Bridon --- src/mapi/glapi/gen/glX_XML.py| 2 +- src/mapi/glapi/gen/glX_proto_send.py | 2 +- src/mapi/glapi/gen/glX_proto_size.py | 18 +- src/mapi/glapi/gen/gl_XML.py | 6 +++--- src/mapi/glapi/gen/gl_procs.py | 2 +- src/mapi/mapi_abi.py | 10 -- src/util/xmlpool/gen_xmlpool.py | 4 ++-- 7 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/mapi/glapi/gen/glX_XML.py b/src/mapi/glapi/gen/glX_XML.py index e1aa1b3e61..bbcecd6023 100644 --- a/src/mapi/glapi/gen/glX_XML.py +++ b/src/mapi/glapi/gen/glX_XML.py @@ -64,7 +64,7 @@ class glx_enum(gl_XML.gl_enum): else: mode = 1 -if not self.functions.has_key(n): +if n not in self.functions: self.functions[ n ] = [c, mode] return diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py index f199e9a0a1..7ab1eb4a70 100644 --- a/src/mapi/glapi/gen/glX_proto_send.py +++ b/src/mapi/glapi/gen/glX_proto_send.py @@ -842,7 +842,7 @@ generic_%u_byte( GLint rop, const void * ptr ) def printPixelFunction(self, f): -if self.pixel_stubs.has_key( f.name ): +if f.name in self.pixel_stubs: # Normally gl_function::get_parameter_string could be # used. However, this call needs to have the missing # dimensions (e.g., a fake height value for diff --git a/src/mapi/glapi/gen/glX_proto_size.py b/src/mapi/glapi/gen/glX_proto_size.py index 284ee70e61..18a6f2e502 100644 --- a/src/mapi/glapi/gen/glX_proto_size.py +++ b/src/mapi/glapi/gen/glX_proto_size.py @@ -71,7 +71,7 @@ class glx_enum_function(object): for enum_name in enum_dict: e = enum_dict[ enum_name ] -if e.functions.has_key( match_name ): +if match_name in e.functions: [count, mode] = e.functions[ match_name ] if mode_set and mode != self.mode: @@ -79,11 +79,11 @@ class glx_enum_function(object): self.mode = mode -if self.enums.has_key( e.value ): +if e.value in self.enums: if e.name not in self.enums[ e.value ]: self.enums[ e.value ].append( e ) else: -if not self.count.has_key( count ): +if count not in self.count: self.count[ count ] = [] self.enums[ e.value ] = [ e ] @@ -131,7 +131,7 @@ class glx_enum_function(object): for a in self.enums: count += 1 -if self.count.has_key(-1): +if -1 in self.count: return 0 # Determine if there is some mask M, such that M = (2^N) - 1, @@ -356,7 +356,7 @@ class PrintGlxSizeStubs_c(PrintGlxSizeStubs_common): if (ef.is_set() and self.emit_set) or (not ef.is_set() and self.emit_get): sig = ef.signature() -if enum_sigs.has_key( sig ): +if sig in enum_sigs: aliases.append( [func.name, enum_sigs[ sig ]] ) else: enum_sigs[ sig ] = func.name @@ -477,10 +477,10 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common): sig = ef.signature() -if not enum_functions.has_key(func.name): +if func.name not in enum_functions: enum_functions[ func.name ] = sig -if not enum_sigs.has_key( sig ): +if sig not in enum_sigs: enum_sigs[ sig ] = ef @@ -496,7 +496,7 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common): if func.server_handcode: continue if not func.has_variable_size_request(): continue -if enum_functions.has_key(func.name): +if func.name in enum_functions: sig = enum_functions[func.name] ef = enum_sigs[ sig ] @@ -621,7 +621,7 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common): # already be emitted, don't emit this function. Instead, add # it to the list of function aliases. -if self.counter_sigs.has_key(sig): +if sig in self.counter_sigs: n = self.counter_sigs[sig]; alias = [f.name, n] else: diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py index 330ca0e5a6..52e2cab6b9 100644 --- a/src/mapi/glapi/gen/gl_XML.py +++ b/src/mapi/glapi/gen/gl_XML.py @@ -943,7 +943,7 @@ class gl_api(object): temp_name = child.get( "name" ) self.category_dict[ temp_name ] = [cat_name, cat_number] -if self.functions_by_name.has_key( func_name ): +if func_name
[Mesa-dev] [PATCH] build: Fix string matching
Commit f69bc797e15fe6beb9e439009fab55f7fae0b7f9 did the following: -if format.layout in ('bptc', 'astc'): +if format.layout in ('astc'): The intention was to go from matching either 'bptc' or 'astc' to matching only 'astc'. But the new code doesn't respect this intention any more, because in Python `('astc')` is not a tuple containing a string, it is just the string. (the parentheses are simply ignored) That means we now match any substring of 'astc', for example 'a'. This commit fixes the test to respect the original intention. --- src/gallium/auxiliary/util/u_format_table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/util/u_format_table.py b/src/gallium/auxiliary/util/u_format_table.py index 1f8e15fa97..a9df984994 100644 --- a/src/gallium/auxiliary/util/u_format_table.py +++ b/src/gallium/auxiliary/util/u_format_table.py @@ -139,7 +139,7 @@ def write_format_table(formats): u_format_pack.print_channels(format, do_swizzle_array) print " %s," % (colorspace_map(format.colorspace),) access = True -if format.layout in ('astc'): +if format.layout == 'astc': access = False if format.layout == 'etc' and format.short_name() != 'etc1_rgb8': access = False -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] Make the output of the Python build scripts more reproducible
I ported the Mesa build system to Python 3. The result of this work can be seen on my fork: https://gitlab.freedesktop.org/bochecha/mesa/tree/python3 When porting, I tried to ensure that the generated files are identical to the ones generated by a build on master. This was made difficult by some scripts not having reproducible outputs. This patch series only makes these scripts generate reproducible output, to ease verification of the port. src/amd/common/sid_tables.py | 2 +- src/amd/vulkan/radv_icd.py| 2 +- src/compiler/nir/nir_algebraic.py | 3 ++- src/compiler/nir/nir_opt_algebraic.py | 3 ++- src/intel/vulkan/anv_icd.py | 2 +- src/mapi/glapi/gen/glX_proto_size.py | 2 +- src/mapi/glapi/gen/gl_XML.py | 3 ++- 7 files changed, 10 insertions(+), 7 deletions(-) * [PATCH 1/2] build: Stabilize some script outputs * [PATCH 2/2] build: Specify the JSON separators ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 2/2] build: Specify the JSON separators
On Python 2, the default JSON separators are ', ' for items and ': ' for dicts. On Python 3, the default is the same when no indent is specified, but if one is (and we do specify one) then the default items separator becomes ',' (the dict separator remains unchanged). This change explicitly specifies the Python 3 default, which helps ensuring that the output is identical, whether it was generated by Python 2 or 3. --- src/amd/vulkan/radv_icd.py | 2 +- src/intel/vulkan/anv_icd.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/amd/vulkan/radv_icd.py b/src/amd/vulkan/radv_icd.py index 78ed379bd2..cc86bbfa56 100644 --- a/src/amd/vulkan/radv_icd.py +++ b/src/amd/vulkan/radv_icd.py @@ -44,4 +44,4 @@ if __name__ == '__main__': } with open(args.out, 'w') as f: -json.dump(json_data, f, indent = 4, sort_keys=True) +json.dump(json_data, f, indent = 4, sort_keys=True, separators=(',', ': ')) diff --git a/src/intel/vulkan/anv_icd.py b/src/intel/vulkan/anv_icd.py index 31bb0687a8..36c2882f7d 100644 --- a/src/intel/vulkan/anv_icd.py +++ b/src/intel/vulkan/anv_icd.py @@ -44,4 +44,4 @@ if __name__ == '__main__': } with open(args.out, 'w') as f: -json.dump(json_data, f, indent = 4, sort_keys=True) +json.dump(json_data, f, indent = 4, sort_keys=True, separators=(',', ': ')) -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 1/2] build: Stabilize some script outputs
In Python, dictionaries and sets are unordered, and as a result their is no guarantee that running this script twice will produce the same output. Using ordered dicts and explicitly sorting items makes the build more reproducible, and will make it possible to verify that we're not breaking anything when we move the build scripts to Python 3. --- src/amd/common/sid_tables.py | 2 +- src/compiler/nir/nir_algebraic.py | 3 ++- src/compiler/nir/nir_opt_algebraic.py | 3 ++- src/mapi/glapi/gen/glX_proto_size.py | 2 +- src/mapi/glapi/gen/gl_XML.py | 3 ++- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/amd/common/sid_tables.py b/src/amd/common/sid_tables.py index 4e53acefa4..ca90f82535 100644 --- a/src/amd/common/sid_tables.py +++ b/src/amd/common/sid_tables.py @@ -65,7 +65,7 @@ class StringTable: fragments = [ '"%s\\0" /* %s */' % ( te[0].encode('string_escape'), -', '.join(str(idx) for idx in te[2]) +', '.join(str(idx) for idx in sorted(te[2])) ) for te in self.table ] diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index d6784df004..847c59dbd8 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -25,6 +25,7 @@ from __future__ import print_function import ast +from collections import OrderedDict import itertools import struct import sys @@ -601,7 +602,7 @@ ${pass_name}(nir_shader *shader) class AlgebraicPass(object): def __init__(self, pass_name, transforms): - self.xform_dict = {} + self.xform_dict = OrderedDict() self.pass_name = pass_name error = False diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index db907df854..2f1cba398f 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -23,6 +23,7 @@ # Authors: #Jason Ekstrand (ja...@jlekstrand.net) +from collections import OrderedDict import nir_algebraic import itertools @@ -628,7 +629,7 @@ optimizations = [ 'options->lower_unpack_snorm_4x8'), ] -invert = {'feq': 'fne', 'fne': 'feq', 'fge': 'flt', 'flt': 'fge' } +invert = OrderedDict([('feq', 'fne'), ('fne', 'feq'), ('fge', 'flt'), ('flt', 'fge')]) for left, right in list(itertools.combinations(invert.keys(), 2)) + zip(invert.keys(), invert.keys()): optimizations.append((('inot', ('ior(is_used_once)', (left, a, b), (right, c, d))), diff --git a/src/mapi/glapi/gen/glX_proto_size.py b/src/mapi/glapi/gen/glX_proto_size.py index e16dbab3e0..8dbb0af86d 100644 --- a/src/mapi/glapi/gen/glX_proto_size.py +++ b/src/mapi/glapi/gen/glX_proto_size.py @@ -191,7 +191,7 @@ class glx_enum_function(object): print 'switch( e ) {' -for c in self.count: +for c in sorted(self.count): for e in self.count[c]: first = 1 diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py index a5320e90a1..1bab5fee51 100644 --- a/src/mapi/glapi/gen/gl_XML.py +++ b/src/mapi/glapi/gen/gl_XML.py @@ -24,6 +24,7 @@ # Authors: #Ian Romanick +from collections import OrderedDict from decimal import Decimal import xml.etree.ElementTree as ET import re, sys, string @@ -861,7 +862,7 @@ class gl_item_factory(object): class gl_api(object): def __init__(self, factory): -self.functions_by_name = {} +self.functions_by_name = OrderedDict() self.enums_by_name = {} self.types_by_name = {} -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev