Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7e30318

Browse files
authored
Shift git version fetching to tools/gn (#51175)
Avoids GN invoking python scripts that run git commands to determine git hashes. Part of flutter/flutter#144430
1 parent e6974df commit 7e30318

File tree

2 files changed

+41
-32
lines changed

2 files changed

+41
-32
lines changed

shell/version/version.gni

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,6 @@ declare_args() {
1414

1515
_flutter_root = "//flutter"
1616

17-
if (engine_version == "") {
18-
engine_version_lines =
19-
exec_script("//flutter/build/git_revision.py",
20-
[
21-
"--repository",
22-
rebase_path(_flutter_root, "", _flutter_root),
23-
],
24-
"list lines")
25-
engine_version = engine_version_lines[0]
26-
}
27-
28-
if (skia_version == "") {
29-
skia_version_lines = exec_script(
30-
"//flutter/build/git_revision.py",
31-
[
32-
"--repository",
33-
rebase_path("//flutter/third_party/skia", "", _flutter_root),
34-
],
35-
"list lines")
36-
skia_version = skia_version_lines[0]
37-
}
38-
39-
if (dart_version == "") {
40-
dart_version_lines =
41-
exec_script("//flutter/build/git_revision.py",
42-
[
43-
"--repository",
44-
rebase_path("$dart_src", "", _flutter_root),
45-
],
46-
"list lines")
47-
dart_version = dart_version_lines[0]
48-
}
17+
assert(engine_version != "", "The engine_version argument must be supplied")
18+
assert(skia_version != "", "The skia_version argument must be supplied")
19+
assert(dart_version != "", "The dart_version argument must be supplied")

tools/gn

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,40 @@ def setup_apple_sdks():
344344
return sdks_gn_args
345345

346346

347+
def get_repository_version(repository):
348+
'Returns the Git HEAD for the supplied repository path as a string.'
349+
if not os.path.exists(repository):
350+
raise IOError('path does not exist')
351+
352+
git = 'git'
353+
if sys.platform.startswith(('cygwin', 'win')):
354+
git = 'git.bat'
355+
version = subprocess.check_output([
356+
git,
357+
'-C',
358+
repository,
359+
'rev-parse',
360+
'HEAD',
361+
])
362+
363+
return str(version.strip(), 'utf-8')
364+
365+
366+
def setup_git_versions():
367+
revision_args = {}
368+
369+
engine_path = os.path.join(SRC_ROOT, 'flutter')
370+
revision_args['engine_version'] = get_repository_version(engine_path)
371+
372+
skia_path = os.path.join(SRC_ROOT, 'flutter', 'third_party', 'skia')
373+
revision_args['skia_version'] = get_repository_version(skia_path)
374+
375+
dart_path = os.path.join(SRC_ROOT, 'third_party', 'dart')
376+
revision_args['dart_version'] = get_repository_version(dart_path)
377+
378+
return revision_args
379+
380+
347381
def to_gn_args(args):
348382
if args.simulator:
349383
if args.target_os != 'ios':
@@ -355,6 +389,8 @@ def to_gn_args(args):
355389

356390
gn_args['is_debug'] = args.unoptimized
357391

392+
gn_args.update(setup_git_versions())
393+
358394
gn_args.update(setup_goma(args))
359395

360396
gn_args.update(setup_rbe(args))
@@ -697,6 +733,8 @@ def to_gn_args(args):
697733
# for a host Windows build and make GN think we will be building ANGLE.
698734
# Angle is not used on Mac hosts as there are no tests for the OpenGL backend.
699735
if is_host_build(args) or (args.target_os == 'android' and get_host_os() == 'win'):
736+
# Don't include git commit information.
737+
gn_args['angle_enable_commit_id'] = False
700738
# Do not build unnecessary parts of the ANGLE tree.
701739
gn_args['angle_build_all'] = False
702740
gn_args['angle_has_astc_encoder'] = False

0 commit comments

Comments
 (0)