Skip to content

Commit 647d6ce

Browse files
author
Thomas Bao
committed
print out digests to download from CAS
1 parent 14199fc commit 647d6ce

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
11
# execlog-parser
2+
3+
## Build
4+
5+
`bazel build //:ExecLogParser --incompatible_java_common_parameters=false`
6+
7+
Note you may or may not need `--incompatible_java_common_parameters=false`
8+
9+
## Run
10+
11+
After building:
12+
13+
`bazel-bin/ExecLogDiffer <exec log filepath #1> <exec log filepath #2>`

src/main/java/com/airbnb/execlog_parser/ExecLogParser.kt

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.airbnb.execlog_parser
22

33
import com.google.devtools.build.lib.exec.Protos.SpawnExec
4+
import com.google.devtools.build.lib.exec.Protos.Digest
45
import java.io.File
56
import java.io.FileInputStream
67
import java.io.IOException
@@ -20,21 +21,22 @@ object ExecLogParser {
2021
}
2122

2223
@Throws(IOException::class)
23-
fun getFileHashes(logPath: String): Map<String,String> {
24+
fun getFileDigests(logPath: String): Map<String, Digest> {
2425
inputStream = FileInputStream(logPath)
25-
val fileHashMap = mutableMapOf<String, String>()
26+
val fileHashMap = mutableMapOf<String, Digest>()
2627
var spawnExec = getNext()
2728
while (spawnExec != null) {
2829
spawnExec.inputsList.union(spawnExec.actualOutputsList).forEach { fileProto ->
29-
val hash = fileProto.digest.hash
30+
val digest = fileProto.digest
31+
val hash = digest.hash
3032
val path = fileProto.path
31-
if (fileHashMap.get(path) != null && fileHashMap.get(path) != hash) {
33+
if (fileHashMap.get(path) != null && fileHashMap.get(path)!!.hash != hash) {
3234
throw Exception(
3335
"File hash changed during bazel build. Something is seriously wrong!\n" +
3436
"$path has at least two different hashes: ${fileHashMap[path]} $hash\n"
3537
)
3638
}
37-
fileHashMap[path] = hash
39+
fileHashMap[path] = digest
3840
}
3941
spawnExec = getNext()
4042
}
@@ -54,8 +56,8 @@ object ExecLogParser {
5456
if (allowListPath != null) {
5557
allowList = File(allowListPath).readLines().map { it.trim() }.toSet()
5658
}
57-
val fileHashMap1 = getFileHashes(logPath1)
58-
val fileHashMap2 = getFileHashes(logPath2)
59+
val fileHashMap1 = getFileDigests(logPath1)
60+
val fileHashMap2 = getFileDigests(logPath2)
5961
if (fileHashMap1.keys != fileHashMap2.keys) {
6062
throw Exception(
6163
"Execution logs have different sets of inputs and outputs!\n" +
@@ -64,22 +66,22 @@ object ExecLogParser {
6466
"The second log has these additional inputs/output files: ${fileHashMap2.keys.subtract(fileHashMap1.keys)}\n"
6567
)
6668
}
67-
val inputHashDiffs = mutableMapOf<String, Pair<String, String>>()
69+
val inputDigestDiffs = mutableMapOf<String, Pair<Digest, Digest>>()
6870
fileHashMap1.keys.forEach { path ->
69-
if (fileHashMap1[path] != fileHashMap2[path]) {
71+
if (fileHashMap1[path]!!.hash != fileHashMap2[path]!!.hash) {
7072
if (allowList.any {
7173
path.endsWith(it)
7274
}) {
7375
return@forEach
7476
}
75-
inputHashDiffs[path] = Pair(fileHashMap1[path]!!, fileHashMap2[path]!!)
77+
inputDigestDiffs[path] = Pair(fileHashMap1[path]!!, fileHashMap2[path]!!)
7678
}
7779
}
78-
if (inputHashDiffs.isNotEmpty()) {
80+
if (inputDigestDiffs.isNotEmpty()) {
7981
println("Execution logs have unexpected hash diffs, indicating the build is not deterministic")
8082
println("Consider adding the path to the allowlist if its impact is small. Otherwise, please fix")
81-
println("input hash diffs:")
82-
inputHashDiffs.forEach {
83+
println("input file digests:")
84+
inputDigestDiffs.forEach {
8385
println("${it.key}: ${it.value.first} ${it.value.second}")
8486
}
8587
throw Exception("Execution logs have different hashes for the same input")

0 commit comments

Comments
 (0)