Skip to content

Commit 52c3566

Browse files
Googlercopybara-github
authored andcommitted
BEGIN_PUBLIC
Expand baseline profile wildcards before optimizer tools see the profiles. END_PUBLIC This addresses what is described here: b/295087579 In particular, the human-readable format for baseline profiles can contain wildcards (eg. "LSomeClass*"). Profgen can expand these, and thus AppReduce does not have to process them. Note: This does not expand anything provided by the `startup_profiles` attribute. The assumption is this isn't necessary as these would be generated by a device, and thus shouldn't have wildcards. Expanding wildcards here could arguably be an unnecessary cost for build performance. Currently, if AppReduce encounters wildcards, it will just ignore them. RELNOTES: Expands baseline profile wildcards before optimizer tools see them. PiperOrigin-RevId: 556095126 Change-Id: Ie6cb65ebbf0131da098504fe0d27ade0b967ae57
1 parent 2c8f6bb commit 52c3566

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidSemantics.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,14 @@ public Artifact mergeBaselineProfiles(
145145
public Artifact mergeStartupProfiles(RuleContext ruleContext, String baselineProfileDir) {
146146
return null;
147147
}
148+
149+
/* Bazel does not currently support baseline profiles in the final apk. */
150+
@Override
151+
public Artifact expandBaselineProfileWildcards(
152+
RuleContext ruleContext,
153+
Artifact deployJar,
154+
Artifact mergedStaticProfile,
155+
String baselineProfileDir) {
156+
return null;
157+
}
148158
}

src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,17 +545,24 @@ public static RuleConfiguredTargetBuilder createAndroidBinary(
545545
if (baselineprofileProvider == null
546546
&& Allowlist.hasAllowlist(ruleContext, "allow_baseline_profiles_optimizer_integration")
547547
&& Allowlist.isAvailable(ruleContext, "allow_baseline_profiles_optimizer_integration")) {
548-
if (!proguardSpecs.isEmpty()) {
549-
// This is only needed for optimized builds since otherwise the dexer doesn't process this.
550-
startupProfile = androidSemantics.mergeStartupProfiles(ruleContext, baselineProfileDir);
551-
}
552548
baselineProfile =
553549
androidSemantics.mergeBaselineProfiles(
554550
ruleContext,
555551
baselineProfileDir,
556552
// Include startup profiles if the optimizer is disabled since profiles won't be
557553
// merged in the optimizer.
558554
proguardSpecs.isEmpty());
555+
if (!proguardSpecs.isEmpty()) {
556+
// This is only needed for optimized builds since otherwise the dexer doesn't process this.
557+
startupProfile = androidSemantics.mergeStartupProfiles(ruleContext, baselineProfileDir);
558+
// Wildcards only need to be expanded for optimized builds since if these aren't consumed by
559+
// the optimizer, they can just be expanded during profile compilation instead.
560+
// Start-up profiles are not expanded because it shouldn't be necessary as these should
561+
// contain profiles generated by devices on start-up.
562+
baselineProfile =
563+
androidSemantics.expandBaselineProfileWildcards(
564+
ruleContext, binaryJar, baselineProfile, baselineProfileDir);
565+
}
559566
}
560567
ProguardOutput proguardOutput =
561568
applyProguard(

src/main/java/com/google/devtools/build/lib/rules/android/AndroidSemantics.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ Artifact mergeBaselineProfiles(
118118
/** The merged startup profiles from the {@code startup_profiles} attribute. */
119119
Artifact mergeStartupProfiles(RuleContext ruleContext, String baselineProfileDir);
120120

121+
/** Expands any wildcards present in a baseline profile, and returns the new expanded artifact. */
122+
public Artifact expandBaselineProfileWildcards(
123+
RuleContext ruleContext,
124+
Artifact deployJar,
125+
Artifact mergedStaticProfile,
126+
String baselineProfileDir);
127+
121128
/** The artifact for ART profile information, given a particular merged profile. */
122129
Artifact compileBaselineProfile(
123130
RuleContext ruleContext,

0 commit comments

Comments
 (0)