intelxed / xed

The X86 Encoder Decoder (XED), is a software library for encoding and decoding X86 (IA32 and Intel64) instructions
https://intelxed.github.io/
Apache License 2.0
1.38k stars 146 forks source link

Fix build on python <3.6 #293

Closed percontation closed 1 year ago

percontation commented 1 year ago

For reasons, I'm building xed under Debian Stretch which only has python3.5, which seems like it's supposed to work since mfile.py currently suggests that the build scripts work with python >= 3.4 https://github.com/intelxed/xed/blob/9fc12ab6c0ba7a9eaadb20135369b4b4107fa670/mfile.py#L89

But, it doesn't, since some f-strings (syntax feature added in python3.6) have crept into the build scripts.

The following patch appears to fix the issue for me:

--- mbuild/mbuild/util.py
+++ mbuild/mbuild/util.py
@@ -944,7 +944,7 @@ def get_clang_version(full_path):
         pass
     # Try the --version knob
     try:
-        (retcode, stdout, stderr) = run_command(f'{full_path} --version')
+        (retcode, stdout, stderr) = run_command(full_path + ' --version')
         if retcode == 0:
             for line in stdout:
                 r = re.search('version[ ]+(?P<version>(\d+\.)+\d+)', line.lower())
--- xed/xed_mbuild.py
+++ xed/xed_mbuild.py
@@ -152,7 +152,7 @@ class generator_inputs_t(object):
         found = False
         for f in list(self.files[file_type]):
             if os.path.samefile(f, file_name):
-                mbuild.vmsgb(1, f"REMOVE FILE ({file_type})", f)
+                mbuild.vmsgb(1, "REMOVE FILE (%s)" % file_type, f)
                 self.files[file_type].remove(f)
                 found = True
         if not found:
@@ -2570,7 +2570,7 @@ def _run_canned_tests(env,osenv):
     # Add additional tests (from cmd knob or layer's config files)
     for d in env['tests_ext']:
         mbuild.vmsgb(1, "ADDED TESTS EXT", d)
-        cmd += f" --tests {aq(d)}"
+        cmd += " --tests " + aq(d)

     # add test restriction/subetting codes
     codes = []

So, I'd suggest removing the incidental f-string usage as per that patch.

That, or raising the version check in mfile.py to indicate that python 3.6 is required, because currently, attempting to build with python <3.6 doesn't work, and also the build scripts swallow the relevant exception and return an incorrect error message about ./mbuild/ not being in the right place.

marjevan commented 1 year ago

Thanks for the report. I'll update the python requirement to 3.6. The update will be available with the next external release.