Skip to content

Commit a9d529f

Browse files
A Googlercopybara-github
authored andcommitted
This CL attempts to fix the runtime error that happens when:
- You have an AAB is built with android_applicaiton - Sideload the AAB using bundletool - Invoke jetpack baseline profile installer through ADB adb shell am broadcast -a androidx.profileinstaller.action.INSTALL_PROFILE \ com.google.android.GoogleCamera/androidx.profileinstaller.ProfileInstallReceiver The installer fails with the erro like: 10-30 22:45:18.716 447 447 D ProfileInstaller: DIAGNOSTIC_PROFILE_IS_COMPRESSED This is because the baseline profilie in the AAB is not placed in the location which bundletool expects Note that Gradle supports this location: PiperOrigin-RevId: 831564698 Change-Id: I53d49f4e67851fc41fc57451f9d19962df4cb109
1 parent fa47c0d commit a9d529f

4 files changed

Lines changed: 28 additions & 5 deletions

File tree

providers/providers.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,16 @@ BaselineProfileProvider = provider(
282282
),
283283
)
284284

285+
# buildifier: disable=name-conventions
286+
ArtProfileInfo = provider(
287+
doc = "ArtProfileInfo",
288+
fields = dict(
289+
art_profile_zip = "Zip file containing the baseline profile and metadata, intended to be merged into APK.",
290+
baseline_profile = "Generated baseline.prof file",
291+
baseline_profile_metadata = "Generated baseline.profm file",
292+
),
293+
)
294+
285295
# buildifier: disable=name-conventions
286296
AndroidLibraryResourceClassJarProvider = provider(
287297
doc = "AndroidLibraryResourceClassJarProvider",

rules/android_application/android_application_rule.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ load(
2222
"AndroidPreDexJarInfo",
2323
"AndroidSandboxedSdkBundleInfo",
2424
"ApkInfo",
25+
"ArtProfileInfo",
2526
"ProguardMappingInfo",
2627
"StarlarkAndroidResourcesInfo",
2728
)
@@ -368,6 +369,11 @@ def _impl(ctx):
368369
if ctx.file.app_integrity_config:
369370
metadata["com.google.play.apps.integrity/AppIntegrityConfig.pb"] = ctx.file.app_integrity_config
370371

372+
if ArtProfileInfo in ctx.attr.base_module:
373+
base_art_profile_info = ctx.attr.base_module[ArtProfileInfo]
374+
metadata["com.android.tools.build.profiles/baseline.prof"] = base_art_profile_info.baseline_profile
375+
metadata["com.android.tools.build.profiles/baseline.profm"] = base_art_profile_info.baseline_profile_metadata
376+
371377
# Create .aab
372378
_bundletool.build(
373379
ctx,

rules/android_binary/impl.bzl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ def _process_baseline_profiles(ctx, validation_ctx, deploy_ctx, **_unused_ctxs):
708708

709709
def _process_art_profile(ctx, validation_ctx, bp_ctx, dex_ctx, optimize_ctx, **_unused_ctxs):
710710
providers = []
711-
art_profile_zip = None
711+
art_profile_info = None
712712
if ctx.attr.generate_art_profile and not validation_ctx.use_r8:
713713
merged_baseline_profile = bp_ctx.baseline_profile_output.baseline_profile
714714
merged_baseline_profile_rewritten = \
@@ -726,18 +726,20 @@ def _process_art_profile(ctx, validation_ctx, bp_ctx, dex_ctx, optimize_ctx, **_
726726
if merged_baseline_profile_rewritten:
727727
merged_baseline_profile = merged_baseline_profile_rewritten
728728
if merged_baseline_profile:
729-
art_profile_zip = _baseline_profiles.process_art_profile(
729+
art_profile_info = _baseline_profiles.process_art_profile(
730730
ctx,
731731
final_classes_dex = dex_ctx.dex_info.final_classes_dex_zip,
732732
merged_profile = merged_baseline_profile,
733733
proguard_output_map = proguard_output_map,
734734
profgen = get_android_toolchain(ctx).profgen.files_to_run,
735735
toolchain_type = ANDROID_TOOLCHAIN_TYPE,
736736
)
737+
providers.append(art_profile_info)
738+
737739
return ProviderInfo(
738740
name = "ap_ctx",
739741
value = struct(
740-
art_profile_zip = art_profile_zip,
742+
art_profile_zip = art_profile_info.art_profile_zip if art_profile_info else None,
741743
providers = providers,
742744
),
743745
)

rules/baseline_profiles.bzl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Defines baseline profiles processing methods in Android Rules.
1616
"""
1717

18+
load("//providers:providers.bzl", "ArtProfileInfo")
1819
load("//rules:common.bzl", _common = "common")
1920
load("//rules:java.bzl", _java = "java")
2021
load("//rules:visibility.bzl", "PROJECT_VISIBILITY")
@@ -120,7 +121,7 @@ def _process_art_profile(
120121
profgen: FilesToRunProvider. The profgen executable for profile compilation.
121122
toolchain_type: Label or String. Toolchain type of the executable used in actions.
122123
Returns:
123-
Provider info containing BaselineProfileProvider for all merged profiles.
124+
ArtProfileInfo containing the generated profile, the metadata, and the combined zip file.
124125
"""
125126

126127
# Profgen
@@ -160,7 +161,11 @@ def _process_art_profile(
160161
resources = [output_profile, output_profile_meta],
161162
java_toolchain = _common.get_java_toolchain(ctx),
162163
)
163-
return output_profile_zip
164+
return ArtProfileInfo(
165+
art_profile_zip = output_profile_zip,
166+
baseline_profile = output_profile,
167+
baseline_profile_metadata = output_profile_meta,
168+
)
164169

165170
def _get_profile_dir(ctx):
166171
return ctx.label.name + _BASELINE_PROFILE_DIR_SUFFIX

0 commit comments

Comments
 (0)