Deferred files causing stochastic build failures
- Dominant language
- Kotlin
- Stars
- 42
- Forks
- 17
- PR merge metrics
- No merged PRs in 30d
Description
We have a project with 317 layout `.xml` files (maybe the large number is relevant).
In CI and occasionally locally, the build fails because the generated stubs source jar for layout bindings has an empty file at the root instead of the valid generate file.
For example:
```
unzip -l bazel-bin/path/to/app/lib_dev-stubs_binding.srcjar | grep FragmentFoo
0 1980-02-01 00:00 FragmentFooBinding.java
1715 1980-02-01 00:00 com/ourcompany/databinding/FragmentFoo2Binding.java
```
In the above example, you'll see that `FragmentFoo2Binding.java` is in the correct spot and has a valid size. But `FragmentFooBinding.java` is empty and isn't at the proper path.
If I set `verbose=true` for the `SourceJarCreator`, I'll see that we're hitting this line: https://github.com/grab/grab-bazel-common/blob/987bb4ef56aa331ca0b3c10233baef99def7b7b3/tools/db-compiler-lite/src/main/java/com/grab/databinding/stub/util/jars/SourceJarCreator.kt#L163
for `FragmentFooBinding`. And the body will be empty.
One workaround I see is to re-read the file when visiting deferred files.
For example:
```kotlin
filenameHelper.visitDeferredEntries { path, jarFilename, bytes ->
if (jarFilename == null) {
val newBytes = Files.readAllBytes(path) // ADDED THIS
if (verbose) {
val body = newBytes.toString(Charset.defaultCharset())
System.err.println("""could not determine jar entry name for $path. Body:\n$body}""")
addEntry(path.fileName.toString(), path, newBytes)
} else {
// if not verbose silently add files at the root.
addEntry(path.fileName.toString(), path, newBytes)
}
} else {
System.err.println("adding deferred source file $path -> $jarFilename")
addEntry(jarFilename, path, bytes)
}
}
```
Perhaps something about bazel causes this file not to be available yet in the first go around? If it's not the sheer number of layout files, maybe it is something in my `.bazelrc`?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in tools/db-compiler-lite/src/main/java/com/grab/databinding/stub/util/jars/SourceJarCreator.kt around line 163, especially the filenameHelper.visitDeferredEntries callback. Reproduce the generated stubs source jar issue and inspect the deferred file bytes and entry paths, using the reported verbose output as a guide. Done means deferred layout binding files are nonempty and placed at their correct jar paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100