Skip to content

Commit

Permalink
Always use commit_id.py to generate commit.h
Browse files Browse the repository at this point in the history
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/+/2070600
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Geoff Lang <geofflang@chromium.org>
  • Loading branch information
vonture authored and Commit Bot committed Feb 24, 2020
1 parent 74cc3a0 commit 4dc19c3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 50 deletions.
53 changes: 24 additions & 29 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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/libGLESv2.gni")

Expand Down Expand Up @@ -466,29 +457,33 @@ config("commit_id_config") {
visibility = [ ":commit_id" ]
}

commit_id_output_file = "$root_gen_dir/angle/id/commit.h"
if (angle_use_commit_id) {
action("commit_id") {
script = "src/commit_id.py"
outputs = [ commit_id_output_file ]

# commit id should depend on angle's HEAD revision
inputs = [ ".git/HEAD" ]
commit_id_output_file = "$root_gen_dir/angle/commit.h"
action("commit_id") {
script = "src/commit_id.py"
outputs = [ commit_id_output_file ]

args = [
"gen",
rebase_path(".", root_build_dir),
rebase_path(commit_id_output_file, root_build_dir),
]
# commit id should depend on angle's HEAD revision
commit_id_git_dep = ".git/HEAD"

public_configs = [ ":commit_id_config" ]
}
} else {
copy("commit_id") {
sources = [ "src/commit.h" ]
outputs = [ commit_id_output_file ]
public_configs = [ ":commit_id_config" ]
# Add git as a dependency if it is available.
angle_git_is_present =
exec_script("src/commit_id.py",
[
"check",
rebase_path(commit_id_git_dep, root_build_dir),
],
"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") {
Expand Down
14 changes: 0 additions & 14 deletions src/commit.h

This file was deleted.

21 changes: 15 additions & 6 deletions src/commit_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ def grab_output(command, cwd):
sys.exit(usage)

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':
index_path = os.path.join(cwd, '.git', 'index')
if os.path.exists(index_path):
try:
# Try a git command to verify the cwd is valid and we can use the 'gen command'
grab_output('git status', cwd)
print("1")
else:
except:
print("0")
sys.exit(0)

Expand All @@ -38,18 +42,23 @@ def grab_output(command, cwd):

output_file = sys.argv[3]
commit_id_size = 12
commit_id = 'unknown hash'
commit_date = 'unknown date'

additional_defines = []
try:
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)
except:
commit_id = 'invalid-hash'
commit_date = 'invalid-date'
additional_defines.append('#define ANGLE_DISABLE_PROGRAM_BINARY_LOAD')

hfile = open(output_file, 'w')

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_DATE "%s"\n' % commit_date)

for additional_define in additional_defines:
hfile.write(additional_define + '\n')

hfile.close()
2 changes: 1 addition & 1 deletion src/common/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef COMMON_VERSION_H_
#define COMMON_VERSION_H_

#include "id/commit.h"
#include "commit.h"

#define ANGLE_MAJOR_VERSION 2
#define ANGLE_MINOR_VERSION 1
Expand Down

0 comments on commit 4dc19c3

Please sign in to comment.