[llvm] e306255 - gn build: set HAVE_VCS_VERSION_INC while building Version.cpp

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 23 13:11:24 PST 2019


Author: Nico Weber
Date: 2019-11-23T16:11:11-05:00
New Revision: e306255d45213c0201e236e0d62045965095f20c

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

LOG: gn build: set HAVE_VCS_VERSION_INC while building Version.cpp

And belatedly merge r353268 / r353269.

test/Driver/wasm-toolchain-lto.c currently requires getLLVMRevision()
to return something non-empty to pass. That's hopefully temporary,
but making Version.cpp work is probalby a good idea regardless.
(Note its contents will by default usually be out-of-date, because
llvm_allow_tardy_revision defaults to false.)

Added: 
    llvm/utils/gn/build/write_vcsrevision.gni

Modified: 
    llvm/utils/gn/build/write_vcsrevision.py
    llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
    llvm/utils/gn/secondary/lld/Common/BUILD.gn
    llvm/utils/gn/secondary/llvm/include/llvm/Support/BUILD.gn

Removed: 
    


################################################################################
diff  --git a/llvm/utils/gn/build/write_vcsrevision.gni b/llvm/utils/gn/build/write_vcsrevision.gni
new file mode 100644
index 000000000000..61ce0b02ca6b
--- /dev/null
+++ b/llvm/utils/gn/build/write_vcsrevision.gni
@@ -0,0 +1,54 @@
+# This file introduces a templates for calling write_vcsrevision.py.
+#
+# Parameters:
+#
+#   header (required) [string]
+#
+#   names (optional) [list of strings]
+#       Writes "$foo_REVISION" and "$foo_REPOSITORY" for each foo in names.
+#       Defaults to [ "LLVM" ]
+
+declare_args() {
+  # If this set to false, VCSRevision.h is updated after every git commit.
+  # That's technically correct, but results in rebuilds after every commit.
+  # If it's true (default), VCSRevision.h will usually be somewhat
+  # out-of-date, but builds will be faster.
+  llvm_allow_tardy_revision = true
+}
+
+template("write_vcsrevision") {
+  assert(defined(invoker.header), "must set 'header' in $target_name")
+
+  action("write_vcsrevision") {
+    script = "//llvm/utils/gn/build/write_vcsrevision.py"
+    header = invoker.header
+    if (defined(invoker.names)) {
+      names = invoker.names
+    } else {
+      names = [ "LLVM" ]
+    }
+
+    args = [ rebase_path(header, root_build_dir) ]
+    if (!llvm_allow_tardy_revision) {
+      depfile = "$header.d"
+      args += [
+        "-d",
+        rebase_path(depfile, root_build_dir),
+      ]
+    }
+
+    foreach(name, names) {
+      args += [ "--name=$name" ]
+    }
+
+    outputs = [
+      header,
+    ]
+
+    forward_variables_from(invoker,
+                           [
+                             "public_configs",
+                             "visibility",
+                           ])
+  }
+}

diff  --git a/llvm/utils/gn/build/write_vcsrevision.py b/llvm/utils/gn/build/write_vcsrevision.py
index 5bdca23e7648..10fc293bd21b 100755
--- a/llvm/utils/gn/build/write_vcsrevision.py
+++ b/llvm/utils/gn/build/write_vcsrevision.py
@@ -29,6 +29,9 @@ def main():
     parser.add_argument('-d', '--depfile',
                         help='if set, writes a depfile that causes this script '
                              'to re-run each time the current revision changes')
+    parser.add_argument('--name', action='append',
+                        help='if set, writes a depfile that causes this script '
+                             'to re-run each time the current revision changes')
     parser.add_argument('vcs_header', help='path to the output file to write')
     args = parser.parse_args()
 
@@ -54,8 +57,12 @@ def main():
 
     rev = subprocess.check_output([git, 'rev-parse', '--short', 'HEAD'],
                                   cwd=git_dir, shell=use_shell).decode().strip()
-    # FIXME: add pizzas such as the svn revision read off a git note?
-    vcsrevision_contents = '#define LLVM_REVISION "git-%s"\n' % rev
+    url = subprocess.check_output([git, 'remote', 'get-url', 'origin'],
+                                  cwd=git_dir, shell=use_shell).decode().strip()
+    vcsrevision_contents = ''
+    for name in args.name:
+        vcsrevision_contents += '#define %s_REVISION "%s"\n' % (name, rev)
+        vcsrevision_contents += '#define %s_REPOSITORY "%s"\n' % (name, url)
 
     # If the output already exists and is identical to what we'd write,
     # return to not perturb the existing file's timestamp.

diff  --git a/llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn b/llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
index 5245320d6cb4..27939314493e 100644
--- a/llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
+++ b/llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
@@ -1,20 +1,52 @@
+import("//llvm/utils/gn/build/write_vcsrevision.gni")
+
+config("write_vcsrevision_config") {
+  # To pick up the generated inc file.
+  include_dirs = [ target_gen_dir ]
+  visibility = [ ":write_vcsrevision" ]
+}
+
+write_vcsrevision("write_vcsrevision") {
+  visibility = [ ":Version" ]
+  header = "$target_gen_dir/VCSVersion.inc"
+  names = [ "LLVM", "CLANG" ]
+  public_configs = [ ":write_vcsrevision_config" ]
+}
+
+source_set("Version") {
+  visibility = [ ":Basic" ]
+
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  public_deps = [
+    # public_dep because public header Version.h includes generated Version.inc.
+    "//clang/include/clang/Basic:version",
+  ]
+  deps = [
+    ":write_vcsrevision",
+    "//clang/include/clang/Config",
+  ]
+  sources = [
+    "Version.cpp",
+  ]
+  defines = [ "HAVE_VCS_VERSION_INC" ]
+}
+
 static_library("Basic") {
   output_name = "clangBasic"
   configs += [ "//llvm/utils/gn/build:clang_code" ]
   public_deps = [
     # public_dep because public header Version.h includes generated Version.inc.
+    ":Version",
     "//clang/include/clang/Basic:AttrList",
     "//clang/include/clang/Basic:AttrSubMatchRulesList",
     "//clang/include/clang/Basic:DiagnosticGroups",
     "//clang/include/clang/Basic:arm_mve_builtins",
     "//clang/include/clang/Basic:diags_tablegen",
-    "//clang/include/clang/Basic:version",
   ]
   deps = [
     "//clang/include/clang/Basic:AttrHasAttributeImpl",
     "//clang/include/clang/Basic:arm_fp16",
     "//clang/include/clang/Basic:arm_neon",
-    "//clang/include/clang/Config",
     "//llvm/include/llvm/Config:llvm-config",
     "//llvm/lib/IR",
     "//llvm/lib/MC",
@@ -72,10 +104,6 @@ static_library("Basic") {
     "Targets/X86.cpp",
     "Targets/XCore.cpp",
     "TokenKinds.cpp",
-
-    # FIXME: This should be in its own target that passes -DHAVE_SVN_VERSION_INC
-    # and that also depends on a target generating SVNVersion.inc.
-    "Version.cpp",
     "Warnings.cpp",
     "XRayInstr.cpp",
     "XRayLists.cpp",

diff  --git a/llvm/utils/gn/secondary/lld/Common/BUILD.gn b/llvm/utils/gn/secondary/lld/Common/BUILD.gn
index a01696a7cf06..dc1804452fba 100644
--- a/llvm/utils/gn/secondary/lld/Common/BUILD.gn
+++ b/llvm/utils/gn/secondary/lld/Common/BUILD.gn
@@ -25,6 +25,8 @@ static_library("Common") {
     "TargetOptionsCommandFlags.cpp",
     "Threads.cpp",
     "Timer.cpp",
+
+    # FIXME: This should be in its own target that passes -DHAVE_VCS_VERSION_INC
     "Version.cpp",
   ]
 }

diff  --git a/llvm/utils/gn/secondary/llvm/include/llvm/Support/BUILD.gn b/llvm/utils/gn/secondary/llvm/include/llvm/Support/BUILD.gn
index cf26a214c327..f64ecebebcb0 100644
--- a/llvm/utils/gn/secondary/llvm/include/llvm/Support/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/include/llvm/Support/BUILD.gn
@@ -1,25 +1,5 @@
-declare_args() {
-  # If this set to false, VCSRevision.h is updated after every git commit.
-  # That's technically correct, but results in rebuilds after every commit.
-  # If it's true (default), VCSRevision.h will usually be somewhat
-  # out-of-date, but builds will be faster.
-  llvm_allow_tardy_revision = true
-}
+import("//llvm/utils/gn/build/write_vcsrevision.gni")
 
-action("write_vcsrevision") {
-  script = "//llvm/utils/gn/build/write_vcsrevision.py"
+write_vcsrevision("write_vcsrevision") {
   header = "$target_gen_dir/VCSRevision.h"
-
-  args = [ rebase_path(header, root_build_dir) ]
-  if (!llvm_allow_tardy_revision) {
-    depfile = "$header.d"
-    args += [
-      "-d",
-      rebase_path(depfile, root_build_dir),
-    ]
-  }
-
-  outputs = [
-    header,
-  ]
 }


        


More information about the llvm-commits mailing list