diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-08 20:31:13 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-08 20:31:13 +0000 |
commit | 9af0b83e7ce94d9e5c61623ab76634f97374c517 (patch) | |
tree | 39a7df15f783c23fba52f38797a1b209836fe318 /build/util | |
parent | bf02a62e32aedeb9961b669ea14777ec3c2fa985 (diff) | |
download | chromium_src-9af0b83e7ce94d9e5c61623ab76634f97374c517.zip chromium_src-9af0b83e7ce94d9e5c61623ab76634f97374c517.tar.gz chromium_src-9af0b83e7ce94d9e5c61623ab76634f97374c517.tar.bz2 |
Add a target in GN that generates a last_change.h file for the SVN revision.
This is GN-only so the GYP build currently sets this to 0.
This adds the root generated file directory to all targets, so you can do #include "foo/bar.h" and get a generated file "bar.h" generated in directory "foo". This basically matches the internal Google build, and I use it here.
BUG=
R=viettrungluu@chromium.org
Review URL: https://codereview.chromium.org/46003002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233969 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build/util')
-rwxr-xr-x | build/util/lastchange.py | 65 |
1 files changed, 58 insertions, 7 deletions
diff --git a/build/util/lastchange.py b/build/util/lastchange.py index 3c1ce28..8d758d2 100755 --- a/build/util/lastchange.py +++ b/build/util/lastchange.py @@ -168,6 +168,42 @@ def FetchVersionInfo(default_lastchange, directory=None, version_info = VersionInfo(None, None) return version_info +def GetHeaderGuard(path): + """ + Returns the header #define guard for the given file path. + This treats everything after the last instance of "src/" as being a + relevant part of the guard. If there is no "src/", then the entire path + is used. + """ + src_index = path.rfind('src/') + if src_index != -1: + guard = path[src_index + 4:] + else: + guard = path + guard = guard.upper() + return guard.replace('/', '_').replace('.', '_').replace('\\', '_') + '_' + +def GetHeaderContents(path, define, version): + """ + Returns what the contents of the header file should be that indicate the given + revision. Note that the #define is specified as a string, even though it's + currently always a SVN revision number, in case we need to move to git hashes. + """ + header_guard = GetHeaderGuard(path) + + header_contents = """/* Generated by lastchange.py, do not edit.*/ + +#ifndef %(header_guard)s +#define %(header_guard)s + +#define %(define)s "%(version)s" + +#endif // %(header_guard)s +""" + header_contents = header_contents % { 'header_guard': header_guard, + 'define': define, + 'version': version } + return header_contents def WriteIfChanged(file_name, contents): """ @@ -191,16 +227,26 @@ def main(argv=None): parser = optparse.OptionParser(usage="lastchange.py [options]") parser.add_option("-d", "--default-lastchange", metavar="FILE", - help="default last change input FILE") + help="Default last change input FILE.") + parser.add_option("-m", "--version-macro", + help="Name of C #define when using --header. Defaults to " + + "LAST_CHANGE.", + default="LAST_CHANGE") parser.add_option("-o", "--output", metavar="FILE", - help="write last change to FILE") + help="Write last change to FILE. " + + "Can be combined with --header to write both files.") + parser.add_option("", "--header", metavar="FILE", + help="Write last change to FILE as a C/C++ header. " + + "Can be combined with --output to write both files.") parser.add_option("--revision-only", action='store_true', - help="just print the SVN revision number") + help="Just print the SVN revision number. Overrides any " + + "file-output-related options.") parser.add_option("-s", "--source-dir", metavar="DIR", - help="use repository in the given directory") + help="Use repository in the given directory.") opts, args = parser.parse_args(argv[1:]) out_file = opts.output + header = opts.header while len(args) and out_file is None: if out_file is None: @@ -224,10 +270,15 @@ def main(argv=None): print version_info.revision else: contents = "LASTCHANGE=%s\n" % version_info.revision - if out_file: - WriteIfChanged(out_file, contents) - else: + if not out_file and not opts.header: sys.stdout.write(contents) + else: + if out_file: + WriteIfChanged(out_file, contents) + if header: + WriteIfChanged(header, + GetHeaderContents(header, opts.version_macro, + version_info.revision)) return 0 |