diff options
author | plf <plf@google.com> | 2017-08-31 19:24:14 +0200 |
---|---|---|
committer | Vladimir Moskva <vladmos@google.com> | 2017-09-01 12:27:43 +0200 |
commit | ca58a3e431b003bde02be043bfca74226ac4a238 (patch) | |
tree | d232bab0fde07fdf534d64bace5e9fdfc831baa3 /src/main/java/com/google/devtools/build/lib/rules/cpp | |
parent | 9d9e1a7f11d68680c87aefd16ac26ad6af4fd94c (diff) |
Automated rollback of commit fc41c430e4de4594a1d699f573d191cbad52a2fb.
PiperOrigin-RevId: 167154793
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp')
4 files changed, 4 insertions, 151 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java index 32c8cf9dc1..4856b0a1e6 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java @@ -19,7 +19,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.devtools.build.lib.actions.ActionAnalysisMetadata; import com.google.devtools.build.lib.actions.Artifact; @@ -39,7 +38,6 @@ import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.PackageIdentifier; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition; import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.rules.apple.ApplePlatform; import com.google.devtools.build.lib.rules.cpp.CcLibraryHelper.SourceCategory; @@ -48,7 +46,6 @@ import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfig import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables; import com.google.devtools.build.lib.rules.cpp.CppConfiguration.DynamicMode; import com.google.devtools.build.lib.rules.cpp.CppConfiguration.HeadersCheckingMode; -import com.google.devtools.build.lib.rules.cpp.TransitiveSourcesProvider.SourceUsage; import com.google.devtools.build.lib.shell.ShellUtils; import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.util.FileType; @@ -60,7 +57,6 @@ import java.util.List; import java.util.Map; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; -import java.util.stream.Collectors; import javax.annotation.Nullable; /** @@ -223,22 +219,12 @@ public final class CcCommon { return new TransitiveLipoInfoProvider(scannableBuilder.build()); } - /** Returns true if the given rule has sources in the target configuration. */ - static boolean hasSourcesInTargetConfig(RuleContext ruleContext) { - return (ruleContext.attributes().has("srcs") - && ruleContext.attributes().getAttributeDefinition("srcs").getConfigurationTransition() - == ConfigurationTransition.NONE); - } - /** - * Returns a list of ({@link Artifact}, {@link Label}) pairs. Each pair represents an input source - * file and the label of the rule that generates it (or the label of the source file itself if it - * is an input file). + * Returns a list of ({@link Artifact}, {@link Label}) pairs. Each pair represents an input + * source file and the label of the rule that generates it (or the label of the source file + * itself if it is an input file). */ - static List<Pair<Artifact, Label>> getSources(RuleContext ruleContext) { - if (!ruleContext.attributes().has("srcs")) { - return ImmutableList.of(); - } + List<Pair<Artifact, Label>> getSources() { Map<Artifact, Label> map = Maps.newLinkedHashMap(); Iterable<? extends TransitiveInfoCollection> providers = ruleContext.getPrerequisitesIf("srcs", Mode.TARGET, FileProvider.class); @@ -269,15 +255,6 @@ public final class CcCommon { } /** - * Returns a list of ({@link Artifact}, {@link Label}) pairs. Each pair represents an input source - * file and the label of the rule that generates it (or the label of the source file itself if it - * is an input file). - */ - List<Pair<Artifact, Label>> getSources() { - return getSources(ruleContext); - } - - /** * Returns the files from headers and does some sanity checks. Note that this method reports * warnings to the {@link RuleContext} as a side effect, and so should only be called once for any * given rule. @@ -591,40 +568,6 @@ public final class CcCommon { } } - /** Computes the {@link TransitiveSourcesProvider} for this target using the given target. */ - public static TransitiveSourcesProvider getTransitiveSourcesProvider(RuleContext ruleContext) { - List<String> sources = - getSources(ruleContext) - .stream() - .map(pair -> pair.getSecond().getCanonicalForm()) - .collect(Collectors.toList()); - return getTransitiveSourcesProvider(ruleContext, sources); - } - - /** Computes the {@link TransitiveSourcesProvider} for this target using the given target. */ - public static TransitiveSourcesProvider getTransitiveSourcesProvider( - RuleContext ruleContext, List<String> sources) { - TransitiveSourcesProvider.Builder result = new TransitiveSourcesProvider.Builder(); - Iterable<TransitiveSourcesProvider> depTransitiveSourcesProviders = - ruleContext.getPrerequisitesSafe("deps", Mode.TARGET, TransitiveSourcesProvider.class); - for (SourceUsage sourceUsage : SourceUsage.values()) { - boolean sourceIsUsed = false; - // If dependencies use this source type, then the source type is used. - sourceIsUsed |= - (Lists.newArrayList(depTransitiveSourcesProviders) - .stream() - .anyMatch(provider -> provider.uses(sourceUsage))); - - // If this target uses this source type, then the source type is used. - sourceIsUsed |= (sources.stream().anyMatch(source -> sourceUsage.matches(source))); - - if (sourceIsUsed) { - result.doesUse(sourceUsage); - } - } - return result.build(); - } - /** * Creates the feature configuration for a given rule. * @@ -668,13 +611,6 @@ public final class CcCommon { requestedFeatures.addAll(sourceCategory.getActionConfigSet()); - // We check that this target has "srcs" in the target configuration to prevent failing in - // getSources() for rules like cc_embed_data, which have "srcs" in the data configuration. - if (hasSourcesInTargetConfig(ruleContext) - && getTransitiveSourcesProvider(ruleContext).uses(SourceUsage.OBJC)) { - requestedFeatures.add(CppRuleClasses.CONTAINS_OBJC_SOURCE); - } - FeatureSpecification currentFeatureSpecification = FeatureSpecification.create(requestedFeatures.build(), unsupportedFeatures); try { 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 6294cbe30a..a7ffab3456 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 @@ -68,7 +68,6 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; import java.util.regex.Pattern; -import java.util.stream.Collectors; import javax.annotation.Nullable; /** @@ -1086,18 +1085,6 @@ public final class CcLibraryHelper { new CcLinkParamsInfo( createCcLinkParamsStore(ccLinkingOutputs, cppCompilationContext, forcePic))); } - - if (CcCommon.hasSourcesInTargetConfig(ruleContext)) { - List<String> sources = - compilationUnitSources - .stream() - .map(cppSource -> cppSource.getSource().getExecPathString()) - .collect(Collectors.toList()); - providers.put( - TransitiveSourcesProvider.class, - CcCommon.getTransitiveSourcesProvider(ruleContext, sources)); - } - return new Info( providers.build(), outputGroups, diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java index 28c1735da9..06e4c9b687 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java @@ -365,7 +365,4 @@ public class CppRuleClasses { /** A string constant for the match-clif feature. */ public static final String MATCH_CLIF = "match_clif"; - - /** A string constant for the contains_objc_source feature. */ - public static final String CONTAINS_OBJC_SOURCE = "contains_objc_source"; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/TransitiveSourcesProvider.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/TransitiveSourcesProvider.java deleted file mode 100644 index a83ce68d34..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/TransitiveSourcesProvider.java +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2017 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.cpp; - -import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; -import com.google.devtools.build.lib.util.FileTypeSet; - -/** Provides information on sources in the transitive closure of a target. */ -// TODO(b/65016770): Add SWIFT to this provider. -public class TransitiveSourcesProvider implements TransitiveInfoProvider { - - /** Signal that a certain source type is used. */ - public enum SourceUsage { - CPP(FileTypeSet.of(CppFileTypes.CPP_SOURCE, CppFileTypes.OBJCPP_SOURCE)), - OBJC(FileTypeSet.of(CppFileTypes.OBJC_SOURCE)); - - private final FileTypeSet fileType; - - SourceUsage(FileTypeSet fileType) { - this.fileType = fileType; - } - - /** If true, the presence of the given source signals this source usage. */ - public boolean matches(String fileName) { - return fileType.matches(fileName); - } - } - - private final ImmutableList<SourceUsage> sources; - - private TransitiveSourcesProvider(ImmutableList<SourceUsage> sources) { - this.sources = sources; - } - - /** True if sources of the given type are used in this build. */ - public boolean uses(SourceUsage source) { - return sources.contains(source); - } - - /** Builder for TransitiveSourcesProvider */ - public static class Builder { - private final ImmutableList.Builder<SourceUsage> sources = ImmutableList.builder(); - - /** Signals that the build uses sources of the provided type. */ - public Builder doesUse(SourceUsage source) { - this.sources.add(source); - return this; - } - - public TransitiveSourcesProvider build() { - return new TransitiveSourcesProvider(this.sources.build()); - } - } -} |