Commit 4dc19c38 by Geoff Lang Committed by Commit Bot

Always use commit_id.py to generate commit.h

commit_id_.py is capable of generating the default commit.h. This makes it so we always take a single path in gn. Remove the existing commit.h and generate it into the root generation folder (not the id subfolder) because Android blueprints can't handle generating into subfolders that don't exist. Make the <angle_dir> argument capable of taking a filename or directory name. This allows us to pass the .git/HEAD file which is a gn input. Android blueprints require all paths used as input or output to a script are listed as inputs or outputs in the genrule. BUG=angleproject:2344 Change-Id: Ifd9c8331f421586db6f2c6e17faf3242376e11d0 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2070600Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 74cc3a05
...@@ -54,15 +54,6 @@ if (ozone_platform_gbm) { ...@@ -54,15 +54,6 @@ if (ozone_platform_gbm) {
} }
} }
angle_git_is_present = exec_script("src/commit_id.py",
[
"check",
rebase_path(".", root_build_dir),
],
"value")
angle_use_commit_id = angle_git_is_present == 1
import("src/compiler.gni") import("src/compiler.gni")
import("src/libGLESv2.gni") import("src/libGLESv2.gni")
...@@ -466,29 +457,33 @@ config("commit_id_config") { ...@@ -466,29 +457,33 @@ config("commit_id_config") {
visibility = [ ":commit_id" ] visibility = [ ":commit_id" ]
} }
commit_id_output_file = "$root_gen_dir/angle/id/commit.h" commit_id_output_file = "$root_gen_dir/angle/commit.h"
if (angle_use_commit_id) { action("commit_id") {
action("commit_id") { script = "src/commit_id.py"
script = "src/commit_id.py" outputs = [ commit_id_output_file ]
outputs = [ commit_id_output_file ]
# commit id should depend on angle's HEAD revision
inputs = [ ".git/HEAD" ]
args = [ # commit id should depend on angle's HEAD revision
"gen", commit_id_git_dep = ".git/HEAD"
rebase_path(".", root_build_dir),
rebase_path(commit_id_output_file, root_build_dir),
]
public_configs = [ ":commit_id_config" ] # Add git as a dependency if it is available.
} angle_git_is_present =
} else { exec_script("src/commit_id.py",
copy("commit_id") { [
sources = [ "src/commit.h" ] "check",
outputs = [ commit_id_output_file ] rebase_path(commit_id_git_dep, root_build_dir),
public_configs = [ ":commit_id_config" ] ],
"value") == 1
if (angle_git_is_present) {
inputs = [ commit_id_git_dep ]
} }
args = [
"gen",
rebase_path(commit_id_git_dep, root_build_dir),
rebase_path(commit_id_output_file, root_build_dir),
]
public_configs = [ ":commit_id_config" ]
} }
angle_source_set("angle_version") { angle_source_set("angle_version") {
......
//
// Copyright 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// commit.h:
// This is a default commit hash header, when git is not available.
//
#define ANGLE_COMMIT_HASH "unknown hash"
#define ANGLE_COMMIT_HASH_SIZE 12
#define ANGLE_COMMIT_DATE "unknown date"
#define ANGLE_DISABLE_PROGRAM_BINARY_LOAD
...@@ -23,13 +23,17 @@ if len(sys.argv) < 3: ...@@ -23,13 +23,17 @@ if len(sys.argv) < 3:
sys.exit(usage) sys.exit(usage)
operation = sys.argv[1] operation = sys.argv[1]
cwd = sys.argv[2] if os.path.isdir(sys.argv[2]):
cwd = sys.argv[2]
else:
cwd = os.path.dirname(sys.argv[2])
if operation == 'check': if operation == 'check':
index_path = os.path.join(cwd, '.git', 'index') try:
if os.path.exists(index_path): # Try a git command to verify the cwd is valid and we can use the 'gen command'
grab_output('git status', cwd)
print("1") print("1")
else: except:
print("0") print("0")
sys.exit(0) sys.exit(0)
...@@ -38,13 +42,15 @@ if len(sys.argv) < 4 or operation != 'gen': ...@@ -38,13 +42,15 @@ if len(sys.argv) < 4 or operation != 'gen':
output_file = sys.argv[3] output_file = sys.argv[3]
commit_id_size = 12 commit_id_size = 12
commit_id = 'unknown hash'
commit_date = 'unknown date'
additional_defines = []
try: try:
commit_id = grab_output('git rev-parse --short=%d HEAD' % commit_id_size, cwd) commit_id = grab_output('git rev-parse --short=%d HEAD' % commit_id_size, cwd)
commit_date = grab_output('git show -s --format=%ci HEAD', cwd) commit_date = grab_output('git show -s --format=%ci HEAD', cwd)
except: except:
commit_id = 'invalid-hash' additional_defines.append('#define ANGLE_DISABLE_PROGRAM_BINARY_LOAD')
commit_date = 'invalid-date'
hfile = open(output_file, 'w') hfile = open(output_file, 'w')
...@@ -52,4 +58,7 @@ hfile.write('#define ANGLE_COMMIT_HASH "%s"\n' % commit_id) ...@@ -52,4 +58,7 @@ hfile.write('#define ANGLE_COMMIT_HASH "%s"\n' % commit_id)
hfile.write('#define ANGLE_COMMIT_HASH_SIZE %d\n' % commit_id_size) hfile.write('#define ANGLE_COMMIT_HASH_SIZE %d\n' % commit_id_size)
hfile.write('#define ANGLE_COMMIT_DATE "%s"\n' % commit_date) hfile.write('#define ANGLE_COMMIT_DATE "%s"\n' % commit_date)
for additional_define in additional_defines:
hfile.write(additional_define + '\n')
hfile.close() hfile.close()
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#ifndef COMMON_VERSION_H_ #ifndef COMMON_VERSION_H_
#define COMMON_VERSION_H_ #define COMMON_VERSION_H_
#include "id/commit.h" #include "commit.h"
#define ANGLE_MAJOR_VERSION 2 #define ANGLE_MAJOR_VERSION 2
#define ANGLE_MINOR_VERSION 1 #define ANGLE_MINOR_VERSION 1
......
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