Skip to content

Commit 9921a99

Browse files
Googlercopybara-github
Googler
authored andcommitted
Automatic code cleanup.
PiperOrigin-RevId: 444856681
1 parent 219ef5d commit 9921a99

9 files changed

+81
-81
lines changed

src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java

+16-13
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,13 @@ public static List<Pair<Artifact, Label>> getHeaders(RuleContext ruleContext) {
356356
FileProvider provider = target.getProvider(FileProvider.class);
357357
for (Artifact artifact : provider.getFilesToBuild().toList()) {
358358
if (CppRuleClasses.DISALLOWED_HDRS_FILES.matches(artifact.getFilename())) {
359-
ruleContext.attributeWarning("hdrs", "file '" + artifact.getFilename()
360-
+ "' from target '" + target.getLabel() + "' is not allowed in hdrs");
359+
ruleContext.attributeWarning(
360+
"hdrs",
361+
"file '"
362+
+ artifact.getFilename()
363+
+ "' from target '"
364+
+ target.getLabel()
365+
+ "' is not allowed in hdrs");
361366
continue;
362367
}
363368
Label oldLabel = map.put(artifact, target.getLabel());
@@ -366,9 +371,7 @@ public static List<Pair<Artifact, Label>> getHeaders(RuleContext ruleContext) {
366371
"hdrs",
367372
String.format(
368373
"Artifact '%s' is duplicated (through '%s' and '%s')",
369-
artifact.getExecPathString(),
370-
oldLabel,
371-
target.getLabel()));
374+
artifact.getExecPathString(), oldLabel, target.getLabel()));
372375
}
373376
}
374377
}
@@ -380,6 +383,14 @@ public static List<Pair<Artifact, Label>> getHeaders(RuleContext ruleContext) {
380383
return result.build();
381384
}
382385

386+
/**
387+
* Returns the files from headers and does some checks. Note that this method reports warnings to
388+
* the {@link RuleContext} as a side effect, and so should only be called once for any given rule.
389+
*/
390+
public List<Pair<Artifact, Label>> getHeaders() {
391+
return getHeaders(ruleContext);
392+
}
393+
383394
/** Returns the C++ toolchain provider. */
384395
@StarlarkMethod(name = "toolchain", documented = false, structField = true)
385396
public CcToolchainProvider getToolchain() {
@@ -391,14 +402,6 @@ public FdoContext getFdoContext() {
391402
return fdoContext;
392403
}
393404

394-
/**
395-
* Returns the files from headers and does some checks. Note that this method reports warnings to
396-
* the {@link RuleContext} as a side effect, and so should only be called once for any given rule.
397-
*/
398-
public List<Pair<Artifact, Label>> getHeaders() {
399-
return getHeaders(ruleContext);
400-
}
401-
402405
@StarlarkMethod(
403406
name = "report_invalid_options",
404407
documented = false,

src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -389,21 +389,6 @@ public CcCompilationHelper addPublicHeaders(Collection<Artifact> headers) {
389389
return this;
390390
}
391391

392-
/**
393-
* Adds headers that are compiled into a separate module (when using C++ modules). The idea here
394-
* is that a single (generated) library might want to create headers of very different transitive
395-
* dependency size. In this case, building headers with very few transitive dependencies into a
396-
* separate module can drastrically improve build performance of that module and its users.
397-
*
398-
* <p>Headers in this separate module must not include any of the regular headers.
399-
*
400-
* <p>THIS IS AN EXPERIMENTAL FACILITY THAT MIGHT GO AWAY.
401-
*/
402-
public CcCompilationHelper addSeparateModuleHeaders(Collection<Artifact> headers) {
403-
separateModuleHeaders.addAll(headers);
404-
return this;
405-
}
406-
407392
/**
408393
* Adds {@code headers} as public header files. These files will be made visible to dependent
409394
* rules. They may be parsed/preprocessed or compiled into a header module depending on the
@@ -426,6 +411,21 @@ public CcCompilationHelper addPublicHeaders(Iterable<Pair<Artifact, Label>> head
426411
return this;
427412
}
428413

414+
/**
415+
* Adds headers that are compiled into a separate module (when using C++ modules). The idea here
416+
* is that a single (generated) library might want to create headers of very different transitive
417+
* dependency size. In this case, building headers with very few transitive dependencies into a
418+
* separate module can drastrically improve build performance of that module and its users.
419+
*
420+
* <p>Headers in this separate module must not include any of the regular headers.
421+
*
422+
* <p>THIS IS AN EXPERIMENTAL FACILITY THAT MIGHT GO AWAY.
423+
*/
424+
public CcCompilationHelper addSeparateModuleHeaders(Collection<Artifact> headers) {
425+
separateModuleHeaders.addAll(headers);
426+
return this;
427+
}
428+
429429
/**
430430
* Add the corresponding files as public header files, i.e., these files will not be compiled, but
431431
* are made visible as includes to dependent rules in module maps.

src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java

-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,6 @@ protected <T> Object asClassImmutableListOrNestedSet(
504504
* @param objectFiles {@code Sequence<Artifact>}
505505
* @return
506506
* @throws EvalException
507-
* @throws InterruptedException
508507
*/
509508
@Override
510509
public LibraryToLink createLibraryLinkerInput(

src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -1290,22 +1290,6 @@ protected FeatureConfiguration() {
12901290
/* ccToolchainPath= */ PathFragment.EMPTY_FRAGMENT);
12911291
}
12921292

1293-
@AutoCodec.Instantiator
1294-
static FeatureConfiguration createForSerialization(
1295-
ImmutableSet<String> requestedFeatures,
1296-
ImmutableList<Feature> enabledFeatures,
1297-
ImmutableSet<String> enabledActionConfigActionNames,
1298-
ImmutableMap<String, ActionConfig> actionConfigByActionName,
1299-
PathFragment ccToolchainPath) {
1300-
return FEATURE_CONFIGURATION_INTERNER.intern(
1301-
new FeatureConfiguration(
1302-
requestedFeatures,
1303-
enabledFeatures,
1304-
enabledActionConfigActionNames,
1305-
actionConfigByActionName,
1306-
ccToolchainPath));
1307-
}
1308-
13091293
FeatureConfiguration(
13101294
ImmutableSet<String> requestedFeatures,
13111295
ImmutableList<Feature> enabledFeatures,
@@ -1325,6 +1309,22 @@ static FeatureConfiguration createForSerialization(
13251309
this.ccToolchainPath = ccToolchainPath;
13261310
}
13271311

1312+
@AutoCodec.Instantiator
1313+
static FeatureConfiguration createForSerialization(
1314+
ImmutableSet<String> requestedFeatures,
1315+
ImmutableList<Feature> enabledFeatures,
1316+
ImmutableSet<String> enabledActionConfigActionNames,
1317+
ImmutableMap<String, ActionConfig> actionConfigByActionName,
1318+
PathFragment ccToolchainPath) {
1319+
return FEATURE_CONFIGURATION_INTERNER.intern(
1320+
new FeatureConfiguration(
1321+
requestedFeatures,
1322+
enabledFeatures,
1323+
enabledActionConfigActionNames,
1324+
actionConfigByActionName,
1325+
ccToolchainPath));
1326+
}
1327+
13281328
/**
13291329
* @return whether the given {@code feature} is enabled.
13301330
*/

src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProviderHelper.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ static PathFragment resolveIncludeDir(
267267
// TODO(jungjw): This should probably be getExecPath.
268268
pathPrefix = PackageIdentifier.parse(packageString).getPackagePath(siblingRepositoryLayout);
269269
} catch (LabelSyntaxException e) {
270-
throw new InvalidConfigurationException("The package '" + packageString + "' is not valid");
270+
throw new InvalidConfigurationException(
271+
"The package '" + packageString + "' is not valid", e);
271272
}
272273
int pathStartIndex = packageEndIndex + PACKAGE_END.length();
273274
if (pathStartIndex + 1 < s.length()) {
@@ -347,9 +348,6 @@ private static CppModuleMap createCrosstoolModuleMap(CcToolchainAttributesProvid
347348
/**
348349
* Returns {@link CcToolchainVariables} instance with build variables that only depend on the
349350
* toolchain.
350-
*
351-
* @throws RuleErrorException if there are configuration errors making it impossible to resolve
352-
* certain build variables of this toolchain
353351
*/
354352
static CcToolchainVariables getBuildVariables(
355353
BuildOptions buildOptions,

src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainVariables.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ boolean isAvailable(String variable, @Nullable ArtifactExpander expander) {
446446
return lookupVariable(variable, /* throwOnMissingVariable= */ false, expander) != null;
447447
} catch (ExpansionException e) {
448448
throw new IllegalStateException(
449-
"Should not happen - call to lookupVariable threw when asked not to.");
449+
"Should not happen - call to lookupVariable threw when asked not to.", e);
450450
}
451451
}
452452

src/main/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLine.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public ImmutableList<String> getCopts() {
181181
variables, CompileBuildVariables.USER_COMPILE_FLAGS.getVariableName());
182182
} catch (ExpansionException e) {
183183
throw new IllegalStateException(
184-
"Should not happen - 'user_compile_flags' should be a string list, but wasn't.");
184+
"Should not happen - 'user_compile_flags' should be a string list, but wasn't.", e);
185185
}
186186
} else {
187187
return ImmutableList.of();

src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java

+29-29
Original file line numberDiff line numberDiff line change
@@ -711,35 +711,6 @@ List<PathFragment> getSystemIncludeDirs() throws CommandLineExpansionException {
711711
return getSystemIncludeDirs(getCompilerOptions());
712712
}
713713

714-
private static final ImmutableList<CharMatcher> MSVC_CHARS =
715-
ImmutableList.of(
716-
CharMatcher.anyOf("mM"),
717-
CharMatcher.anyOf("sS"),
718-
CharMatcher.anyOf("vV"),
719-
CharMatcher.anyOf("cC"));
720-
private static final ImmutableList<CharMatcher> INCLUDE_PREFIX_CHARS =
721-
ImmutableList.of(CharMatcher.anyOf("-/"), CharMatcher.anyOf("iI"));
722-
723-
private static boolean substrMatchesChars(
724-
String s, int startPos, ImmutableList<CharMatcher> substr) {
725-
for (int i = 0; i < substr.size(); i++) {
726-
if (!substr.get(i).matches(s.charAt(startPos + i))) {
727-
return false;
728-
}
729-
}
730-
return true;
731-
}
732-
733-
private static boolean matchesCaseInsensitiveMsvc(String s) {
734-
return s.length() >= 4 && substrMatchesChars(s, 0, MSVC_CHARS);
735-
}
736-
737-
private static boolean matchesIncludeCaseInsensitiveMsvc(String s) {
738-
return s.length() >= 6
739-
&& substrMatchesChars(s, 0, INCLUDE_PREFIX_CHARS)
740-
&& substrMatchesChars(s, 2, MSVC_CHARS);
741-
}
742-
743714
private List<PathFragment> getSystemIncludeDirs(List<String> compilerOptions) {
744715
// TODO(bazel-team): parsing the command line flags here couples us to gcc- and clang-cl-style
745716
// compiler command lines; use a different way to specify system includes (for example through a
@@ -773,6 +744,35 @@ private List<PathFragment> getSystemIncludeDirs(List<String> compilerOptions) {
773744
return result.build();
774745
}
775746

747+
private static final ImmutableList<CharMatcher> MSVC_CHARS =
748+
ImmutableList.of(
749+
CharMatcher.anyOf("mM"),
750+
CharMatcher.anyOf("sS"),
751+
CharMatcher.anyOf("vV"),
752+
CharMatcher.anyOf("cC"));
753+
private static final ImmutableList<CharMatcher> INCLUDE_PREFIX_CHARS =
754+
ImmutableList.of(CharMatcher.anyOf("-/"), CharMatcher.anyOf("iI"));
755+
756+
private static boolean substrMatchesChars(
757+
String s, int startPos, ImmutableList<CharMatcher> substr) {
758+
for (int i = 0; i < substr.size(); i++) {
759+
if (!substr.get(i).matches(s.charAt(startPos + i))) {
760+
return false;
761+
}
762+
}
763+
return true;
764+
}
765+
766+
private static boolean matchesCaseInsensitiveMsvc(String s) {
767+
return s.length() >= 4 && substrMatchesChars(s, 0, MSVC_CHARS);
768+
}
769+
770+
private static boolean matchesIncludeCaseInsensitiveMsvc(String s) {
771+
return s.length() >= 6
772+
&& substrMatchesChars(s, 0, INCLUDE_PREFIX_CHARS)
773+
&& substrMatchesChars(s, 2, MSVC_CHARS);
774+
}
775+
776776
private static ImmutableList<String> getCmdlineIncludes(List<String> args) {
777777
ImmutableList.Builder<String> cmdlineIncludes = ImmutableList.builder();
778778
for (Iterator<String> argi = args.iterator(); argi.hasNext(); ) {

src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ public CppLinkAction build() throws InterruptedException, RuleErrorException {
760760
.build();
761761

762762
PathFragment paramRootPath =
763-
ParameterFile.derivePath(outputRootPath, (isLtoIndexing) ? "lto-index" : "2");
763+
ParameterFile.derivePath(outputRootPath, isLtoIndexing ? "lto-index" : "2");
764764

765765
@Nullable
766766
final Artifact paramFile =

0 commit comments

Comments
 (0)