From 5ccda6878d3b8f494d65dfc084ba1a884329d57a Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 6 Mar 2020 11:09:48 -0800 Subject: [PATCH] project_tests: Add "version" to "shared_lib" and "pdb" types This allows the harness to apply the version correctly, putting it in the right place, dropping the right amount of numbers, etc. pdb taking a version allows it to be more easily copied from the shared_lib type. --- docs/markdown/Contributing.md | 14 ++++++++++- run_project_tests.py | 29 +++++++++++++++++++++-- test cases/d/4 library versions/test.json | 26 ++++++++++---------- test cases/d/7 multilib/test.json | 16 ++++++------- 4 files changed, 61 insertions(+), 24 deletions(-) diff --git a/docs/markdown/Contributing.md b/docs/markdown/Contributing.md index 65460d9f9..4d52ce1b8 100644 --- a/docs/markdown/Contributing.md +++ b/docs/markdown/Contributing.md @@ -190,7 +190,7 @@ Exanple `test.json`: "installed": [ { "type": "exe", "file": "usr/bin/testexe" }, { "type": "pdb", "file": "usr/bin/testexe" }, - { "type": "shared_lib", "file": "usr/lib/z" }, + { "type": "shared_lib", "file": "usr/lib/z", "version": "1.2.3" }, ], "matrix": { "options": { @@ -246,6 +246,18 @@ current platform. The following values are currently supported: Except for the `file` and `expr` types, all paths should be provided *without* a suffix. +The `shared_lib` and `pdb` types takes an optional additional parameter, `version`, this is us a string in `X.Y.Z` format that will be applied to the library. Each version to be tested must have a single version. The harness will apply this correctly per platform: + +```json +{ + "type": "shared_lib", "file": "usr/lib/lib", + "type": "shared_lib", "file": "usr/lib/lib", "version": "1", + "type": "shared_lib", "file": "usr/lib/lib", "version": "1.2.3.", +} +``` + +This will be applied appropraitly per platform. On windows this expects `lib.dll` and `lib-1.dll`. on MacOS it expects `liblib.dylib` and `liblib.1.dylib`. On other Unices it expects `liblib.so`, `liblib.so.1`, and `liblib.so.1.2.3`. + If the `platform` key is present, the installed file entry is only considered if the platform matches. The following values for `platform` are currently supported: diff --git a/run_project_tests.py b/run_project_tests.py index d63dd38a3..160fbf38f 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -95,6 +95,13 @@ class InstalledFile: self.typ = raw['type'] self.platform = raw.get('platform', None) + version = raw.get('version', '') # type: str + if version: + self.version = version.split('.') # type: T.List[str] + else: + # split on '' will return [''], we want an empty list though + self.version = [] + def get_path(self, compiler: str, env: environment.Environment) -> T.Optional[Path]: p = Path(self.path) canonical_compiler = compiler @@ -116,17 +123,35 @@ class InstalledFile: return p elif self.typ == 'shared_lib': if env.machines.host.is_windows() or env.machines.host.is_cygwin(): + # Windows only has foo.dll and foo-X.dll + if len(self.version) > 1: + return None + if self.version: + p = p.with_name('{}-{}'.format(p.name, self.version[0])) return p.with_suffix('.dll') p = p.with_name('lib{}'.format(p.name)) if env.machines.host.is_darwin(): - return p.with_suffix('.dylib') + # MacOS only has libfoo.dylib and libfoo.X.dylib + if len(self.version) > 1: + return None + + # pathlib.Path.with_suffix replaces, not appends + suffix = '.dylib' + if self.version: + suffix = '.{}{}'.format(self.version[0], suffix) else: - return p.with_suffix('.so') + # pathlib.Path.with_suffix replaces, not appends + suffix = '.so' + if self.version: + suffix = '{}.{}'.format(suffix, '.'.join(self.version)) + return p.with_suffix(suffix) elif self.typ == 'exe': if env.machines.host.is_windows() or env.machines.host.is_cygwin(): return p.with_suffix('.exe') elif self.typ == 'pdb': + if self.version: + p = p.with_name('{}-{}'.format(p.name, self.version[0])) return p.with_suffix('.pdb') if canonical_compiler == 'msvc' else None elif self.typ == 'implib' or self.typ == 'implibempty': if env.machines.host.is_windows() and canonical_compiler == 'msvc': diff --git a/test cases/d/4 library versions/test.json b/test cases/d/4 library versions/test.json index 2a3433e8a..942122b87 100644 --- a/test cases/d/4 library versions/test.json +++ b/test cases/d/4 library versions/test.json @@ -1,18 +1,18 @@ { "installed": [ - {"type": "file", "platform": "gcc", "file": "usr/lib/libsome.so"}, - {"type": "file", "platform": "gcc", "file": "usr/lib/libsome.so.0"}, - {"type": "file", "platform": "gcc", "file": "usr/lib/libsome.so.1.2.3"}, - {"type": "file", "platform": "gcc", "file": "usr/lib/libnoversion.so"}, - {"type": "file", "platform": "gcc", "file": "usr/lib/libonlyversion.so"}, - {"type": "file", "platform": "gcc", "file": "usr/lib/libonlyversion.so.1"}, - {"type": "file", "platform": "gcc", "file": "usr/lib/libonlyversion.so.1.4.5"}, - {"type": "file", "platform": "gcc", "file": "usr/lib/libonlysoversion.so"}, - {"type": "file", "platform": "gcc", "file": "usr/lib/libonlysoversion.so.5"}, - {"type": "file", "platform": "msvc", "file": "usr/bin/noversion.dll"}, - {"type": "file", "platform": "msvc", "file": "usr/bin/onlysoversion-5.dll"}, - {"type": "file", "platform": "msvc", "file": "usr/bin/onlyversion-1.dll"}, - {"type": "file", "platform": "msvc", "file": "usr/bin/some-0.dll"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/some"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/some", "version": "0"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/some", "version": "1.2.3"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/noversion"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/onlyversion"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/onlyversion", "version": "1"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/onlyversion", "version": "1.4.5"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/onlysoversion"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/onlysoversion", "version": "5"}, + {"type": "shared_lib", "platform": "msvc", "file": "usr/bin/noversion"}, + {"type": "shared_lib", "platform": "msvc", "file": "usr/bin/onlysoversion", "version": "5"}, + {"type": "shared_lib", "platform": "msvc", "file": "usr/bin/onlyversion", "version": "1"}, + {"type": "shared_lib", "platform": "msvc", "file": "usr/bin/some", "version": "0"}, {"type": "file", "platform": "msvc", "file": "usr/lib/noversion.lib"}, {"type": "file", "platform": "msvc", "file": "usr/lib/onlysoversion.lib"}, {"type": "file", "platform": "msvc", "file": "usr/lib/onlyversion.lib"}, diff --git a/test cases/d/7 multilib/test.json b/test cases/d/7 multilib/test.json index 408c4f227..2d51338ee 100644 --- a/test cases/d/7 multilib/test.json +++ b/test cases/d/7 multilib/test.json @@ -1,14 +1,14 @@ { "installed": [ {"type": "exe", "file": "usr/bin/app_d"}, - {"type": "file", "platform": "gcc", "file": "usr/lib/libsay1.so"}, - {"type": "file", "platform": "gcc", "file": "usr/lib/libsay1.so.0"}, - {"type": "file", "platform": "gcc", "file": "usr/lib/libsay1.so.1.2.3"}, - {"type": "file", "platform": "gcc", "file": "usr/lib/libsay2.so"}, - {"type": "file", "platform": "gcc", "file": "usr/lib/libsay2.so.1"}, - {"type": "file", "platform": "gcc", "file": "usr/lib/libsay2.so.1.2.4"}, - {"type": "file", "platform": "msvc", "file": "usr/bin/say1-0.dll"}, - {"type": "file", "platform": "msvc", "file": "usr/bin/say2-1.dll"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/say1"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/say1", "version": "0"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/say1", "version": "1.2.3"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/say2"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/say2", "version": "1"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/say2", "version": "1.2.4"}, + {"type": "shared_lib", "platform": "msvc", "file": "usr/bin/say1", "version": "0"}, + {"type": "shared_lib", "platform": "msvc", "file": "usr/bin/say2", "version": "1"}, {"type": "file", "platform": "msvc", "file": "usr/lib/say1.lib"}, {"type": "file", "platform": "msvc", "file": "usr/lib/say2.lib"} ]