Skip to content

Commit 31b7244

Browse files
authored
Merge pull request #182 from gradle/no/mergesourcesetfolders
Disable caching of MergeSourceSetFolders
2 parents ef4601f + 09b48ce commit 31b7244

File tree

5 files changed

+48
-20
lines changed

5 files changed

+48
-20
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,6 @@ room {
125125
* There can only be a single schema export directory for the project - you cannot configure variant-specific export
126126
directories. Schemas exported from different variants will be merged in the directory specified in the "room" extension.
127127

128-
### MergeNativeLibsWorkaround, StripDebugSymbols, MergeJavaResources
128+
### MergeNativeLibs, StripDebugSymbols, MergeJavaResources, and MergeSourceSetFolders Workarounds
129129

130-
It has been observed that caching the `MergeNativeLibsTask`, `StripDebugSymbols`, and `MergeJavaResources` tasks rarely provide any significant positive avoidance savings. In fact, they frequently provide negative savings, especially when fetched from a remote cache node. As such, these workarounds actually disable caching for these tasks.
130+
It has been observed that caching the `MergeNativeLibsTask`, `StripDebugSymbols`, `MergeJavaResources`, and `MergeSourceSetFolders` tasks rarely provide any significant positive avoidance savings. In fact, they frequently provide negative savings, especially when fetched from a remote cache node. As such, these workarounds actually disable caching for these tasks.

Diff for: src/main/groovy/org/gradle/android/AndroidCacheFixPlugin.groovy

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.gradle.android.workarounds.MergeJavaResourcesWorkaround
99
import org.gradle.android.workarounds.MergeNativeLibsWorkaround
1010
import org.gradle.android.workarounds.MergeResourcesWorkaround
1111
import org.gradle.android.workarounds.CompileLibraryResourcesWorkaround_4_2
12+
import org.gradle.android.workarounds.MergeSourceSetFoldersWorkaround
1213
import org.gradle.android.workarounds.StripDebugSymbolsWorkaround
1314
import org.gradle.android.workarounds.SystemPropertiesCompat
1415
import org.gradle.android.workarounds.RoomSchemaLocationWorkaround
@@ -48,6 +49,7 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
4849
return Arrays.<Workaround>asList(
4950
new MergeJavaResourcesWorkaround(),
5051
new MergeNativeLibsWorkaround(),
52+
new MergeSourceSetFoldersWorkaround(),
5153
new RoomSchemaLocationWorkaround(),
5254
new CompileLibraryResourcesWorkaround_4_0(),
5355
new CompileLibraryResourcesWorkaround_4_2(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.gradle.android.workarounds
2+
3+
import com.android.build.gradle.tasks.MergeSourceSetFolders
4+
import org.gradle.android.AndroidIssue
5+
import org.gradle.api.Project
6+
7+
/**
8+
* Disables caching of the MergeSourceSetFolders task which is mostly disk bound and unlikely to provide positive
9+
* performance benefits.
10+
*/
11+
@AndroidIssue(introducedIn = "3.5.0", fixedIn = [], link = "https://issuetracker.google.com/issues/194804421")
12+
class MergeSourceSetFoldersWorkaround implements Workaround {
13+
private static final String CACHING_ENABLED_PROPERTY = "org.gradle.android.cache-fix.MergeSourceSetFolders.caching.enabled"
14+
15+
@Override
16+
void apply(WorkaroundContext context) {
17+
context.project.tasks.withType(MergeSourceSetFolders).configureEach {
18+
outputs.doNotCacheIf("Caching MergeSourceSetFolders is unlikely to provide positive performance results.", {true })
19+
}
20+
}
21+
22+
@Override
23+
boolean canBeApplied(Project project) {
24+
return !SystemPropertiesCompat.getBoolean(CACHING_ENABLED_PROPERTY, project)
25+
}
26+
}

Diff for: src/test/groovy/org/gradle/android/CrossVersionOutcomeAndRelocationTest.groovy

+12-12
Original file line numberDiff line numberDiff line change
@@ -265,19 +265,19 @@ class CrossVersionOutcomeAndRelocationTest extends AbstractTest {
265265
builder.expect(':app:kaptDebugKotlin', FROM_CACHE)
266266
builder.expect(':app:kaptGenerateStubsReleaseKotlin', FROM_CACHE)
267267
builder.expect(':app:kaptReleaseKotlin', FROM_CACHE)
268-
builder.expect(':app:mergeDebugAssets', FROM_CACHE)
268+
builder.expect(':app:mergeDebugAssets', SUCCESS)
269269
builder.expect(':app:mergeDebugJavaResource', SUCCESS)
270-
builder.expect(':app:mergeDebugJniLibFolders', FROM_CACHE)
271-
builder.expect(':app:mergeDebugShaders', FROM_CACHE)
270+
builder.expect(':app:mergeDebugJniLibFolders', SUCCESS)
271+
builder.expect(':app:mergeDebugShaders', SUCCESS)
272272
builder.expect(':app:mergeDexRelease', FROM_CACHE)
273273
builder.expect(':app:mergeExtDexDebug', FROM_CACHE)
274274
builder.expect(':app:mergeExtDexRelease', FROM_CACHE)
275275
builder.expect(':app:mergeLibDexDebug', FROM_CACHE)
276276
builder.expect(':app:mergeProjectDexDebug', FROM_CACHE)
277-
builder.expect(':app:mergeReleaseAssets', FROM_CACHE)
277+
builder.expect(':app:mergeReleaseAssets', SUCCESS)
278278
builder.expect(':app:mergeReleaseJavaResource', SUCCESS)
279-
builder.expect(':app:mergeReleaseJniLibFolders', FROM_CACHE)
280-
builder.expect(':app:mergeReleaseShaders', FROM_CACHE)
279+
builder.expect(':app:mergeReleaseJniLibFolders', SUCCESS)
280+
builder.expect(':app:mergeReleaseShaders', SUCCESS)
281281
builder.expect(':app:mergeRoomSchemaLocations', SUCCESS)
282282
builder.expect(':app:packageDebug', SUCCESS)
283283
builder.expect(':app:packageRelease', SUCCESS)
@@ -325,16 +325,16 @@ class CrossVersionOutcomeAndRelocationTest extends AbstractTest {
325325
builder.expect(':library:kaptGenerateStubsReleaseKotlin', FROM_CACHE)
326326
builder.expect(':library:kaptReleaseKotlin', FROM_CACHE)
327327
builder.expect(':library:mergeDebugJavaResource', SUCCESS)
328-
builder.expect(':library:mergeDebugJniLibFolders', FROM_CACHE)
329-
builder.expect(':library:mergeDebugShaders', FROM_CACHE)
328+
builder.expect(':library:mergeDebugJniLibFolders', SUCCESS)
329+
builder.expect(':library:mergeDebugShaders', SUCCESS)
330330
builder.expect(':library:mergeReleaseJavaResource', SUCCESS)
331-
builder.expect(':library:mergeReleaseJniLibFolders', FROM_CACHE)
331+
builder.expect(':library:mergeReleaseJniLibFolders', SUCCESS)
332332
builder.expect(':library:mergeReleaseResources', FROM_CACHE)
333-
builder.expect(':library:mergeReleaseShaders', FROM_CACHE)
334-
builder.expect(':library:packageDebugAssets', FROM_CACHE)
333+
builder.expect(':library:mergeReleaseShaders', SUCCESS)
334+
builder.expect(':library:packageDebugAssets', SUCCESS)
335335
builder.expect(':library:packageDebugRenderscript', NO_SOURCE)
336336
builder.expect(':library:packageDebugResources', FROM_CACHE)
337-
builder.expect(':library:packageReleaseAssets', FROM_CACHE)
337+
builder.expect(':library:packageReleaseAssets', SUCCESS)
338338
builder.expect(':library:packageReleaseRenderscript', NO_SOURCE)
339339
builder.expect(':library:packageReleaseResources', FROM_CACHE)
340340
builder.expect(':library:mergeRoomSchemaLocations', SUCCESS)

Diff for: src/test/groovy/org/gradle/android/WorkaroundTest.groovy

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ class WorkaroundTest extends Specification {
1212
workarounds.collect { it.class.simpleName.replaceAll(/Workaround/, "") }.sort() == expectedWorkarounds.sort()
1313
where:
1414
androidVersion | expectedWorkarounds
15-
"7.0.0" | ['MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_7_0']
16-
"4.2.2" | ['MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_2', 'MergeResources']
17-
"4.1.3" | ['MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_0', 'MergeResources']
18-
"4.0.2" | ['MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_0', 'MergeResources']
19-
"3.6.4" | ['MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs']
20-
"3.5.4" | ['MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs']
15+
"7.0.0" | ['MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_7_0']
16+
"4.2.2" | ['MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_2', 'MergeResources']
17+
"4.1.3" | ['MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_0', 'MergeResources']
18+
"4.0.2" | ['MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_0', 'MergeResources']
19+
"3.6.4" | ['MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs']
20+
"3.5.4" | ['MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs']
2121
}
2222
}

0 commit comments

Comments
 (0)