Commit d3d6e38b authored by machenbach's avatar machenbach Committed by Commit bot

Reland Auto-generate v8 version based on tags.

This relands the CL
https://codereview.chromium.org/797503007/.

It runs the version generation two times. First during
runhooks as a fallback for recipes that loose git context
(e.g. android_aosp). Second during compilation like in the
original CL. In case of failures, the result from the
runhooks call will be reused.

BUG=chromium:446166
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#26120}
parent d962c092
......@@ -27,6 +27,7 @@
.project
.pydevproject
.settings
.version.cc
.*.sw?
bsuite
d8
......
......@@ -314,6 +314,25 @@ action("run_mksnapshot") {
}
}
action("generate_v8_version") {
visibility = [ ":*" ] # Only targets in this file can depend on this.
script = "tools/push-to-trunk/generate_version.py"
sources = [
"src/version.cc",
]
outputs = [
"$target_gen_dir/version.cc"
]
args = [
rebase_path("$target_gen_dir/version.cc", root_build_dir),
]
}
###############################################################################
# Source Sets (aka static libraries)
#
......@@ -398,6 +417,7 @@ source_set("v8_base") {
visibility = [ ":*" ] # Only targets in this file can depend on this.
sources = [
"$target_gen_dir/version.cc",
"src/accessors.cc",
"src/accessors.h",
"src/allocation.cc",
......@@ -934,7 +954,6 @@ source_set("v8_base") {
"src/v8threads.h",
"src/variables.cc",
"src/variables.h",
"src/version.cc",
"src/version.h",
"src/vm-state-inl.h",
"src/vm-state.h",
......@@ -1212,6 +1231,7 @@ source_set("v8_base") {
defines = []
deps = [
":v8_libbase",
":generate_v8_version",
]
if (is_win) {
......
......@@ -87,6 +87,13 @@ hooks = [
'pattern': '.',
'action': ['python', 'v8/tools/clang/scripts/update.py', '--if-needed'],
},
{
# Generate v8 version based on the last git tag.
"pattern": ".",
"action": ["python",
"v8/tools/push-to-trunk/generate_version.py",
"--hook"],
},
{
# A change to a .gyp, .gypi, or to GYP itself should run the generator.
"pattern": ".",
......
......@@ -335,6 +335,34 @@
}],
],
},
{
'target_name': 'v8_version',
'type': 'none',
'conditions': [
['want_separate_host_toolset==1', {
'toolsets': ['host'],
}, {
'toolsets': ['target'],
}],
],
'actions': [
{
'action_name': 'generate_v8_version',
'inputs': [
'../../tools/push-to-trunk/generate_version.py',
'../../src/version.cc',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/version.cc',
],
'action': [
'python',
'../../tools/push-to-trunk/generate_version.py',
'<(SHARED_INTERMEDIATE_DIR)/version.cc',
],
},
],
},
{
'target_name': 'v8_base',
'type': 'static_library',
......@@ -348,6 +376,7 @@
'../..',
],
'sources': [ ### gcmole(all) ###
'<(SHARED_INTERMEDIATE_DIR)/version.cc',
'../../src/accessors.cc',
'../../src/accessors.h',
'../../src/allocation.cc',
......@@ -887,7 +916,6 @@
'../../src/variables.cc',
'../../src/variables.h',
'../../src/vector.h',
'../../src/version.cc',
'../../src/version.h',
'../../src/vm-state-inl.h',
'../../src/vm-state.h',
......@@ -899,8 +927,14 @@
],
'conditions': [
['want_separate_host_toolset==1', {
'dependencies': [
'v8_version#host',
],
'toolsets': ['host', 'target'],
}, {
'dependencies': [
'v8_version',
],
'toolsets': ['target'],
}],
['v8_target_arch=="arm"', {
......
......@@ -5,9 +5,23 @@
"""
Script to set v8's version file to the version given by the latest tag.
The script can be run in two modes:
1) As a gclient hook with the option --hook.
The script will write a temporary version file into the checkout.
2) During compilation as an action.
The script will write version.cc in the output folder based on the
tag info. In case of a failure it will fall back to the temporary file
from the hook call.
In most cases, 2) will succeed and the temporary information from 1) won't
be used. In case the checkout is copied somewhere and the git context is
lost (e.g. on the android_aosp builder), the temporary file from 1) is
required.
"""
import optparse
import os
import re
import subprocess
......@@ -17,8 +31,10 @@ import sys
CWD = os.path.abspath(
os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
VERSION_CC = os.path.join(CWD, "src", "version.cc")
TMP_VERSION_CC = os.path.join(CWD, ".version.cc")
def main():
def generate_version_file():
tag = subprocess.check_output(
"git describe --tags",
shell=True,
......@@ -50,28 +66,68 @@ def main():
patch = "0"
# Modify version.cc with the new values.
with open(VERSION_CC, "r") as f:
text = f.read()
output = []
for line in text.split("\n"):
for definition, substitute in (
("MAJOR_VERSION", major),
("MINOR_VERSION", minor),
("BUILD_NUMBER", build),
("PATCH_LEVEL", patch),
("IS_CANDIDATE_VERSION", candidate)):
if line.startswith("#define %s" % definition):
line = re.sub("\d+$", substitute, line)
output.append(line)
with open(VERSION_CC, "w") as f:
f.write("\n".join(output))
# Log what was done.
with open(VERSION_CC, "r") as f:
for line in f:
for definition, substitute in (
("MAJOR_VERSION", major),
("MINOR_VERSION", minor),
("BUILD_NUMBER", build),
("PATCH_LEVEL", patch),
("IS_CANDIDATE_VERSION", candidate)):
if line.startswith("#define %s" % definition):
line = re.sub("\d+$", substitute, line)
output.append(line)
# Log what was calculated.
candidate_txt = " (candidate)" if candidate == "1" else ""
patch_txt = ".%s" % patch if patch != "0" else ""
version_txt = ("%s.%s.%s%s%s" %
(major, minor, build, patch_txt, candidate_txt))
print "Modified version.cc. Set V8 version to %s" % version_txt
print "Modifying version.cc. Set V8 version to %s" % version_txt
return "".join(output)
def delete_tmp_version_file():
# Make sure a subsequent call to this script doesn't use an outdated
# version file.
if os.path.exists(TMP_VERSION_CC):
os.remove(TMP_VERSION_CC)
def main():
parser = optparse.OptionParser()
parser.add_option("--hook",
help="Run as a gclient hook",
default=False, action="store_true")
(options, args) = parser.parse_args()
if options.hook:
version_out = TMP_VERSION_CC
else:
if len(args) != 1:
print "Error: Specify the output file path for version.cc"
return 1
version_out = args[0]
assert os.path.exists(os.path.dirname(version_out))
try:
version_file_content = generate_version_file()
except Exception as e:
# Allow exceptions when run during compilation. E.g. there might be no git
# context availabe. When run as a gclient hook, generation must succeed.
if options.hook:
delete_tmp_version_file()
raise e
# Assume the script already ran as a hook.
print "No git context available. Using V8 version from hook."
assert os.path.exists(TMP_VERSION_CC)
with open(TMP_VERSION_CC, "r") as f:
version_file_content = f.read()
delete_tmp_version_file()
with open(version_out, "w") as f:
f.write(version_file_content)
return 0
if __name__ == "__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