Skip to content

Commit e3d6800

Browse files
jtmcdoleazatech
authored andcommitted
fix: produce pom/jar files with content_hash (flutter#172378)
fixes: flutter#172259 The contents of the files (pom, .jar) produced by android also reference the artifacts version number (which includes the git-hash). The flutter recipies are just dumb re-uploaders for the content hash at the moment. In order to change the contents, we can just update some GN files. This has some local duplication of files, but is acceptible for now. I've also added the content-hash as a string in the .so file and its printed out next to the hash. "Why is the folder name the git-hash?" The recipies have a quirk - the logs will have you believe they upload individual files such that "gsutil cp a.jar b.jar" would produce "b.jar"; but that's not what's going on. The recipies recurisively upload from the root of the temporary folder the files are copied to. At the moment, the "Ensure" step of builder.py updates the URL path, so it will handling uploading to the correct path, but not the file or its contents (hence this change). Plan for the future: at some point we can stop producing git-ref hashes. E.g. git-hash: dfd7318 content-hash: 3bfa6013b7be2b0bbadc22a9c3495d4efa46aba7 ```shell zip_archives └── download.flutter.io └── io └── flutter ├── arm64_v8a_debug │   └── 1.0.0-dfd7318efc71019bce1665bc41c0e8c21d1344f9 │   ├── arm64_v8a_debug-1.0.0-3bfa6013b7be2b0bbadc22a9c3495d4efa46aba7.jar │   ├── arm64_v8a_debug-1.0.0-3bfa6013b7be2b0bbadc22a9c3495d4efa46aba7.pom │   ├── arm64_v8a_debug-1.0.0-dfd7318efc71019bce1665bc41c0e8c21d1344f9.jar │   └── arm64_v8a_debug-1.0.0-dfd7318efc71019bce1665bc41c0e8c21d1344f9.pom └── flutter_embedding_debug └── 1.0.0-dfd7318efc71019bce1665bc41c0e8c21d1344f9 ├── flutter_embedding_debug-1.0.0-3bfa6013b7be2b0bbadc22a9c3495d4efa46aba7-sources.jar ├── flutter_embedding_debug-1.0.0-3bfa6013b7be2b0bbadc22a9c3495d4efa46aba7.jar ├── flutter_embedding_debug-1.0.0-3bfa6013b7be2b0bbadc22a9c3495d4efa46aba7.pom ├── flutter_embedding_debug-1.0.0-dfd7318efc71019bce1665bc41c0e8c21d1344f9-sources.jar ├── flutter_embedding_debug-1.0.0-dfd7318efc71019bce1665bc41c0e8c21d1344f9.jar └── flutter_embedding_debug-1.0.0-dfd7318efc71019bce1665bc41c0e8c21d1344f9.pom ```
1 parent d240bd1 commit e3d6800

File tree

7 files changed

+156
-5
lines changed

7 files changed

+156
-5
lines changed

engine/src/flutter/shell/common/switches.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ void PrintUsage(const std::string& executable_name) {
9393

9494
std::cerr << "Flutter Engine Version: " << GetFlutterEngineVersion()
9595
<< std::endl;
96+
97+
std::cerr << "Flutter Content Hash: " << GetFlutterContentHash() << std::endl;
98+
9699
std::cerr << "Skia Version: " << GetSkiaVersion() << std::endl;
97100

98101
std::cerr << "Dart Version: " << GetDartVersion() << std::endl << std::endl;

engine/src/flutter/shell/platform/android/BUILD.gn

Lines changed: 123 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,8 @@ action("android_jar") {
533533
deps = [
534534
":flutter_shell_java",
535535
":flutter_shell_native",
536+
":pom_content_hash_embedding",
537+
":pom_content_hash_libflutter",
536538
":pom_embedding",
537539
":pom_libflutter",
538540
]
@@ -603,6 +605,30 @@ action("pom_libflutter") {
603605
]
604606
}
605607

608+
action("pom_content_hash_libflutter") {
609+
script = "//flutter/tools/androidx/generate_pom_file.py"
610+
611+
inputs = [ "//flutter/tools/androidx/files.json" ]
612+
613+
artifact_id =
614+
string_replace(android_app_abi, "-", "_") + "_" + flutter_runtime_mode
615+
616+
hash_dir = "$root_build_dir/content_hash"
617+
outputs = [
618+
"$hash_dir/$artifact_id.pom",
619+
"$hash_dir/$artifact_id.maven-metadata.xml",
620+
]
621+
622+
args = [
623+
"--destination",
624+
rebase_path(hash_dir),
625+
"--engine-version",
626+
content_hash,
627+
"--engine-artifact-id",
628+
artifact_id,
629+
]
630+
}
631+
606632
action("pom_embedding") {
607633
script = "//flutter/tools/androidx/generate_pom_file.py"
608634

@@ -627,6 +653,31 @@ action("pom_embedding") {
627653
]
628654
}
629655

656+
action("pom_content_hash_embedding") {
657+
script = "//flutter/tools/androidx/generate_pom_file.py"
658+
659+
inputs = [ "//flutter/tools/androidx/files.json" ]
660+
661+
artifact_id = "flutter_embedding_$flutter_runtime_mode"
662+
663+
hash_dir = "$root_build_dir/content_hash"
664+
outputs = [
665+
"$hash_dir/$artifact_id.pom",
666+
"$hash_dir/$artifact_id.maven-metadata.xml",
667+
]
668+
669+
args = [
670+
"--destination",
671+
rebase_path(hash_dir),
672+
"--engine-version",
673+
content_hash,
674+
"--engine-artifact-id",
675+
artifact_id,
676+
"--include-embedding-dependencies",
677+
"true",
678+
]
679+
}
680+
630681
# TODO(jsimmons): remove this placeholder when it is no longer used by the LUCI recipes
631682
group("robolectric_tests") {
632683
deps = [ ":android_jar" ]
@@ -792,18 +843,26 @@ action("embedding_jars") {
792843

793844
deps = [
794845
":flutter_shell_java",
846+
":pom_content_hash_embedding",
795847
":pom_embedding",
796848
]
797-
sources = [
849+
base_sources = [
798850
"$root_out_dir/flutter_embedding_$flutter_runtime_mode.jar",
799851
"$root_out_dir/flutter_embedding_$flutter_runtime_mode.pom",
800852
]
853+
hash_dir = "$root_build_dir/content_hash"
854+
hash_sources = [
855+
"$hash_dir/flutter_embedding_$flutter_runtime_mode.pom",
856+
"$root_out_dir/flutter_embedding_$flutter_runtime_mode.jar",
857+
]
858+
sources = base_sources + hash_sources
859+
801860
outputs = []
802861
args = []
803862
base_name = "$root_out_dir/zip_archives/download.flutter.io/io/flutter/" +
804863
"flutter_embedding_$flutter_runtime_mode/1.0.0-$engine_version/" +
805864
"flutter_embedding_$flutter_runtime_mode-1.0.0-${engine_version}"
806-
foreach(source, sources) {
865+
foreach(source, base_sources) {
807866
extension = get_path_info(source, "extension")
808867
name = get_path_info(source, "name")
809868
if (extension == "jar") {
@@ -828,6 +887,40 @@ action("embedding_jars") {
828887
]
829888
}
830889
}
890+
891+
# NOTE(codefu): the URL having /*-$engine_version/ is expected; we want these
892+
# files in one URL. The flutter-recipes duplicate them to content_hash as
893+
# part of its upload step.
894+
# More info here: https://github.com/flutter/flutter/issues/172259
895+
hash_base_name =
896+
"$root_out_dir/zip_archives/download.flutter.io/io/flutter/" +
897+
"flutter_embedding_$flutter_runtime_mode/1.0.0-$engine_version/" +
898+
"flutter_embedding_$flutter_runtime_mode-1.0.0-${content_hash}"
899+
foreach(source, hash_sources) {
900+
extension = get_path_info(source, "extension")
901+
name = get_path_info(source, "name")
902+
if (extension == "jar") {
903+
outputs += [
904+
"${hash_base_name}.jar",
905+
"${hash_base_name}-sources.jar",
906+
]
907+
args += [
908+
"-i",
909+
"${name}.jar",
910+
rebase_path("${hash_base_name}.jar"),
911+
"-i",
912+
"${name}-sources.jar",
913+
rebase_path("${hash_base_name}-sources.jar"),
914+
]
915+
} else {
916+
outputs += [ "${hash_base_name}.${extension}" ]
917+
args += [
918+
"-i",
919+
rebase_path(source),
920+
rebase_path("${hash_base_name}.${extension}"),
921+
]
922+
}
923+
}
831924
}
832925

833926
# Renames android artifacts and places them in the final
@@ -836,21 +929,28 @@ action("abi_jars") {
836929
script = "//flutter/build/android_artifacts.py"
837930
deps = [
838931
":android_jar",
932+
":pom_content_hash_libflutter",
839933
":pom_libflutter",
840934
]
841935

842936
artifact_id =
843937
string_replace(android_app_abi, "-", "_") + "_" + flutter_runtime_mode
844-
sources = [
938+
base_sources = [
845939
"$root_out_dir/${artifact_id}.jar",
846940
"$root_out_dir/${artifact_id}.pom",
847941
]
942+
hash_dir = "$root_build_dir/content_hash"
943+
hash_sources = [
944+
"$hash_dir/${artifact_id}.pom",
945+
"$root_out_dir/${artifact_id}.jar",
946+
]
947+
sources = base_sources + hash_sources
848948
outputs = []
849949
args = []
850950
base_name = "$root_out_dir/zip_archives/download.flutter.io/io/flutter/" +
851951
"${artifact_id}/1.0.0-$engine_version/" +
852952
"${artifact_id}-1.0.0-${engine_version}"
853-
foreach(source, sources) {
953+
foreach(source, base_sources) {
854954
extension = get_path_info(source, "extension")
855955
name = get_path_info(source, "name")
856956
outputs += [ "${base_name}.${extension}" ]
@@ -860,4 +960,23 @@ action("abi_jars") {
860960
rebase_path("${base_name}.${extension}"),
861961
]
862962
}
963+
964+
# NOTE(codefu): the URL having /*-$engine_version/ is expected; we want these
965+
# files in one URL. The flutter-recipes duplicate them to content_hash as
966+
# part of its upload step.
967+
# More info here: https://github.com/flutter/flutter/issues/172259
968+
hash_base_name =
969+
"$root_out_dir/zip_archives/download.flutter.io/io/flutter/" +
970+
"${artifact_id}/1.0.0-$engine_version/" +
971+
"${artifact_id}-1.0.0-${content_hash}"
972+
foreach(source, hash_sources) {
973+
extension = get_path_info(source, "extension")
974+
name = get_path_info(source, "name")
975+
outputs += [ "${hash_base_name}.${extension}" ]
976+
args += [
977+
"-i",
978+
rebase_path(source),
979+
rebase_path("${hash_base_name}.${extension}"),
980+
]
981+
}
863982
}

engine/src/flutter/shell/version/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ source_set("version") {
1212

1313
defines = [
1414
"FLUTTER_ENGINE_VERSION=\"$engine_version\"",
15+
"FLUTTER_CONTENT_HASH=\"$content_hash\"",
1516
"SKIA_VERSION=\"$skia_version\"",
1617
"DART_VERSION=\"$dart_version\"",
1718
]

engine/src/flutter/shell/version/version.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const char* GetFlutterEngineVersion() {
1212
return FLUTTER_ENGINE_VERSION;
1313
}
1414

15+
const char* GetFlutterContentHash() {
16+
return FLUTTER_CONTENT_HASH;
17+
}
18+
1519
const char* GetSkiaVersion() {
1620
return SKIA_VERSION;
1721
}

engine/src/flutter/shell/version/version.gni

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import("//flutter/build/dart/dart.gni")
77
declare_args() {
88
engine_version = ""
99

10+
content_hash = ""
11+
1012
skia_version = ""
1113

1214
dart_version = ""
@@ -15,5 +17,6 @@ declare_args() {
1517
_flutter_root = "//flutter"
1618

1719
assert(engine_version != "", "The engine_version argument must be supplied")
20+
assert(content_hash != "", "The content_hash argument must be supplied")
1821
assert(skia_version != "", "The skia_version argument must be supplied")
1922
assert(dart_version != "", "The dart_version argument must be supplied")

engine/src/flutter/shell/version/version.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace flutter {
99

1010
const char* GetFlutterEngineVersion();
1111

12+
const char* GetFlutterContentHash();
13+
1214
const char* GetSkiaVersion();
1315

1416
const char* GetDartVersion();

engine/src/flutter/tools/gn

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,31 @@ def get_repository_version(repository):
328328
return str(version.strip(), 'utf-8')
329329

330330

331+
def get_content_hash():
332+
'Returns the content hash for the engine.'
333+
hash_method = os.path.join(SRC_ROOT, '..', '..', 'bin', 'internal', 'content_aware_hash')
334+
if sys.platform.startswith(('cygwin', 'win')):
335+
hash_method = f'{hash_method}.ps1'
336+
# hash_command.insert(0, 'cmd.exe /c powershell.exe')
337+
else:
338+
hash_method = f'{hash_method}.sh'
339+
340+
hash_command = []
341+
if sys.platform.startswith(('cygwin', 'win')):
342+
hash_command = hash_command + ['cmd.exe', '/c', 'powershell.exe']
343+
hash_command = hash_command + [hash_method]
344+
345+
version = subprocess.check_output(hash_command)
346+
347+
return str(version.strip(), 'utf-8')
348+
349+
331350
def setup_git_versions():
332351
revision_args = {}
333352

334353
engine_path = os.path.join(SRC_ROOT, 'flutter')
335354
revision_args['engine_version'] = get_repository_version(engine_path)
336-
355+
revision_args['content_hash'] = get_content_hash()
337356
skia_path = os.path.join(SRC_ROOT, 'flutter', 'third_party', 'skia')
338357
revision_args['skia_version'] = get_repository_version(skia_path)
339358

0 commit comments

Comments
 (0)