From 4a19af7b54587f3d161844dff90a50f69919b4a9 Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Thu, 15 Aug 2019 17:53:32 -0700 Subject: [PATCH] getdeps: honor INSTALL_DIR correctly in the generated run_cmake.py script Summary: This cleans up how the `CMAKE_ENV` and `CMAKE_DEFINE_ARGS` variables are written in the generated `run_cmake.py` script that we emit for CMake-based projects. We now emit each entry in these variables on separate lines, just to improve readability. (Both of these variables tend to have a number of entries and are very long if emitted on a single line.) This also replaces the `-DCMAKE_INSTALL_PREFIX` entry in `CMAKE_DEFINE_ARGS` to have it correctly honor the `INSTALL_DIR` variable defined in `run_cmake.py`. This makes `run_cmake.py` still do the right thing if someone manually edits it to change the `INSTALL_DIR` value. Reviewed By: wez Differential Revision: D16778006 fbshipit-source-id: fee5d25748b87b5d9c57ee2edf8de5e586e872ee --- build/fbcode_builder/getdeps/builder.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/build/fbcode_builder/getdeps/builder.py b/build/fbcode_builder/getdeps/builder.py index 96859481a..34851b6ce 100644 --- a/build/fbcode_builder/getdeps/builder.py +++ b/build/fbcode_builder/getdeps/builder.py @@ -203,12 +203,12 @@ import os import subprocess CMAKE = {cmake!r} -CMAKE_ENV = {env!r} -CMAKE_DEFINE_ARGS = {define_args!r} SRC_DIR = {src_dir!r} BUILD_DIR = {build_dir!r} INSTALL_DIR = {install_dir!r} CMD_PREFIX = {cmd_prefix!r} +CMAKE_ENV = {env_str} +CMAKE_DEFINE_ARGS = {define_args_str} def main(): @@ -278,6 +278,23 @@ if __name__ == "__main__": return False def _write_build_script(self, **kwargs): + env_lines = [" {!r}: {!r},".format(k, v) for k, v in kwargs["env"].items()] + kwargs["env_str"] = "\n".join(["{"] + env_lines + ["}"]) + + define_arg_lines = ["["] + for arg in kwargs["define_args"]: + # Replace the CMAKE_INSTALL_PREFIX argument to use the INSTALL_DIR + # variable that we define in the MANUAL_BUILD_SCRIPT code. + if arg.startswith("-DCMAKE_INSTALL_PREFIX="): + value = " {!r}.format(INSTALL_DIR),".format( + "-DCMAKE_INSTALL_PREFIX={}" + ) + else: + value = " {!r},".format(arg) + define_arg_lines.append(value) + define_arg_lines.append("]") + kwargs["define_args_str"] = "\n".join(define_arg_lines) + # In order to make it easier for developers to manually run builds for # CMake-based projects, write out some build scripts that can be used to invoke # CMake manually.