Commit 0707afc8 authored by machenbach's avatar machenbach Committed by Commit bot

Partially reland Auto-generate v8 version based on tags.

This relands parts of
https://codereview.chromium.org/843913009

It prepares for using this script outside of v8, e.g. in a
chromium hook.

The script is intended to run as a hook and will create
version_gen.cc if the content has changed.

Changes to gyp and gn files can land as a follow up, once
calling the hook on the chromium side has landed.

BUG=chromium:446166
LOG=n

Review URL: https://codereview.chromium.org/830093003

Cr-Commit-Position: refs/heads/master@{#26144}
parent cecd89c2
...@@ -46,6 +46,7 @@ shell_g ...@@ -46,6 +46,7 @@ shell_g
/out /out
/perf.data /perf.data
/perf.data.old /perf.data.old
/src/version_gen.cc
/test/benchmarks/CHECKED_OUT_* /test/benchmarks/CHECKED_OUT_*
/test/benchmarks/downloaded_* /test/benchmarks/downloaded_*
/test/benchmarks/kraken /test/benchmarks/kraken
......
...@@ -87,6 +87,11 @@ hooks = [ ...@@ -87,6 +87,11 @@ hooks = [
'pattern': '.', 'pattern': '.',
'action': ['python', 'v8/tools/clang/scripts/update.py', '--if-needed'], 'action': ['python', 'v8/tools/clang/scripts/update.py', '--if-needed'],
}, },
{
# Generate v8 version based on the last git tag.
"pattern": ".",
"action": ["python", "v8/build/generate_version.py"],
},
{ {
# A change to a .gyp, .gypi, or to GYP itself should run the generator. # A change to a .gyp, .gypi, or to GYP itself should run the generator.
"pattern": ".", "pattern": ".",
......
...@@ -266,7 +266,7 @@ NACL_CHECKS = $(addsuffix .check,$(NACL_BUILDS)) ...@@ -266,7 +266,7 @@ NACL_CHECKS = $(addsuffix .check,$(NACL_BUILDS))
# File where previously used GYPFLAGS are stored. # File where previously used GYPFLAGS are stored.
ENVFILE = $(OUTDIR)/environment ENVFILE = $(OUTDIR)/environment
.PHONY: all check clean builddeps dependencies $(ENVFILE).new native \ .PHONY: all check clean builddeps dependencies $(ENVFILE).new native version \
qc quickcheck $(QUICKCHECKS) turbocheck \ qc quickcheck $(QUICKCHECKS) turbocheck \
$(addsuffix .quickcheck,$(MODES)) $(addsuffix .quickcheck,$(ARCHES)) \ $(addsuffix .quickcheck,$(MODES)) $(addsuffix .quickcheck,$(ARCHES)) \
$(ARCHES) $(MODES) $(BUILDS) $(CHECKS) $(addsuffix .clean,$(ARCHES)) \ $(ARCHES) $(MODES) $(BUILDS) $(CHECKS) $(addsuffix .clean,$(ARCHES)) \
...@@ -279,9 +279,13 @@ ENVFILE = $(OUTDIR)/environment ...@@ -279,9 +279,13 @@ ENVFILE = $(OUTDIR)/environment
# Target definitions. "all" is the default. # Target definitions. "all" is the default.
all: $(DEFAULT_MODES) all: $(DEFAULT_MODES)
# Target for generating the v8 version file from git tags.
version:
build/generate_version.py
# Special target for the buildbots to use. Depends on $(OUTDIR)/Makefile # Special target for the buildbots to use. Depends on $(OUTDIR)/Makefile
# having been created before. # having been created before.
buildbot: buildbot: version
$(MAKE) -C "$(OUTDIR)" BUILDTYPE=$(BUILDTYPE) \ $(MAKE) -C "$(OUTDIR)" BUILDTYPE=$(BUILDTYPE) \
builddir="$(abspath $(OUTDIR))/$(BUILDTYPE)" builddir="$(abspath $(OUTDIR))/$(BUILDTYPE)"
...@@ -292,14 +296,14 @@ $(MODES): $(addsuffix .$$@,$(DEFAULT_ARCHES)) ...@@ -292,14 +296,14 @@ $(MODES): $(addsuffix .$$@,$(DEFAULT_ARCHES))
$(ARCHES): $(addprefix $$@.,$(DEFAULT_MODES)) $(ARCHES): $(addprefix $$@.,$(DEFAULT_MODES))
# Defines how to build a particular target (e.g. ia32.release). # Defines how to build a particular target (e.g. ia32.release).
$(BUILDS): $(OUTDIR)/Makefile.$$@ $(BUILDS): $(OUTDIR)/Makefile.$$@ version
@$(MAKE) -C "$(OUTDIR)" -f Makefile.$@ \ @$(MAKE) -C "$(OUTDIR)" -f Makefile.$@ \
BUILDTYPE=$(shell echo $(subst .,,$(suffix $@)) | \ BUILDTYPE=$(shell echo $(subst .,,$(suffix $@)) | \
python -c "print \ python -c "print \
raw_input().replace('opt', '').capitalize()") \ raw_input().replace('opt', '').capitalize()") \
builddir="$(shell pwd)/$(OUTDIR)/$@" builddir="$(shell pwd)/$(OUTDIR)/$@"
native: $(OUTDIR)/Makefile.native native: $(OUTDIR)/Makefile.native version
@$(MAKE) -C "$(OUTDIR)" -f Makefile.native \ @$(MAKE) -C "$(OUTDIR)" -f Makefile.native \
BUILDTYPE=Release \ BUILDTYPE=Release \
builddir="$(shell pwd)/$(OUTDIR)/$@" builddir="$(shell pwd)/$(OUTDIR)/$@"
...@@ -307,7 +311,8 @@ native: $(OUTDIR)/Makefile.native ...@@ -307,7 +311,8 @@ native: $(OUTDIR)/Makefile.native
$(ANDROID_ARCHES): $(addprefix $$@.,$(MODES)) $(ANDROID_ARCHES): $(addprefix $$@.,$(MODES))
$(ANDROID_BUILDS): $(GYPFILES) $(ENVFILE) build/android.gypi \ $(ANDROID_BUILDS): $(GYPFILES) $(ENVFILE) build/android.gypi \
must-set-ANDROID_NDK_ROOT_OR_TOOLCHAIN Makefile.android must-set-ANDROID_NDK_ROOT_OR_TOOLCHAIN Makefile.android \
version
@$(MAKE) -f Makefile.android $@ \ @$(MAKE) -f Makefile.android $@ \
ARCH="$(basename $@)" \ ARCH="$(basename $@)" \
MODE="$(subst .,,$(suffix $@))" \ MODE="$(subst .,,$(suffix $@))" \
...@@ -317,7 +322,7 @@ $(ANDROID_BUILDS): $(GYPFILES) $(ENVFILE) build/android.gypi \ ...@@ -317,7 +322,7 @@ $(ANDROID_BUILDS): $(GYPFILES) $(ENVFILE) build/android.gypi \
$(NACL_ARCHES): $(addprefix $$@.,$(MODES)) $(NACL_ARCHES): $(addprefix $$@.,$(MODES))
$(NACL_BUILDS): $(GYPFILES) $(ENVFILE) \ $(NACL_BUILDS): $(GYPFILES) $(ENVFILE) \
Makefile.nacl must-set-NACL_SDK_ROOT Makefile.nacl must-set-NACL_SDK_ROOT version
@$(MAKE) -f Makefile.nacl $@ \ @$(MAKE) -f Makefile.nacl $@ \
ARCH="$(basename $@)" \ ARCH="$(basename $@)" \
MODE="$(subst .,,$(suffix $@))" \ MODE="$(subst .,,$(suffix $@))" \
...@@ -417,7 +422,10 @@ native.clean: ...@@ -417,7 +422,10 @@ native.clean:
rm -rf $(OUTDIR)/native rm -rf $(OUTDIR)/native
find $(OUTDIR) -regex '.*\(host\|target\)\.native\.mk' -delete find $(OUTDIR) -regex '.*\(host\|target\)\.native\.mk' -delete
clean: $(addsuffix .clean, $(ARCHES) $(ANDROID_ARCHES) $(NACL_ARCHES)) native.clean gtags.clean version.clean:
rm -f src/version_gen.cc
clean: $(addsuffix .clean, $(ARCHES) $(ANDROID_ARCHES) $(NACL_ARCHES)) native.clean gtags.clean version.clean
# GYP file generation targets. # GYP file generation targets.
OUT_MAKEFILES = $(addprefix $(OUTDIR)/Makefile.,$(BUILDS)) OUT_MAKEFILES = $(addprefix $(OUTDIR)/Makefile.,$(BUILDS))
......
...@@ -5,20 +5,29 @@ ...@@ -5,20 +5,29 @@
""" """
Script to set v8's version file to the version given by the latest tag. Script to set v8's version file to the version given by the latest tag.
The script is intended to be run as a gclient hook. The script will write a
generated version file into the checkout.
On build systems where no git is available and where the version information
is not necessary, the version generation can be bypassed with the option
--skip.
""" """
import optparse
import os import os
import re import re
import subprocess import subprocess
import sys import sys
CWD = os.path.abspath( CWD = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
VERSION_CC = os.path.join(CWD, "src", "version.cc") VERSION_CC = os.path.join(CWD, "src", "version.cc")
VERSION_GEN_CC = os.path.join(CWD, "src", "version_gen.cc")
def main():
def generate_version_file():
tag = subprocess.check_output( tag = subprocess.check_output(
"git describe --tags", "git describe --tags",
shell=True, shell=True,
...@@ -49,30 +58,61 @@ def main(): ...@@ -49,30 +58,61 @@ def main():
build = str(int(build) + 1) build = str(int(build) + 1)
patch = "0" patch = "0"
# Modify version.cc with the new values. # Modify version_gen.cc with the new values.
with open(VERSION_CC, "r") as f:
text = f.read()
output = [] output = []
for line in text.split("\n"): with open(VERSION_CC, "r") as f:
for definition, substitute in ( for line in f:
("MAJOR_VERSION", major), for definition, substitute in (
("MINOR_VERSION", minor), ("MAJOR_VERSION", major),
("BUILD_NUMBER", build), ("MINOR_VERSION", minor),
("PATCH_LEVEL", patch), ("BUILD_NUMBER", build),
("IS_CANDIDATE_VERSION", candidate)): ("PATCH_LEVEL", patch),
if line.startswith("#define %s" % definition): ("IS_CANDIDATE_VERSION", candidate)):
line = re.sub("\d+$", substitute, line) if line.startswith("#define %s" % definition):
output.append(line) line = re.sub("\d+$", substitute, line)
with open(VERSION_CC, "w") as f: output.append(line)
f.write("\n".join(output))
# Prepare log message.
# Log what was done.
candidate_txt = " (candidate)" if candidate == "1" else "" candidate_txt = " (candidate)" if candidate == "1" else ""
patch_txt = ".%s" % patch if patch != "0" else "" patch_txt = ".%s" % patch if patch != "0" else ""
version_txt = ("%s.%s.%s%s%s" % version_txt = ("%s.%s.%s%s%s" %
(major, minor, build, patch_txt, candidate_txt)) (major, minor, build, patch_txt, candidate_txt))
print "Modified version.cc. Set V8 version to %s" % version_txt log_message = "Modifying version_gen.cc. Set V8 version to %s" % version_txt
return "".join(output), log_message
def bypass_version_file():
with open(VERSION_CC, "r") as f:
return f.read(), "Bypassing V8 version creation."
def main():
parser = optparse.OptionParser()
parser.add_option("--skip",
help="Use raw version.cc file (disables version "
"generation and uses a dummy version).",
default=False, action="store_true")
(options, args) = parser.parse_args()
if options.skip:
version_file_content, log_message = bypass_version_file()
else:
version_file_content, log_message = generate_version_file()
old_content = ""
if os.path.exists(VERSION_GEN_CC):
with open(VERSION_GEN_CC, "r") as f:
old_content = f.read()
# Only generate version file if content has changed.
if old_content != version_file_content:
with open(VERSION_GEN_CC, "w") as f:
f.write(version_file_content)
# Log what was calculated.
print log_message
return 0 return 0
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(main()) sys.exit(main())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment