diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp')
20 files changed, 147 insertions, 235 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java index 86f3184349..7b7906a529 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.rules.cpp; -import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.Artifact; @@ -236,15 +235,14 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory { helper.addStaticLibraries(alwayslinkLibrariesFromSrcs); helper.addPicStaticLibraries(picStaticLibrariesFromSrcs); helper.addPicStaticLibraries(picAlwayslinkLibrariesFromSrcs); - helper.addDynamicLibraries(Iterables.transform(precompiledFiles.getSharedLibraries(), - new Function<Artifact, LibraryToLink>() { - @Override - public LibraryToLink apply(Artifact library) { - return LinkerInputs.solibLibraryToLink( - common.getDynamicLibrarySymlink(library, true), library, - CcLinkingOutputs.libraryIdentifierOf(library)); - } - })); + helper.addDynamicLibraries( + Iterables.transform( + precompiledFiles.getSharedLibraries(), + library -> + LinkerInputs.solibLibraryToLink( + common.getDynamicLibrarySymlink(library, true), + library, + CcLinkingOutputs.libraryIdentifierOf(library)))); CcLibraryHelper.Info info = helper.build(); /* diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java index ffdacd353d..3c7aa425c2 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java @@ -14,8 +14,10 @@ package com.google.devtools.build.lib.rules.cpp; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toCollection; + import com.google.common.base.Function; -import com.google.common.base.Joiner; import com.google.common.base.Optional; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableList; @@ -24,6 +26,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSetMultimap; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; +import com.google.common.collect.Streams; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.AnalysisUtils; import com.google.devtools.build.lib.analysis.FileProvider; @@ -52,7 +55,6 @@ import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType; import com.google.devtools.build.lib.rules.cpp.Link.Staticness; import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink; import com.google.devtools.build.lib.syntax.Type; -import com.google.devtools.build.lib.util.FileType; import com.google.devtools.build.lib.util.FileTypeSet; import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.util.Preconditions; @@ -171,14 +173,10 @@ public final class CcLibraryHelper { /** Function for extracting module maps from CppCompilationDependencies. */ public static final Function<TransitiveInfoCollection, CppModuleMap> CPP_DEPS_TO_MODULES = - new Function<TransitiveInfoCollection, CppModuleMap>() { - @Override - @Nullable - public CppModuleMap apply(TransitiveInfoCollection dep) { + dep -> { CppCompilationContext context = dep.getProvider(CppCompilationContext.class); return context == null ? null : context.getCppModuleMap(); - } - }; + }; /** * Contains the providers as well as the compilation and linking outputs, and the compilation @@ -1004,15 +1002,17 @@ public final class CcLibraryHelper { LinkerInputs.toNonSolibArtifacts(linkedLibraryMap.get(matchingIdentifier)); ruleContext.ruleError( "Can't put " - + Joiner.on(", ") - .join(Iterables.transform(matchingInputLibs, FileType.TO_FILENAME)) + + Streams.stream(matchingInputLibs) + .map(Artifact::getFilename) + .collect(joining(", ")) + " into the srcs of a " + ruleContext.getRuleClassNameForLogging() + " with the same name (" + ruleContext.getRule().getName() + ") which also contains other code or objects to link; it shares a name with " - + Joiner.on(", ") - .join(Iterables.transform(matchingOutputLibs, FileType.TO_FILENAME)) + + Streams.stream(matchingOutputLibs) + .map(Artifact::getFilename) + .collect(joining(", ")) + " (output compiled and linked from the non-library sources of this rule), " + "which could cause confusion"); } @@ -1463,8 +1463,8 @@ public final class CcLibraryHelper { private Iterable<CppModuleMap> collectModuleMaps() { // Cpp module maps may be null for some rules. We filter the nulls out at the end. - List<CppModuleMap> result = new ArrayList<>(); - Iterables.addAll(result, Iterables.transform(deps, CPP_DEPS_TO_MODULES)); + List<CppModuleMap> result = + deps.stream().map(CPP_DEPS_TO_MODULES).collect(toCollection(ArrayList::new)); if (ruleContext.getRule().getAttributeDefinition(":stl") != null) { CppCompilationContext stl = ruleContext.getPrerequisite(":stl", Mode.TARGET, CppCompilationContext.class); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParams.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParams.java index 9469a30bfe..4b9fcd7e8e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParams.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParams.java @@ -27,7 +27,6 @@ import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink; import com.google.devtools.build.lib.util.Preconditions; - import java.util.Collection; import java.util.List; import java.util.Objects; @@ -90,13 +89,7 @@ public final class CcLinkParams { } public ImmutableList<String> flattenedLinkopts() { - return ImmutableList.copyOf(Iterables.concat(Iterables.transform(linkOpts, - new Function<LinkOptions, ImmutableList<String>>() { - @Override - public ImmutableList<String> apply(LinkOptions linkOptions) { - return linkOptions.get(); - } - }))); + return ImmutableList.copyOf(Iterables.concat(Iterables.transform(linkOpts, LinkOptions::get))); } /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParamsProvider.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParamsProvider.java index 0f103b7eb6..76a6c768f3 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParamsProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParamsProvider.java @@ -31,23 +31,20 @@ public final class CcLinkParamsProvider extends SkylarkClassObject public static final ClassObjectConstructor CC_LINK_PARAMS = new NativeClassObjectConstructor("link_params") { }; public static final Function<TransitiveInfoCollection, CcLinkParamsStore> TO_LINK_PARAMS = - new Function<TransitiveInfoCollection, CcLinkParamsStore>() { - @Override - public CcLinkParamsStore apply(TransitiveInfoCollection input) { + input -> { - // Try native first... - CcLinkParamsProvider provider = input.getProvider(CcLinkParamsProvider.class); - if (provider != null) { - return provider.getCcLinkParamsStore(); - } + // Try native first... + CcLinkParamsProvider provider = input.getProvider(CcLinkParamsProvider.class); + if (provider != null) { + return provider.getCcLinkParamsStore(); + } - // ... then try Skylark. - provider = (CcLinkParamsProvider) input.get(CC_LINK_PARAMS.getKey()); - if (provider != null) { - return provider.getCcLinkParamsStore(); - } - return null; + // ... then try Skylark. + provider = (CcLinkParamsProvider) input.get(CC_LINK_PARAMS.getKey()); + if (provider != null) { + return provider.getCcLinkParamsStore(); } + return null; }; private final CcLinkParamsStoreImpl store; diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSpecificLinkParamsProvider.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSpecificLinkParamsProvider.java index e43154fb91..6afb548bb0 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSpecificLinkParamsProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSpecificLinkParamsProvider.java @@ -37,12 +37,9 @@ public final class CcSpecificLinkParamsProvider implements TransitiveInfoProvide } public static final Function<TransitiveInfoCollection, CcLinkParamsStore> TO_LINK_PARAMS = - new Function<TransitiveInfoCollection, CcLinkParamsStore>() { - @Override - public CcLinkParamsStore apply(TransitiveInfoCollection input) { - CcSpecificLinkParamsProvider provider = input.getProvider( - CcSpecificLinkParamsProvider.class); - return provider == null ? null : provider.getLinkParams(); - } + input -> { + CcSpecificLinkParamsProvider provider = + input.getProvider(CcSpecificLinkParamsProvider.class); + return provider == null ? null : provider.getLinkParams(); }; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java index 67226586a6..1eee0802c4 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java @@ -18,7 +18,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; import com.google.common.base.Optional; import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; import com.google.common.base.Strings; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; @@ -762,14 +761,9 @@ public class CcToolchainFeatures implements Serializable { Optional<CToolchain.Tool> tool = Iterables.tryFind( tools, - new Predicate<CToolchain.Tool>() { - // We select the first listed tool for which all specified features are activated - // in this configuration - @Override - public boolean apply(CToolchain.Tool input) { - Collection<String> featureNamesForTool = input.getWithFeature().getFeatureList(); - return enabledFeatureNames.containsAll(featureNamesForTool); - } + input -> { + Collection<String> featureNamesForTool = input.getWithFeature().getFeatureList(); + return enabledFeatureNames.containsAll(featureNamesForTool); }); if (tool.isPresent()) { return new Tool(tool.get()); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLine.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLine.java index f8c39402eb..2df5412218 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLine.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLine.java @@ -15,7 +15,6 @@ package com.google.devtools.build.lib.rules.cpp; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.config.PerLabelOptions; import com.google.devtools.build.lib.cmdline.Label; @@ -197,7 +196,7 @@ public final class CompileCommandLine { // For each option in 'in', add it to 'out' unless it is matched by the 'coptsFilter' regexp. private void addFilteredOptions(List<String> out, List<String> in) { - Iterables.addAll(out, Iterables.filter(in, coptsFilter)); + in.stream().filter(coptsFilter).forEachOrdered(out::add); } public Artifact getSourceFile() { diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java index c86348a100..f5d21f486d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java @@ -222,17 +222,14 @@ public class CppCompileActionBuilder { if (finalPatterns.isEmpty()) { return Predicates.alwaysTrue(); } else { - return new Predicate<String>() { - @Override - public boolean apply(String option) { - for (Pattern pattern : finalPatterns) { - if (pattern.matcher(option).matches()) { - return false; - } + return option -> { + for (Pattern pattern : finalPatterns) { + if (pattern.matcher(option).matches()) { + return false; } - - return true; } + + return true; }; } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java index b66c6904e4..5468a1607e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java @@ -15,7 +15,6 @@ package com.google.devtools.build.lib.rules.cpp; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Predicate; import com.google.common.base.Verify; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableList; @@ -52,7 +51,6 @@ import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain; -import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain.ActionConfig; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain.ArtifactNamePattern; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.LinkingModeFlags; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.LipoMode; @@ -405,22 +403,19 @@ public class CppConfiguration extends BuildConfiguration.Fragment { Iterable<Tool> neededTools = Iterables.filter( EnumSet.allOf(Tool.class), - new Predicate<Tool>() { - @Override - public boolean apply(Tool tool) { - if (tool == Tool.DWP) { - // When fission is unsupported, don't check for the dwp tool. - return supportsFission(); - } else if (tool == Tool.LLVM_PROFDATA) { - // TODO(tmsriram): Fix this to check if this is a llvm crosstool - // and return true. This needs changes to crosstool_config.proto. - return false; - } else if (tool == Tool.GCOVTOOL || tool == Tool.OBJCOPY) { - // gcov-tool and objcopy are optional, don't check whether they're present - return false; - } else { - return true; - } + tool -> { + if (tool == Tool.DWP) { + // When fission is unsupported, don't check for the dwp tool. + return supportsFission(); + } else if (tool == Tool.LLVM_PROFDATA) { + // TODO(tmsriram): Fix this to check if this is a llvm crosstool + // and return true. This needs changes to crosstool_config.proto. + return false; + } else if (tool == Tool.GCOVTOOL || tool == Tool.OBJCOPY) { + // gcov-tool and objcopy are optional, don't check whether they're present + return false; + } else { + return true; } }); for (Tool tool : neededTools) { @@ -600,17 +595,10 @@ public class CppConfiguration extends BuildConfiguration.Fragment { } private static boolean actionsAreConfigured(CToolchain toolchain) { - return Iterables.any( - toolchain.getActionConfigList(), - new Predicate<ActionConfig>() { - @Override - public boolean apply(@Nullable ActionConfig actionConfig) { - // We cannot assume actions are configured just by presence of any action_config. Some - // crosstools specify unrelated action_configs (e.g. clif_match), but C/C++ part is - // in fact not configured. - return actionConfig.getActionName().contains("c++"); - } - }); + return toolchain + .getActionConfigList() + .stream() + .anyMatch(actionConfig -> actionConfig.getActionName().contains("c++")); } // TODO(bazel-team): Remove this once bazel supports all crosstool flags through diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java index cdda812667..3c7f07f6df 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java @@ -169,20 +169,17 @@ public final class CppFileTypes { /** Predicate that matches all artifacts that can be used in an objc Clang module map. */ public static final Predicate<Artifact> MODULE_MAP_HEADER = - new Predicate<Artifact>() { - @Override - public boolean apply(Artifact artifact) { - if (artifact.isTreeArtifact()) { - // Tree artifact is basically a directory, which does not have any information about - // the contained files and their extensions. Here we assume the passed in tree artifact - // contains proper header files with .h extension. - return true; - } else { - // The current clang (clang-600.0.57) on Darwin doesn't support 'textual', so we can't - // have '.inc' files in the module map (since they're implictly textual). - // TODO(bazel-team): Use HEADERS file type once clang-700 is the base clang we support. - return artifact.getFilename().endsWith(".h"); - } + artifact -> { + if (artifact.isTreeArtifact()) { + // Tree artifact is basically a directory, which does not have any information about + // the contained files and their extensions. Here we assume the passed in tree artifact + // contains proper header files with .h extension. + return true; + } else { + // The current clang (clang-600.0.57) on Darwin doesn't support 'textual', so we can't + // have '.inc' files in the module map (since they're implictly textual). + // TODO(bazel-team): Use HEADERS file type once clang-700 is the base clang we support. + return artifact.getFilename().endsWith(".h"); } }; diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModuleMapAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModuleMapAction.java index 137e22c871..8df91f4995 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModuleMapAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModuleMapAction.java @@ -77,11 +77,11 @@ public final class CppModuleMapAction extends AbstractFileWriteAction { super( owner, ImmutableList.<Artifact>builder() - .addAll(Iterables.filter(privateHeaders, Artifact.IS_TREE_ARTIFACT)) - .addAll(Iterables.filter(publicHeaders, Artifact.IS_TREE_ARTIFACT)) + .addAll(Iterables.filter(privateHeaders, Artifact::isTreeArtifact)) + .addAll(Iterables.filter(publicHeaders, Artifact::isTreeArtifact)) .build(), cppModuleMap.getArtifact(), - /*makeExecutable=*/false); + /*makeExecutable=*/ false); this.cppModuleMap = cppModuleMap; this.moduleMapHomeIsCwd = moduleMapHomeIsCwd; this.privateHeaders = ImmutableList.copyOf(privateHeaders); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRunfilesProvider.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRunfilesProvider.java index 43c13ac5f5..30f7bc9e11 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRunfilesProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRunfilesProvider.java @@ -45,33 +45,23 @@ public final class CppRunfilesProvider implements TransitiveInfoProvider { } /** - * Returns a function that gets the static C++ runfiles from a {@link TransitiveInfoCollection} - * or the empty runfiles instance if it does not contain that provider. + * Returns a function that gets the static C++ runfiles from a {@link TransitiveInfoCollection} or + * the empty runfiles instance if it does not contain that provider. */ public static final Function<TransitiveInfoCollection, Runfiles> STATIC_RUNFILES = - new Function<TransitiveInfoCollection, Runfiles>() { - @Override - public Runfiles apply(TransitiveInfoCollection input) { - CppRunfilesProvider provider = input.getProvider(CppRunfilesProvider.class); - return provider == null - ? Runfiles.EMPTY - : provider.getStaticRunfiles(); - } + input -> { + CppRunfilesProvider provider = input.getProvider(CppRunfilesProvider.class); + return provider == null ? Runfiles.EMPTY : provider.getStaticRunfiles(); }; /** - * Returns a function that gets the shared C++ runfiles from a {@link TransitiveInfoCollection} - * or the empty runfiles instance if it does not contain that provider. + * Returns a function that gets the shared C++ runfiles from a {@link TransitiveInfoCollection} or + * the empty runfiles instance if it does not contain that provider. */ public static final Function<TransitiveInfoCollection, Runfiles> SHARED_RUNFILES = - new Function<TransitiveInfoCollection, Runfiles>() { - @Override - public Runfiles apply(TransitiveInfoCollection input) { - CppRunfilesProvider provider = input.getProvider(CppRunfilesProvider.class); - return provider == null - ? Runfiles.EMPTY - : provider.getSharedRunfiles(); - } + input -> { + CppRunfilesProvider provider = input.getProvider(CppRunfilesProvider.class); + return provider == null ? Runfiles.EMPTY : provider.getSharedRunfiles(); }; /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoader.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoader.java index 29ace2f135..460dca7136 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoader.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoader.java @@ -45,7 +45,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import javax.annotation.Nullable; @@ -251,12 +250,9 @@ public class CrosstoolConfigurationLoader { String md5 = BaseEncoding.base16().lowerCase().encode(finalProto.getMd5()); CrosstoolConfig.CrosstoolRelease release; try { - release = crosstoolReleaseCache.get(md5, new Callable<CrosstoolRelease>() { - @Override - public CrosstoolRelease call() throws Exception { - return toReleaseConfiguration(finalProto.getName(), finalProto.getContents()); - } - }); + release = + crosstoolReleaseCache.get( + md5, () -> toReleaseConfiguration(finalProto.getName(), finalProto.getContents())); } catch (ExecutionException e) { throw new InvalidConfigurationException(e); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/ExtraLinkTimeLibraries.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/ExtraLinkTimeLibraries.java index d596ce0156..4a5c725fa5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/ExtraLinkTimeLibraries.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/ExtraLinkTimeLibraries.java @@ -15,7 +15,6 @@ package com.google.devtools.build.lib.rules.cpp; import com.google.common.collect.Lists; - import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; @@ -79,9 +78,7 @@ public final class ExtraLinkTimeLibraries { public final Builder addTransitive(ExtraLinkTimeLibraries dep) { for (ExtraLinkTimeLibrary depLibrary : dep.getExtraLibraries()) { Class<? extends ExtraLinkTimeLibrary> c = depLibrary.getClass(); - if (!libraries.containsKey(c)) { - libraries.put(c, depLibrary.getBuilder()); - } + libraries.computeIfAbsent(c, k -> depLibrary.getBuilder()); libraries.get(c).addTransitive(depLibrary); } return this; @@ -92,9 +89,7 @@ public final class ExtraLinkTimeLibraries { */ public final Builder add(ExtraLinkTimeLibrary b) { Class<? extends ExtraLinkTimeLibrary> c = b.getClass(); - if (!libraries.containsKey(c)) { - libraries.put(c, b.getBuilder()); - } + libraries.computeIfAbsent(c, k -> b.getBuilder()); libraries.get(c).addTransitive(b); return this; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java index 70a9dd184d..a8c0160791 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java @@ -15,13 +15,11 @@ package com.google.devtools.build.lib.rules.cpp; import static java.nio.charset.StandardCharsets.ISO_8859_1; +import static java.util.stream.Collectors.joining; -import com.google.common.base.Function; -import com.google.common.base.Joiner; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.ActionExecutionContext; import com.google.devtools.build.lib.actions.ActionExecutionException; import com.google.devtools.build.lib.actions.ActionOwner; @@ -207,24 +205,26 @@ public class FakeCppCompileAction extends CppCompileAction { // runfiles directory (where writing is forbidden), we patch the command // line to write to $TEST_TMPDIR instead. final String outputPrefix = "$TEST_TMPDIR/"; - String argv = Joiner.on(' ').join( - Iterables.transform(getArgv(outputFile.getExecPath()), new Function<String, String>() { - @Override - public String apply(String input) { - String result = ShellEscaper.escapeString(input); - // Once -c and -o options are added into action_config, the argument of - // getArgv(outputFile.getExecPath()) won't be used anymore. There will always be - // -c <tempOutputFile>, but here it has to be outputFile, so we replace it. - if (input.equals(tempOutputFile.getPathString())) { - result = outputPrefix + ShellEscaper.escapeString(outputFile.getExecPathString()); - } - if (input.equals(outputFile.getExecPathString()) - || input.equals(getDotdFile().getSafeExecPath().getPathString())) { - result = outputPrefix + ShellEscaper.escapeString(input); - } - return result; - } - })); + String argv = + getArgv(outputFile.getExecPath()) + .stream() + .map( + input -> { + String result = ShellEscaper.escapeString(input); + // Once -c and -o options are added into action_config, the argument of + // getArgv(outputFile.getExecPath()) won't be used anymore. There will always be + // -c <tempOutputFile>, but here it has to be outputFile, so we replace it. + if (input.equals(tempOutputFile.getPathString())) { + result = + outputPrefix + ShellEscaper.escapeString(outputFile.getExecPathString()); + } + if (input.equals(outputFile.getExecPathString()) + || input.equals(getDotdFile().getSafeExecPath().getPathString())) { + result = outputPrefix + ShellEscaper.escapeString(input); + } + return result; + }) + .collect(joining(" ")); // Write the command needed to build the real .o file to the fake .o file. // Generate a command to ensure that the output directory exists; otherwise diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java index b279440b7f..a904db923b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java @@ -657,8 +657,9 @@ public final class LinkCommandLine extends CommandLine { if (linkstampCompileOptions.isEmpty()) { actualLinkstampCompileOptions = DEFAULT_LINKSTAMP_OPTIONS; } else { - actualLinkstampCompileOptions = ImmutableList.copyOf( - Iterables.concat(DEFAULT_LINKSTAMP_OPTIONS, linkstampCompileOptions)); + actualLinkstampCompileOptions = + ImmutableList.copyOf( + Iterables.concat(DEFAULT_LINKSTAMP_OPTIONS, linkstampCompileOptions)); } if (toolchain == null) { diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInputs.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInputs.java index fd3dce6dee..bee6f9266c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInputs.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInputs.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.rules.cpp; -import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.Artifact; @@ -352,12 +351,7 @@ public abstract class LinkerInputs { */ public static Iterable<LinkerInput> simpleLinkerInputs(Iterable<Artifact> input, final ArtifactCategory category) { - return Iterables.transform(input, new Function<Artifact, LinkerInput>() { - @Override - public LinkerInput apply(Artifact artifact) { - return simpleLinkerInput(artifact, category); - } - }); + return Iterables.transform(input, artifact -> simpleLinkerInput(artifact, category)); } /** @@ -382,12 +376,7 @@ public abstract class LinkerInputs { */ public static Iterable<LibraryToLink> opaqueLibrariesToLink( final ArtifactCategory category, Iterable<Artifact> input) { - return Iterables.transform(input, new Function<Artifact, LibraryToLink>() { - @Override - public LibraryToLink apply(Artifact artifact) { - return precompiledLibraryToLink(artifact, category); - } - }); + return Iterables.transform(input, artifact -> precompiledLibraryToLink(artifact, category)); } /** @@ -429,27 +418,14 @@ public abstract class LinkerInputs { library, category, libraryIdentifier, objectFiles, ltoBitcodeFiles); } - private static final Function<LibraryToLink, Artifact> LIBRARY_TO_NON_SOLIB = - new Function<LibraryToLink, Artifact>() { - @Override - public Artifact apply(LibraryToLink input) { - return input.getOriginalLibraryArtifact(); - } - }; - public static Iterable<Artifact> toNonSolibArtifacts(Iterable<LibraryToLink> libraries) { - return Iterables.transform(libraries, LIBRARY_TO_NON_SOLIB); + return Iterables.transform(libraries, LibraryToLink::getOriginalLibraryArtifact); } /** * Returns the linker input artifacts from a collection of {@link LinkerInput} objects. */ public static Iterable<Artifact> toLibraryArtifacts(Iterable<? extends LinkerInput> artifacts) { - return Iterables.transform(artifacts, new Function<LinkerInput, Artifact>() { - @Override - public Artifact apply(LinkerInput input) { - return input.getArtifact(); - } - }); + return Iterables.transform(artifacts, LinkerInput::getArtifact); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/PrecompiledFiles.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/PrecompiledFiles.java index 6f9e6f0c94..8dbedeae85 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/PrecompiledFiles.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/PrecompiledFiles.java @@ -13,7 +13,6 @@ // limitations under the License. package com.google.devtools.build.lib.rules.cpp; -import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.Artifact; @@ -76,21 +75,20 @@ public final class PrecompiledFiles { public Iterable<Artifact> getObjectFiles(final boolean usePic) { if (usePic) { - return Iterables.filter(files, new Predicate<Artifact>() { - @Override - public boolean apply(Artifact artifact) { - String filename = artifact.getExecPathString(); + return Iterables.filter( + files, + artifact -> { + String filename = artifact.getExecPathString(); - // For compatibility with existing BUILD files, any ".o" files listed - // in srcs are assumed to be position-independent code, or - // at least suitable for inclusion in shared libraries, unless they - // end with ".nopic.o". (The ".nopic.o" extension is an undocumented - // feature to give users at least some control over this.) Note that - // some target platforms do not require shared library code to be PIC. - return CppFileTypes.PIC_OBJECT_FILE.matches(filename) - || (CppFileTypes.OBJECT_FILE.matches(filename) && !filename.endsWith(".nopic.o")); - } - }); + // For compatibility with existing BUILD files, any ".o" files listed + // in srcs are assumed to be position-independent code, or + // at least suitable for inclusion in shared libraries, unless they + // end with ".nopic.o". (The ".nopic.o" extension is an undocumented + // feature to give users at least some control over this.) Note that + // some target platforms do not require shared library code to be PIC. + return CppFileTypes.PIC_OBJECT_FILE.matches(filename) + || (CppFileTypes.OBJECT_FILE.matches(filename) && !filename.endsWith(".nopic.o")); + }); } else { return FileType.filter(files, CppFileTypes.OBJECT_FILE); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/UmbrellaHeaderAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/UmbrellaHeaderAction.java index 14c3a0cfaa..eada861fc1 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/UmbrellaHeaderAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/UmbrellaHeaderAction.java @@ -13,8 +13,10 @@ // limitations under the License. package com.google.devtools.build.lib.rules.cpp; +import static com.google.common.collect.ImmutableList.toImmutableList; + import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; +import com.google.common.collect.Streams; import com.google.devtools.build.lib.actions.ActionExecutionContext; import com.google.devtools.build.lib.actions.ActionOwner; import com.google.devtools.build.lib.actions.Artifact; @@ -50,9 +52,9 @@ public final class UmbrellaHeaderAction extends AbstractFileWriteAction { Iterable<PathFragment> additionalExportedHeaders) { super( owner, - ImmutableList.copyOf(Iterables.filter(publicHeaders, Artifact.IS_TREE_ARTIFACT)), + Streams.stream(publicHeaders).filter(Artifact::isTreeArtifact).collect(toImmutableList()), umbrellaHeader, - /*makeExecutable=*/false); + /*makeExecutable=*/ false); this.umbrellaHeader = umbrellaHeader; this.publicHeaders = ImmutableList.copyOf(publicHeaders); this.additionalExportedHeaders = ImmutableList.copyOf(additionalExportedHeaders); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoLibraryRule.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoLibraryRule.java index 065f722565..dd02eaaadf 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoLibraryRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoLibraryRule.java @@ -25,22 +25,10 @@ import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; import com.google.devtools.build.lib.packages.AspectParameters; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.RuleClass; -import javax.annotation.Nullable; /** Declaration part of cc_proto_library. */ public class CcProtoLibraryRule implements RuleDefinition { - private static final Function<Rule, AspectParameters> ASPECT_PARAMETERS = - new Function<Rule, AspectParameters>() { - @Nullable - @Override - public AspectParameters apply(@Nullable Rule rule) { - return new AspectParameters.Builder() - .addAttribute(INJECTING_RULE_KIND_PARAMETER_KEY, "cc_proto_library") - .build(); - } - }; - private final CcProtoAspect ccProtoAspect; public CcProtoLibraryRule(CcProtoAspect ccProtoAspect) { @@ -49,6 +37,12 @@ public class CcProtoLibraryRule implements RuleDefinition { @Override public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment environment) { + Function<Rule, AspectParameters> aspectParameters = + rule -> + new AspectParameters.Builder() + .addAttribute(INJECTING_RULE_KIND_PARAMETER_KEY, "cc_proto_library") + .build(); + return builder /* <!-- #BLAZE_RULE(cc_proto_library).ATTRIBUTE(deps) --> The list of <a href="protocol-buffer.html#proto_library"><code>proto_library</code></a> @@ -58,7 +52,7 @@ public class CcProtoLibraryRule implements RuleDefinition { attr("deps", LABEL_LIST) .allowedRuleClasses("proto_library") .allowedFileTypes() - .aspect(ccProtoAspect, ASPECT_PARAMETERS)) + .aspect(ccProtoAspect, aspectParameters)) .build(); } |