From b1883448e3a4100242b786f58be71a69d921a210 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 10 May 2019 12:42:23 -0700 Subject: [PATCH] getdeps: respect cmake WORKING_DIRECTORY for tests Summary: the cmake `add_test` and related functions allow specifying the WORKING_DIRECTORY to use for tests. We weren't respecting this value, so this diff looks up the WORKING_DIRECTORY from the ctest json info and adjusts the buck test info json blob that we pass on the testpilot. Since that interface only allows passing an argv array, we use the `cmake -E chdir` command to run a command in a specified directory in a portable manner. Reviewed By: strager Differential Revision: D15274012 fbshipit-source-id: 1f02d461d73178745794703d455494e31c2e09ed --- build/fbcode_builder/getdeps/builder.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/build/fbcode_builder/getdeps/builder.py b/build/fbcode_builder/getdeps/builder.py index f835063ca..88167d7c6 100644 --- a/build/fbcode_builder/getdeps/builder.py +++ b/build/fbcode_builder/getdeps/builder.py @@ -279,6 +279,21 @@ class CMakeBuilder(BuilderBase): def run_tests(self, install_dirs): env = self._compute_env(install_dirs) ctest = path_search(env, "ctest") + cmake = path_search(env, "cmake") + + def get_property(test, propname, defval=None): + """ extracts a named property from a cmake test info json blob. + The properties look like: + [{"name": "WORKING_DIRECTORY"}, + {"value": "something"}] + We assume that it is invalid for the same named property to be + listed more than once. + """ + props = test.get("properties", []) + for p in props: + if p.get("name", None) == propname: + return p.get("value", defval) + return defval def list_tests(): output = subprocess.check_output( @@ -288,12 +303,16 @@ class CMakeBuilder(BuilderBase): tests = [] machine_suffix = self.build_opts.host_type.as_tuple_string() for test in data["tests"]: + working_dir = get_property(test, "WORKING_DIRECTORY") + command = test["command"] + if working_dir: + command = [cmake, "-E", "chdir", working_dir] + command tests.append( { "type": "custom", "target": "%s-%s-getdeps-%s" % (self.manifest.name, test["name"], machine_suffix), - "command": test["command"], + "command": command, } ) return tests