[llvm] r348054 - [gn build] Add action to generate VCSRevision.h and use it to add llvm/lib/Object/BUILD.gn

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 30 16:02:39 PST 2018


Author: nico
Date: Fri Nov 30 16:02:39 2018
New Revision: 348054

URL: http://llvm.org/viewvc/llvm-project?rev=348054&view=rev
Log:
[gn build] Add action to generate VCSRevision.h and use it to add llvm/lib/Object/BUILD.gn

Differential Revision: https://reviews.llvm.org/D55090

Added:
    llvm/trunk/utils/gn/build/write_vcsrevision.py   (with props)
    llvm/trunk/utils/gn/secondary/llvm/include/llvm/Support/
    llvm/trunk/utils/gn/secondary/llvm/include/llvm/Support/BUILD.gn
    llvm/trunk/utils/gn/secondary/llvm/lib/Object/
    llvm/trunk/utils/gn/secondary/llvm/lib/Object/BUILD.gn
Modified:
    llvm/trunk/utils/gn/secondary/BUILD.gn

Added: llvm/trunk/utils/gn/build/write_vcsrevision.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/build/write_vcsrevision.py?rev=348054&view=auto
==============================================================================
--- llvm/trunk/utils/gn/build/write_vcsrevision.py (added)
+++ llvm/trunk/utils/gn/build/write_vcsrevision.py Fri Nov 30 16:02:39 2018
@@ -0,0 +1,77 @@
+#!/usr/bin/env python
+
+"""Gets the current revision and writes it to VCSRevision.h."""
+
+from __future__ import print_function
+
+import argparse
+import os
+import subprocess
+import sys
+
+
+THIS_DIR = os.path.abspath(os.path.dirname(__file__))
+LLVM_DIR = os.path.dirname(os.path.dirname(os.path.dirname(THIS_DIR)))
+MONO_DIR = os.path.dirname(LLVM_DIR)
+
+
+def which(program):
+    # distutils.spawn.which() doesn't find .bat files,
+    # https://bugs.python.org/issue2200
+    for path in os.environ["PATH"].split(os.pathsep):
+        candidate = os.path.join(path, program)
+        if os.path.isfile(candidate) and os.access(candidate, os.X_OK):
+            return candidate
+    return None
+
+
+def main():
+    parser = argparse.ArgumentParser(description=__doc__)
+    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('vcs_header', help='path to the output file to write')
+    args = parser.parse_args()
+
+    if os.path.isdir(os.path.join(LLVM_DIR, '.svn')):
+        print('SVN support not implemented', file=sys.stderr)
+        return 1
+    if os.path.isdir(os.path.join(LLVM_DIR, '.git')):
+        print('non-mono-repo git support not implemented', file=sys.stderr)
+        return 1
+
+    git_dir = os.path.join(MONO_DIR, '.git')
+    if not os.path.isdir(git_dir):
+        print('.git dir not found at "%s"' % git_dir, file=sys.stderr)
+        return 1
+
+    git, use_shell = which('git'), False
+    if not git:
+        git = which('git.exe')
+    if not git:
+        git = which('git.bat')
+        use_shell = True
+    rev = subprocess.check_output([git, 'rev-parse', '--short', 'HEAD'],
+                                  cwd=git_dir, shell=use_shell)
+    # FIXME: add pizzas such as the svn revision read off a git note?
+    vcsrevision_contents = '#define LLVM_REVISION "git-%s"\n' % rev.strip()
+
+    # If the output already exists and is identical to what we'd write,
+    # return to not perturb the existing file's timestamp.
+    if os.path.exists(args.vcs_header) and \
+            open(args.vcs_header).read() == vcsrevision_contents:
+        return 0
+
+    # http://neugierig.org/software/blog/2014/11/binary-revisions.html
+    if args.depfile:
+        build_dir = os.getcwd()
+        with open(args.depfile, 'w') as depfile:
+            depfile.write('%s: %s\n' % (
+                args.vcs_header,
+                os.path.relpath(os.path.join(git_dir, 'logs', 'HEAD'),
+                                build_dir)))
+    open(args.vcs_header, 'w').write(vcsrevision_contents)
+
+
+if __name__ == '__main__':
+    sys.exit(main())

Propchange: llvm/trunk/utils/gn/build/write_vcsrevision.py
------------------------------------------------------------------------------
    svn:executable = *

Modified: llvm/trunk/utils/gn/secondary/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/BUILD.gn?rev=348054&r1=348053&r2=348054&view=diff
==============================================================================
--- llvm/trunk/utils/gn/secondary/BUILD.gn (original)
+++ llvm/trunk/utils/gn/secondary/BUILD.gn Fri Nov 30 16:02:39 2018
@@ -1,8 +1,6 @@
 group("default") {
   deps = [
-    "//llvm/lib/Bitcode/Reader",
-    "//llvm/lib/IR",
-    "//llvm/lib/MC/MCParser",
+    "//llvm/lib/Object",
     "//llvm/tools/llvm-undname",
     "//llvm/utils/TableGen:llvm-tblgen",
   ]

Added: llvm/trunk/utils/gn/secondary/llvm/include/llvm/Support/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/include/llvm/Support/BUILD.gn?rev=348054&view=auto
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/include/llvm/Support/BUILD.gn (added)
+++ llvm/trunk/utils/gn/secondary/llvm/include/llvm/Support/BUILD.gn Fri Nov 30 16:02:39 2018
@@ -0,0 +1,25 @@
+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
+}
+
+action("write_vcsrevision") {
+  script = "//llvm/utils/gn/build/write_vcsrevision.py"
+  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,
+  ]
+}

Added: llvm/trunk/utils/gn/secondary/llvm/lib/Object/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/lib/Object/BUILD.gn?rev=348054&view=auto
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/lib/Object/BUILD.gn (added)
+++ llvm/trunk/utils/gn/secondary/llvm/lib/Object/BUILD.gn Fri Nov 30 16:02:39 2018
@@ -0,0 +1,38 @@
+static_library("Object") {
+  output_name = "LLVMObject"
+  deps = [
+    "//llvm/include/llvm/Config:llvm-config",
+    "//llvm/include/llvm/Support:write_vcsrevision",
+    "//llvm/lib/BinaryFormat",
+    "//llvm/lib/Bitcode/Reader",
+    "//llvm/lib/IR",
+    "//llvm/lib/MC",
+    "//llvm/lib/MC/MCParser",
+    "//llvm/lib/Support",
+  ]
+
+  sources = [
+    "Archive.cpp",
+    "ArchiveWriter.cpp",
+    "Binary.cpp",
+    "COFFImportFile.cpp",
+    "COFFModuleDefinition.cpp",
+    "COFFObjectFile.cpp",
+    "Decompressor.cpp",
+    "ELF.cpp",
+    "ELFObjectFile.cpp",
+    "Error.cpp",
+    "IRObjectFile.cpp",
+    "IRSymtab.cpp",
+    "MachOObjectFile.cpp",
+    "MachOUniversal.cpp",
+    "ModuleSymbolTable.cpp",
+    "Object.cpp",
+    "ObjectFile.cpp",
+    "RecordStreamer.cpp",
+    "SymbolSize.cpp",
+    "SymbolicFile.cpp",
+    "WasmObjectFile.cpp",
+    "WindowsResource.cpp",
+  ]
+}




More information about the llvm-commits mailing list