Skip to content

Commit 1693d40

Browse files
committed
Disable resource conflict warnings
1 parent d1b330c commit 1693d40

6 files changed

Lines changed: 57 additions & 10 deletions

File tree

src/tools/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ public static final class Options {
251251
splitter = ColonSplitter.class,
252252
description = "List of reource only APK files to link against.")
253253
public List<Path> resourceApks = ImmutableList.of();
254+
255+
@Parameter(
256+
names = "--logWarningOnResourceConflict",
257+
arity = 1,
258+
description =
259+
"If passed, resource merge conflicts will be treated as errors instead of warnings")
260+
public boolean logWarningOnResourceConflict;
254261
}
255262

256263
public static void main(String[] args) throws Exception {
@@ -340,6 +347,7 @@ public static void main(String[] args) throws Exception {
340347
symbols,
341348
dataDeserializer,
342349
options.throwOnResourceConflict,
350+
options.logWarningOnResourceConflict,
343351
executorService);
344352
if (options.symbolsOut != null) {
345353
Files.copy(symbolsBin, options.symbolsOut);

src/tools/java/com/google/devtools/build/android/AarGeneratorAction.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ public static final class AarGeneratorOptions {
128128
description =
129129
"If passed, resource merge conflicts will be treated as errors instead of warnings")
130130
public boolean throwOnResourceConflict;
131+
132+
@Parameter(
133+
names = "--logWarningOnResourceConflict",
134+
arity = 1,
135+
description =
136+
"If passed, resource merge conflicts will be treated as errors instead of warnings")
137+
public boolean logWarningOnResourceConflict;
131138
}
132139

133140
public static void main(String[] args) throws ParameterException, IOException {
@@ -162,7 +169,8 @@ public static void main(String[] args) throws ParameterException, IOException {
162169
VariantTypeImpl.LIBRARY,
163170
null,
164171
/* filteredResources= */ ImmutableList.<String>of(),
165-
options.throwOnResourceConflict);
172+
options.throwOnResourceConflict,
173+
options.logWarningOnResourceConflict);
166174
logger.fine(String.format("Merging finished at %dms", timer.elapsed(TimeUnit.MILLISECONDS)));
167175

168176
writeAar(

src/tools/java/com/google/devtools/build/android/AndroidAssetMergingAction.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ public static final class Options {
9898
description =
9999
"If passed, asset merge conflicts will be treated as errors instead of warnings")
100100
public boolean throwOnAssetConflict = true;
101+
102+
@Parameter(
103+
names = "--logWarningOnResourceConflict",
104+
arity = 1,
105+
description =
106+
"If passed, asset merge conflicts will be treated as errors instead of warnings")
107+
public boolean logWarningOnResourceConflict;
101108
}
102109

103110
@Override
@@ -124,6 +131,7 @@ void run(Path tmp, ExecutorServiceCloser executorService) throws Exception {
124131
/* allowPrimaryOverrideAll = */ false,
125132
deserializer,
126133
options.throwOnAssetConflict,
134+
options.logWarningOnResourceConflict,
127135
ContentComparingChecker.create());
128136

129137
logCompletion("Merging");

src/tools/java/com/google/devtools/build/android/AndroidCompiledResourceMergingAction.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ public static class Options {
139139
description =
140140
"Path to where an R.txt file declaring potentially-used resources should be written.")
141141
public Path rTxtOut;
142+
143+
@Parameter(
144+
names = "--logWarningOnResourceConflict",
145+
arity = 1,
146+
description =
147+
"If passed, resource merge conflicts will be treated as errors instead of warnings")
148+
public boolean logWarningOnResourceConflict;
142149
}
143150

144151
public static void main(String[] args) throws Exception {
@@ -197,6 +204,7 @@ public static void main(String[] args) throws Exception {
197204
resourceClassWriter,
198205
rTxtWriter,
199206
options.throwOnResourceConflict,
207+
options.logWarningOnResourceConflict,
200208
executorService);
201209
logger.fine(String.format("Merging finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
202210

src/tools/java/com/google/devtools/build/android/AndroidDataMerger.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ UnwrittenMergedAndroidData loadAndMerge(
155155
ParsedAndroidData primary,
156156
Path primaryManifest,
157157
boolean allowPrimaryOverrideAll,
158-
boolean throwOnResourceConflict) {
158+
boolean throwOnResourceConflict,
159+
boolean logWarningOnResourceConflict) {
159160
Stopwatch timer = Stopwatch.createStarted();
160161
try {
161162
logger.fine(
@@ -169,7 +170,8 @@ UnwrittenMergedAndroidData loadAndMerge(
169170
primary,
170171
primaryManifest,
171172
allowPrimaryOverrideAll,
172-
throwOnResourceConflict);
173+
throwOnResourceConflict,
174+
logWarningOnResourceConflict);
173175
} finally {
174176
logger.fine(String.format("Resources merged in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
175177
}
@@ -245,7 +247,8 @@ UnwrittenMergedAndroidData merge(
245247
ParsedAndroidData direct,
246248
UnvalidatedAndroidData primaryData,
247249
boolean allowPrimaryOverrideAll,
248-
boolean throwOnResourceConflict) {
250+
boolean throwOnResourceConflict,
251+
boolean logWarningOnResourceConflict) {
249252
try {
250253
// Extract the primary resources.
251254
ParsedAndroidData parsedPrimary = ParsedAndroidData.from(primaryData);
@@ -255,7 +258,8 @@ UnwrittenMergedAndroidData merge(
255258
parsedPrimary,
256259
primaryData.getManifest(),
257260
allowPrimaryOverrideAll,
258-
throwOnResourceConflict);
261+
throwOnResourceConflict,
262+
logWarningOnResourceConflict);
259263
} catch (IOException e) {
260264
throw MergingException.wrapException(e);
261265
}
@@ -267,7 +271,8 @@ UnwrittenMergedAndroidData doMerge(
267271
ParsedAndroidData parsedPrimary,
268272
Path primaryManifest,
269273
boolean allowPrimaryOverrideAll,
270-
boolean throwOnResourceConflict) {
274+
boolean throwOnResourceConflict,
275+
boolean logWarningOnResourceConflict) {
271276

272277
// Create the builders for the final parsed data.
273278
final ParsedAndroidData.Builder primaryBuilder = ParsedAndroidData.Builder.newBuilder();
@@ -392,7 +397,9 @@ UnwrittenMergedAndroidData doMerge(
392397
if (throwOnResourceConflict) {
393398
throw MergeConflictException.withMessage(Joiner.on("\n").join(messages));
394399
} else {
395-
logger.warning(Joiner.on("\n").join(messages));
400+
if (logWarningOnResourceConflict) {
401+
logger.warning(Joiner.on("\n").join(messages));
402+
}
396403
}
397404
}
398405
} catch (IOException e) {

src/tools/java/com/google/devtools/build/android/AndroidResourceMerger.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static Path mergeDataToSymbols(
4141
Path symbolsOut,
4242
AndroidCompiledDataDeserializer deserializer,
4343
boolean throwOnResourceConflict,
44+
boolean logWarningOnResourceConflict,
4445
ExecutorServiceCloser executorService)
4546
throws IOException {
4647
AndroidDataMerger merger =
@@ -53,7 +54,8 @@ static Path mergeDataToSymbols(
5354
primary,
5455
manifest,
5556
packageType.equals(VariantTypeImpl.BASE_APK),
56-
throwOnResourceConflict);
57+
throwOnResourceConflict,
58+
logWarningOnResourceConflict);
5759
AndroidDataSerializer serializer = AndroidDataSerializer.create();
5860
merged.serializeTo(serializer);
5961
serializer.flushTo(symbolsOut);
@@ -96,7 +98,8 @@ public static MergedAndroidData mergeDataAndWrite(
9698
final VariantTypeImpl type,
9799
@Nullable final Path symbolsOut,
98100
final List<String> filteredResources,
99-
boolean throwOnResourceConflict) {
101+
boolean throwOnResourceConflict,
102+
boolean logWarningOnResourceConflict) {
100103
try (ExecutorServiceCloser executorService = ExecutorServiceCloser.createWithFixedPoolOf(15)) {
101104
final ParsedAndroidData parsedPrimary = ParsedAndroidData.from(primary);
102105
return writeMergedData(
@@ -114,6 +117,7 @@ public static MergedAndroidData mergeDataAndWrite(
114117
type != VariantTypeImpl.LIBRARY,
115118
AndroidParsedDataDeserializer.withFilteredResources(filteredResources),
116119
throwOnResourceConflict,
120+
logWarningOnResourceConflict,
117121
ContentComparingChecker.create()));
118122
} catch (IOException e) {
119123
throw MergingException.wrapException(e);
@@ -167,6 +171,7 @@ static UnwrittenMergedAndroidData mergeData(
167171
boolean allowPrimaryOverrideAll,
168172
AndroidDataDeserializer deserializer,
169173
boolean throwOnResourceConflict,
174+
boolean logWarningOnResourceConflict,
170175
SourceChecker checker) {
171176
Stopwatch timer = Stopwatch.createStarted();
172177
// TODO(b/74333698): Always check the contents of conflicting resources
@@ -179,7 +184,8 @@ static UnwrittenMergedAndroidData mergeData(
179184
primary,
180185
primaryManifest,
181186
allowPrimaryOverrideAll,
182-
throwOnResourceConflict);
187+
throwOnResourceConflict,
188+
logWarningOnResourceConflict);
183189
} finally {
184190
logger.fine(String.format("merge finished in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
185191
}
@@ -197,6 +203,7 @@ static void mergeCompiledData(
197203
@Nullable final AndroidResourceClassWriter rclassWriter,
198204
@Nullable PlaceholderRTxtWriter rTxtWriter,
199205
boolean throwOnResourceConflict,
206+
boolean logWarningOnResourceConflict,
200207
ListeningExecutorService executorService) {
201208
final ParsedAndroidData.Builder primaryBuilder = ParsedAndroidData.Builder.newBuilder();
202209
final AndroidDataDeserializer deserializer =
@@ -216,6 +223,7 @@ static void mergeCompiledData(
216223
false,
217224
deserializer,
218225
throwOnResourceConflict,
226+
logWarningOnResourceConflict,
219227
AndroidDataMerger.NoopSourceChecker.create());
220228
timer.reset().start();
221229
merged.writeResourceClass(rclassWriter);

0 commit comments

Comments
 (0)