[gn build] Make config_map computation in llvm-lit more table-driven.
authorNico Weber <thakis@chromium.org>
Mon, 11 May 2020 23:21:31 +0000 (19:21 -0400)
committerNico Weber <thakis@chromium.org>
Mon, 11 May 2020 23:21:56 +0000 (19:21 -0400)
No behavior change.

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

index ca2ca24..d3da6fc 100644 (file)
@@ -17,13 +17,6 @@ write_cmake_config("llvm-lit") {
   # lit's lit/llvm/config.py shells out to llvm-config.
   deps = [ "//llvm/tools/llvm-config" ]
 
-  # Generate LLVM_LIT_CONFIG_MAP parameter.
-  # llvm-lit contains a mapping from each lit.cfg.py file to the corresponding
-  # generated llvm.site.cfg.py file, so llvm-lit depends on all the targets to
-  # generate the site.cfg.py file.
-  # FIXME: Write relative paths for path()s.
-  config_map = "def path(p): return p if p else \"\"\n"
-
   deps += [
     "//clang-tools-extra/test:lit_site_cfg",
     "//clang-tools-extra/test:lit_unit_site_cfg",
@@ -35,31 +28,61 @@ write_cmake_config("llvm-lit") {
     "//llvm/test:lit_unit_site_cfg",
   ]
 
-  # Note: \n is converted into a newline by write_cmake_config.py, not by gn.
-  config_map +=
-      "map_config('" + rebase_path("//clang-tools-extra/test/lit.cfg.py") +
-      "', '" + rebase_path(clang_tools_extra_lit_site_cfg_file) + "')\n"
-  config_map +=
-      "map_config('" + rebase_path("//clang-tools-extra/test/Unit/lit.cfg.py") +
-      "', '" + rebase_path(clang_tools_extra_lit_unit_site_cfg_file) + "')\n"
-  config_map += "map_config('" +
-                rebase_path("//clang-tools-extra/clangd/test/lit.cfg.py") +
-                "', '" + rebase_path(clangd_lit_site_cfg_file) + "')\n"
-  config_map += "map_config('" +
-                rebase_path("//clang-tools-extra/clang/unittests/lit.cfg.py") +
-                "', '" + rebase_path(clangd_lit_unit_site_cfg_file) + "')\n"
-  config_map += "map_config('" + rebase_path("//clang/test/lit.cfg.py") +
-                "', '" + rebase_path(clang_lit_site_cfg_file) + "')\n"
-  config_map += "map_config('" + rebase_path("//clang/test/Unit/lit.cfg.py") +
-                "', '" + rebase_path(clang_lit_unit_site_cfg_file) + "')\n"
-  config_map += "map_config('" + rebase_path("//lld/test/lit.cfg.py") + "', '" +
-                rebase_path(lld_lit_site_cfg_file) + "')\n"
-  config_map += "map_config('" + rebase_path("//lld/test/Unit/lit.cfg.py") +
-                "', '" + rebase_path(lld_lit_unit_site_cfg_file) + "')\n"
-  config_map += "map_config('" + rebase_path("//llvm/test/lit.cfg.py") +
-                "', '" + rebase_path(llvm_lit_site_cfg_file) + "')\n"
-  config_map += "map_config('" + rebase_path("//llvm/test/Unit/lit.cfg.py") +
-                "', '" + rebase_path(llvm_lit_unit_site_cfg_file) + "')\n"
+  entries = [
+    [
+      "//clang-tools-extra/test/lit.cfg.py",
+      clang_tools_extra_lit_site_cfg_file,
+    ],
+    [
+      "//clang-tools-extra/test/Unit/lit.cfg.py",
+      clang_tools_extra_lit_unit_site_cfg_file,
+    ],
+    [
+      "//clang-tools-extra/clangd/test/lit.cfg.py",
+      clangd_lit_site_cfg_file,
+    ],
+    [
+      "//clang-tools-extra/clangd/unittests/lit.cfg.py",
+      clangd_lit_unit_site_cfg_file,
+    ],
+    [
+      "//clang/test/lit.cfg.py",
+      clang_lit_site_cfg_file,
+    ],
+    [
+      "//clang/test/Unit/lit.cfg.py",
+      clang_lit_unit_site_cfg_file,
+    ],
+    [
+      "//lld/test/lit.cfg.py",
+      lld_lit_site_cfg_file,
+    ],
+    [
+      "//lld/test/Unit/lit.cfg.py",
+      lld_lit_unit_site_cfg_file,
+    ],
+    [
+      "//llvm/test/lit.cfg.py",
+      llvm_lit_site_cfg_file,
+    ],
+    [
+      "//llvm/test/Unit/lit.cfg.py",
+      llvm_lit_unit_site_cfg_file,
+    ],
+  ]
+
+  # Generate LLVM_LIT_CONFIG_MAP parameter.
+  # llvm-lit contains a mapping from each lit.cfg.py file to the corresponding
+  # 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"
+
+  foreach(entry, entries) {
+    config_map += "map_config('" + rebase_path(entry[0]) + "', '" +
+                  rebase_path(entry[1]) + "')\n"
+  }
 
   values = [
     "LLVM_SOURCE_DIR=" + rebase_path("//llvm"),