[llvm] 18324bb - [gn build] Make paths in generated llvm-lit relative.

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Mon May 11 16:34:34 PDT 2020


Author: Nico Weber
Date: 2020-05-11T19:34:25-04:00
New Revision: 18324bb3d9175d000c6b83e3383a8feecfafdfed

URL: https://github.com/llvm/llvm-project/commit/18324bb3d9175d000c6b83e3383a8feecfafdfed
DIFF: https://github.com/llvm/llvm-project/commit/18324bb3d9175d000c6b83e3383a8feecfafdfed.diff

LOG: [gn build] Make paths in generated llvm-lit relative.

This ports d4638cba and e613f0ee to the GN build.
Since paths in the generated lit.site.cfg.py files still contain
absolute paths in the GN build, this isn't very useful yet.

No intended behavior change.

Added: 
    

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

Removed: 
    


################################################################################
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 d3da6fc3e930..0dd17f370d13 100644
--- a/llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn
@@ -7,6 +7,8 @@ import("//llvm/utils/gn/build/write_cmake_config.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") {
@@ -76,16 +78,18 @@ 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.
-  # FIXME: Write relative paths for path()s.
-  config_map = "def path(p): return p if p else \"\"\n"
+  config_map =
+      "def path(p):\n" + "    if not p: return ''\n" +
+      "    return os.path.abspath(os.path.join(__file__, '..', '..', p))\n"
 
   foreach(entry, entries) {
-    config_map += "map_config('" + rebase_path(entry[0]) + "', '" +
-                  rebase_path(entry[1]) + "')\n"
+    config_map +=
+        "\nmap_config(\n    path(r'" + rebase_path(entry[0], root_out_dir) +
+        "'),\n    path(r'" + rebase_path(entry[1], root_out_dir) + "'))"
   }
 
   values = [
-    "LLVM_SOURCE_DIR=" + rebase_path("//llvm"),
+    "LLVM_SOURCE_DIR=" + rebase_path("//llvm", root_out_dir),
     "BUILD_MODE=.",
     "LLVM_LIT_CONFIG_MAP=" + config_map,
   ]


        


More information about the llvm-commits mailing list