[llvm] 91259bf - [gn build] Use relative paths in generated lit.site.cfg.py files for llvm and clang.

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Mon May 11 17:58:57 PDT 2020


Author: Nico Weber
Date: 2020-05-11T20:58:45-04:00
New Revision: 91259bf9c68ef72cbc0ce9230665808d10dec416

URL: https://github.com/llvm/llvm-project/commit/91259bf9c68ef72cbc0ce9230665808d10dec416
DIFF: https://github.com/llvm/llvm-project/commit/91259bf9c68ef72cbc0ce9230665808d10dec416.diff

LOG: [gn build] Use relative paths in generated lit.site.cfg.py files for llvm and clang.

This ports a16ba6fea2e554f to the GN build.

No intended behavior change.

Added: 
    llvm/utils/gn/secondary/llvm/utils/llvm-lit/lit_path_function.gni

Modified: 
    llvm/utils/gn/secondary/clang/test/BUILD.gn
    llvm/utils/gn/secondary/llvm/test/BUILD.gn
    llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn

Removed: 
    


################################################################################
diff  --git a/llvm/utils/gn/secondary/clang/test/BUILD.gn b/llvm/utils/gn/secondary/clang/test/BUILD.gn
index 12648f846506..b1541ded8752 100644
--- a/llvm/utils/gn/secondary/clang/test/BUILD.gn
+++ b/llvm/utils/gn/secondary/clang/test/BUILD.gn
@@ -5,33 +5,33 @@ import("//llvm/triples.gni")
 import("//llvm/utils/gn/build/libs/pthread/enable.gni")
 import("//llvm/utils/gn/build/libs/zlib/enable.gni")
 import("//llvm/utils/gn/build/write_cmake_config.gni")
+import("//llvm/utils/llvm-lit/lit_path_function.gni")
 import("clang_lit_site_cfg_files.gni")
 
 template("write_lit_config") {
   write_cmake_config(target_name) {
     input = invoker.input
     output = invoker.output
+    dir = get_path_info(output, "dir")
     values = [
-      # FIXME: Write relative paths for path()s.
       "LIT_SITE_CFG_IN_HEADER=" +
-          "## Autogenerated from $input, do not edit\n\n" +
-          "def path(p): return p if p else \"\"",
+          "## Autogenerated from $input, do not edit\n\n" + lit_path_function,
       "CLANG_BINARY_DIR=" +
-          rebase_path(get_label_info("//clang", "target_out_dir")),
-      "CLANG_SOURCE_DIR=" + rebase_path("//clang"),
+          rebase_path(get_label_info("//clang", "target_out_dir"), dir),
+      "CLANG_SOURCE_DIR=" + rebase_path("//clang", dir),
       "ENABLE_SHARED=0",
       "LLVM_BINARY_DIR=" +
-          rebase_path(get_label_info("//llvm", "target_out_dir")),
+          rebase_path(get_label_info("//llvm", "target_out_dir"), dir),
       "LLVM_LIBS_DIR=",  # needed only for shared builds
-      "LLVM_SOURCE_DIR=" + rebase_path("//llvm"),
-      "LLVM_TOOLS_DIR=" + rebase_path("$root_out_dir/bin"),
+      "LLVM_SOURCE_DIR=" + rebase_path("//llvm", dir),
+      "LLVM_TOOLS_DIR=" + rebase_path("$root_out_dir/bin", dir),
       "TARGET_TRIPLE=$llvm_target_triple",
     ]
     if (host_os == "win") {
       # See comment for Windows solink in llvm/utils/gn/build/toolchain/BUILD.gn
-      values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/bin") ]
+      values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/bin", dir) ]
     } else {
-      values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/lib") ]
+      values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/lib", dir) ]
     }
     values += invoker.extra_values
   }
@@ -41,13 +41,13 @@ write_lit_config("lit_site_cfg") {
   # Fully-qualified instead of relative for LIT_SITE_CFG_IN_HEADER.
   input = "//clang/test/lit.site.cfg.py.in"
   output = clang_lit_site_cfg_file
-
+  dir = get_path_info(output, "dir")
   extra_values = [
     "LLVM_WITH_Z3=",  # Must be empty, not 0.
     "CLANG_BUILD_EXAMPLES=0",
     "CLANG_DEFAULT_CXX_STDLIB=",  # Empty string means "default value" here.
     "CLANG_DEFAULT_LINKER=",
-    "CLANG_TOOLS_DIR=" + rebase_path("$root_out_dir/bin"),
+    "CLANG_TOOLS_DIR=" + rebase_path("$root_out_dir/bin", dir),
 
     # This is only used if LLVM_USE_SANITIZER includes lsan and the host
     # OS is macOS. Since the GN build currently never uses LLVM_USE_SANITIZER,

diff  --git a/llvm/utils/gn/secondary/llvm/test/BUILD.gn b/llvm/utils/gn/secondary/llvm/test/BUILD.gn
index 27c96d29f9ef..6d68a4bb0537 100644
--- a/llvm/utils/gn/secondary/llvm/test/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/test/BUILD.gn
@@ -7,28 +7,28 @@ import("//llvm/utils/gn/build/libs/xar/enable.gni")
 import("//llvm/utils/gn/build/libs/xml/enable.gni")
 import("//llvm/utils/gn/build/libs/zlib/enable.gni")
 import("//llvm/utils/gn/build/write_cmake_config.gni")
+import("//llvm/utils/llvm-lit/lit_path_function.gni")
 import("llvm_lit_site_cfg_files.gni")
 
 template("write_lit_config") {
   write_cmake_config(target_name) {
     input = invoker.input
     output = invoker.output
+    dir = get_path_info(output, "dir")
     values = [
-      # FIXME: Write relative paths for path()s.
       "LIT_SITE_CFG_IN_HEADER=" +
-          "## Autogenerated from $input, do not edit\n\n" +
-          "def path(p): return p if p else \"\"",
+          "## Autogenerated from $input, do not edit\n\n" + lit_path_function,
       "ENABLE_SHARED=0",
       "LLVM_BINARY_DIR=" +
-          rebase_path(get_label_info("//llvm", "target_out_dir")),
-      "LLVM_SOURCE_DIR=" + rebase_path("//llvm"),
-      "LLVM_TOOLS_DIR=" + rebase_path("$root_out_dir/bin"),
+          rebase_path(get_label_info("//llvm", "target_out_dir"), dir),
+      "LLVM_SOURCE_DIR=" + rebase_path("//llvm", dir),
+      "LLVM_TOOLS_DIR=" + rebase_path("$root_out_dir/bin", dir),
     ]
     if (host_os == "win") {
       # See comment for Windows solink in llvm/utils/gn/build/toolchain/BUILD.gn
-      values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/bin") ]
+      values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/bin", dir) ]
     } else {
-      values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/lib") ]
+      values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/lib", dir) ]
     }
     values += invoker.extra_values
   }
@@ -37,6 +37,7 @@ template("write_lit_config") {
 write_lit_config("lit_site_cfg") {
   input = "//llvm/test/lit.site.cfg.py.in"
   output = llvm_lit_site_cfg_file
+  dir = get_path_info(output, "dir")
   extra_values = [
     "BUILD_SHARED_LIBS=0",
 
@@ -58,7 +59,7 @@ write_lit_config("lit_site_cfg") {
     "LLVM_ENABLE_FFI=0",
     "LLVM_HAVE_OPT_VIEWER_MODULES=0",
     "LLVM_HOST_TRIPLE=$llvm_current_triple",
-    "LLVM_LIBRARY_DIR=" + rebase_path("$root_out_dir/lib"),
+    "LLVM_LIBRARY_DIR=" + rebase_path("$root_out_dir/lib", dir),
     "LLVM_LINK_LLVM_DYLIB=0",
     "LLVM_LIT_TOOLS_DIR=",  # Intentionally empty, matches cmake build.
     "LLVM_NATIVE_ARCH=$native_target",

diff  --git a/llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn b/llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn
index 0dd17f370d13..526b93b4f0b9 100644
--- a/llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn
@@ -4,11 +4,10 @@ import("//clang/test/clang_lit_site_cfg_files.gni")
 import("//lld/test/lld_lit_site_cfg_files.gni")
 import("//llvm/test/llvm_lit_site_cfg_files.gni")
 import("//llvm/utils/gn/build/write_cmake_config.gni")
+import("//llvm/utils/llvm-lit/lit_path_function.gni")
 
 write_cmake_config("llvm-lit") {
   input = "llvm-lit.in"
-
-  # The rebase_path() calls below assume that this is in $root_out_dir/bin.
   output = "$root_out_dir/bin/llvm-lit"
 
   if (host_os == "win") {
@@ -78,18 +77,15 @@ write_cmake_config("llvm-lit") {
   # generated llvm.site.cfg.py file, so llvm-lit depends on all the targets to
   # generate the site.cfg.py file.
   # Note: \n is converted to a newline by write_cmake_config.py, not by gn.
-  config_map =
-      "def path(p):\n" + "    if not p: return ''\n" +
-      "    return os.path.abspath(os.path.join(__file__, '..', '..', p))\n"
-
+  config_map = lit_path_function + "\n"
+  dir = get_path_info(output, "dir")
   foreach(entry, entries) {
-    config_map +=
-        "\nmap_config(\n    path(r'" + rebase_path(entry[0], root_out_dir) +
-        "'),\n    path(r'" + rebase_path(entry[1], root_out_dir) + "'))"
+    config_map += "\nmap_config(\n    path(r'" + rebase_path(entry[0], dir) +
+                  "'),\n    path(r'" + rebase_path(entry[1], dir) + "'))"
   }
 
   values = [
-    "LLVM_SOURCE_DIR=" + rebase_path("//llvm", root_out_dir),
+    "LLVM_SOURCE_DIR=" + rebase_path("//llvm", dir),
     "BUILD_MODE=.",
     "LLVM_LIT_CONFIG_MAP=" + config_map,
   ]

diff  --git a/llvm/utils/gn/secondary/llvm/utils/llvm-lit/lit_path_function.gni b/llvm/utils/gn/secondary/llvm/utils/llvm-lit/lit_path_function.gni
new file mode 100644
index 000000000000..f877dc100dac
--- /dev/null
+++ b/llvm/utils/gn/secondary/llvm/utils/llvm-lit/lit_path_function.gni
@@ -0,0 +1,4 @@
+lit_path_function =
+    "# Takes a path that's relative to __file__ and makes it absolute.\n" +
+    "def path(p):\n" +
+    "    return os.path.abspath(os.path.join(__file__, '..', p)) if p else ''"


        


More information about the llvm-commits mailing list