Skip to content

Commit

Permalink
Fix reproducible builds by sorting baseline.profm
Browse files Browse the repository at this point in the history
  • Loading branch information
valldrac committed Mar 24, 2023
1 parent de3ae8f commit d207ad5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ plugins {
id 'translations'
}

// Sort baseline.profm for reproducible builds
// See issue: https://issuetracker.google.com/issues/231837768
apply from: 'fix-profm.gradle'

protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.18.0'
Expand Down
38 changes: 38 additions & 0 deletions app/fix-profm.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import com.android.tools.profgen.ArtProfileKt
import com.android.tools.profgen.ArtProfileSerializer
import com.android.tools.profgen.DexFile

buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
}
}

project.afterEvaluate {
tasks.each { task ->
if (task.name.startsWith("compile") && task.name.endsWith("ReleaseArtProfile")) {
task.doLast {
outputs.files.each { file ->
if (file.name.endsWith(".profm")) {
println("Sorting ${file} ...")
def version = ArtProfileSerializer.valueOf("METADATA_0_0_2")
def profile = ArtProfileKt.ArtProfile(file)
def keys = new ArrayList(profile.profileData.keySet())
def sortedData = new LinkedHashMap()
Collections.sort keys, new DexFile.Companion()
keys.each { key -> sortedData[key] = profile.profileData[key] }
new FileOutputStream(file).with {
write(version.magicBytes$profgen)
write(version.versionBytes$profgen)
version.write$profgen(it, sortedData, "")
}
}
}
}
}
}
}

0 comments on commit d207ad5

Please sign in to comment.