From cc98d262fe0168c1523879746d657eceafd38bb6 Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Tue, 28 Jan 2020 15:02:57 +0000 Subject: Test host_machine is correctly detected after add_languages() Test that the host_machine is correctly detected after add_languages(), when no langauge is initially specified in project(). In the MSYS2 MSYSTEM=MINGW32 environment (64-bit MSYS2 but with a i686-w64-mingw32 targeted gcc as gcc) this test fails, as it (incorrectly) tries to build retval-x86_64.S using an x86 compiler. --- test cases/common/123 cpp and asm/meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test cases/common/123 cpp and asm/meson.build b/test cases/common/123 cpp and asm/meson.build index cf064d007..ec7c46684 100644 --- a/test cases/common/123 cpp and asm/meson.build +++ b/test cases/common/123 cpp and asm/meson.build @@ -1,4 +1,5 @@ -project('c++ and assembly test', 'cpp') +project('c++ and assembly test') +add_languages('cpp') cpp = meson.get_compiler('cpp') cpu = host_machine.cpu_family() -- cgit v1.2.3 From 42fbf9299a01c68558302abc354d931675c98ebb Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Sat, 29 Feb 2020 14:48:12 +0000 Subject: Extend _run_test to test build without regenerate Add coverage of a simple 'configure then build' sequence, to catch bugs which occur with that. Also, to simplify returning results from functions called by _run_test(), allow it also throw TestResult objects, which run_test() catches and returns. --- run_project_tests.py | 55 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/run_project_tests.py b/run_project_tests.py index 86db59961..50ce94f1c 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -63,7 +63,7 @@ class BuildStep(Enum): validate = 6 -class TestResult: +class TestResult(BaseException): def __init__(self, cicmds): self.msg = '' # empty msg indicates test success self.stdo = '' @@ -376,6 +376,8 @@ def run_test(test: TestDef, extra_args, compiler, backend, flags, commands, shou with AutoDeletedDir(tempfile.mkdtemp(prefix='i ', dir=os.getcwd())) as install_dir: try: return _run_test(test, build_dir, install_dir, extra_args, compiler, backend, flags, commands, should_fail) + except TestResult as r: + return r finally: mlog.shutdown() # Close the log file because otherwise Windows wets itself. @@ -417,29 +419,39 @@ def _run_test(test: TestDef, test_build_dir: str, install_dir: str, extra_args, testresult.fail('Generating the build system failed.') return testresult builddata = build.load(test_build_dir) - # Touch the meson.build file to force a regenerate so we can test that - # regeneration works before a build is run. - ensure_backend_detects_changes(backend) - os.utime(str(test.path / 'meson.build')) - # Build with subprocess dir_args = get_backend_args_for_dir(backend, test_build_dir) - build_start = time.time() - pc, o, e = Popen_safe(compile_commands + dir_args, cwd=test_build_dir) - testresult.add_step(BuildStep.build, o, e, '', time.time() - build_start) - if should_fail == 'build': + + # Build with subprocess + def build_step(): + build_start = time.time() + pc, o, e = Popen_safe(compile_commands + dir_args, cwd=test_build_dir) + testresult.add_step(BuildStep.build, o, e, '', time.time() - build_start) + if should_fail == 'build': + if pc.returncode != 0: + raise testresult + testresult.fail('Test that should have failed to build succeeded.') + raise testresult if pc.returncode != 0: - return testresult - testresult.fail('Test that should have failed to build succeeded.') - return testresult - if pc.returncode != 0: - testresult.fail('Compiling source code failed.') - return testresult - # Touch the meson.build file to force a regenerate so we can test that - # regeneration works after a build is complete. - ensure_backend_detects_changes(backend) - os.utime(str(test.path / 'meson.build')) - test_start = time.time() + testresult.fail('Compiling source code failed.') + raise testresult + + # Touch the meson.build file to force a regenerate + def force_regenerate(): + ensure_backend_detects_changes(backend) + os.utime(str(test.path / 'meson.build')) + + # just test building + build_step() + + # test that regeneration works for build step + force_regenerate() + build_step() # TBD: assert nothing gets built after the regenerate? + + # test that regeneration works for test step + force_regenerate() + # Test in-process + test_start = time.time() (returncode, tstdo, tstde, test_log) = run_test_inprocess(test_build_dir) testresult.add_step(BuildStep.test, tstdo, tstde, test_log, time.time() - test_start) if should_fail == 'test': @@ -450,6 +462,7 @@ def _run_test(test: TestDef, test_build_dir: str, install_dir: str, extra_args, if returncode != 0: testresult.fail('Running unit tests failed.') return testresult + # Do installation, if the backend supports it if install_commands: env = os.environ.copy() -- cgit v1.2.3 From 0821b182c5ecc4c1090902061673f881318c93bc Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Sat, 29 Feb 2020 17:32:02 +0000 Subject: Fix re-building test '127 custom target directory install' with VS backend Running the build step of test '127 custom target directory install' again, using the VS backend, causes 'docgen.py' to try to create the target directory again (which fails with a FileNotFound exception). I'm guessing that perhaps this is a shortcoming of the VS backend that it doesn't correctly give this target a dependency on the directory. I'm not sure that this test is actually valid meson: the reference manual says custom_target(output:) should be a list of files, and not a directory, as is this case here. --- test cases/common/127 custom target directory install/docgen.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test cases/common/127 custom target directory install/docgen.py b/test cases/common/127 custom target directory install/docgen.py index 245f37035..97a3f906c 100644 --- a/test cases/common/127 custom target directory install/docgen.py +++ b/test cases/common/127 custom target directory install/docgen.py @@ -5,7 +5,10 @@ import sys out = sys.argv[1] -os.mkdir(out) +try: + os.mkdir(out) +except FileExistsError: + pass for name in ('a', 'b', 'c'): with open(os.path.join(out, name + '.html'), 'w') as f: -- cgit v1.2.3 From 2cf2c80112ae16e8b465cdfb91d85b7d031e67fa Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Fri, 24 Jan 2020 19:24:26 +0000 Subject: Redetect machines after every change to languages Currently, detect_machine_info() is called: - from Environment.__init__(), before we have any compiler available - from Interpreter.__init__() with the list of languages provided to project() (determined via the initial parse_project()) This is not sufficent in the case where no languages are specified to project() and are later added with add_languages(). We cannot correctly detect that the host machine should be treated as x86 (on x86_64 hardware) until we have a compiler we are told to use. Redetect machines after project(), and after every add_languages(). --- mesonbuild/interpreter.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index c29ed89fc..b00324d65 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2216,7 +2216,9 @@ class Interpreter(InterpreterBase): self.build_def_files = [os.path.join(self.subdir, environment.build_filename)] if not mock: self.parse_project() + self._redetect_machines() + def _redetect_machines(self): # Re-initialize machine descriptions. We can do a better job now because we # have the compilers needed to gain more knowledge, so wipe out old # inference and start over. @@ -3014,6 +3016,7 @@ external dependencies (including libraries) must go to "dependencies".''') success &= self.add_languages_for(args, required, MachineChoice.HOST) if not self.coredata.is_cross_build(): self.coredata.copy_build_options_from_regular_ones() + self._redetect_machines() return success def add_languages_for(self, args, required, for_machine: MachineChoice): -- cgit v1.2.3