aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar hlopko <hlopko@google.com>2018-03-06 01:58:35 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-06 02:00:07 -0800
commit5494ce4d63660f0c958a56c9cf6a5a8836967a97 (patch)
treebbcabe122d516b4ea46611e1b51f250fcc34553b /src/main/java/com
parent903b47985b329575dc369ed81dc7194db83a8beb (diff)
Remove cc_inc_library from bazel
It shouldn't be open sourced at all, since it solves a very specific internal use case, and for external use cc_library with its includes, include_prefix, and strip_include_prefix attributes can be used to perfectly replace cc_inc_library. RELNOTES: Removed cc_inc_library, please use cc_library instead Use includes, include_prefix, and strip_include_prefix attributes of cc_library to replace the behavior of cc_inc_library with cc_library. PiperOrigin-RevId: 187991313
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/CcRules.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibrary.java26
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibraryRule.java105
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcIncLibrary.java170
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcIncLibraryRule.java67
5 files changed, 0 insertions, 372 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/CcRules.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/CcRules.java
index 4345fb4e90..977c13caf7 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/CcRules.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/CcRules.java
@@ -19,13 +19,11 @@ import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider.RuleSe
import com.google.devtools.build.lib.bazel.rules.CcToolchainType.CcToolchainTypeRule;
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCcBinaryRule;
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCcImportRule;
-import com.google.devtools.build.lib.bazel.rules.cpp.BazelCcIncLibraryRule;
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCcLibraryRule;
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCcTestRule;
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCppRuleClasses;
import com.google.devtools.build.lib.rules.core.CoreRules;
import com.google.devtools.build.lib.rules.cpp.CcImportRule;
-import com.google.devtools.build.lib.rules.cpp.CcIncLibraryRule;
import com.google.devtools.build.lib.rules.cpp.CcModule;
import com.google.devtools.build.lib.rules.cpp.CcToolchainAlias.CcToolchainAliasRule;
import com.google.devtools.build.lib.rules.cpp.CcToolchainRule;
@@ -56,7 +54,6 @@ public class CcRules implements RuleSet {
builder.addRuleDefinition(new CcToolchainRule());
builder.addRuleDefinition(new CcToolchainSuiteRule());
builder.addRuleDefinition(new CcToolchainAliasRule());
- builder.addRuleDefinition(new CcIncLibraryRule());
builder.addRuleDefinition(new CcImportRule());
builder.addRuleDefinition(new CcToolchainTypeRule());
builder.addRuleDefinition(new BazelCppRuleClasses.CcLinkingRule());
@@ -69,7 +66,6 @@ public class CcRules implements RuleSet {
builder.addRuleDefinition(new BazelCcTestRule());
builder.addRuleDefinition(new BazelCppRuleClasses.CcLibraryBaseRule());
builder.addRuleDefinition(new BazelCcLibraryRule());
- builder.addRuleDefinition(new BazelCcIncLibraryRule());
builder.addRuleDefinition(new BazelCcImportRule());
builder.addWorkspaceFileSuffix(
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibrary.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibrary.java
deleted file mode 100644
index dd61123be0..0000000000
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibrary.java
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2016 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.bazel.rules.cpp;
-
-import com.google.devtools.build.lib.rules.cpp.CcIncLibrary;
-
-/**
- * Implementation of cc_inc_library.
- */
-public final class BazelCcIncLibrary extends CcIncLibrary {
- public BazelCcIncLibrary() {
- super(BazelCppSemantics.INSTANCE);
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibraryRule.java
deleted file mode 100644
index 8bbfa2de23..0000000000
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibraryRule.java
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright 2016 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.bazel.rules.cpp;
-
-import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.BuildType.LABEL;
-import static com.google.devtools.build.lib.packages.BuildType.NODEP_LABEL;
-
-import com.google.devtools.build.lib.analysis.BaseRuleClasses;
-import com.google.devtools.build.lib.analysis.RuleDefinition;
-import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
-import com.google.devtools.build.lib.packages.RuleClass;
-import com.google.devtools.build.lib.packages.RuleClass.Builder;
-import com.google.devtools.build.lib.rules.cpp.CcIncLibraryRule;
-import com.google.devtools.build.lib.rules.cpp.CcToolchain;
-import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
-import com.google.devtools.build.lib.rules.cpp.CppRuleClasses;
-
-/** Rule definition for the cc_inc_library class. */
-public final class BazelCcIncLibraryRule implements RuleDefinition {
- @Override
- public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
- return builder
- .requiresConfigurationFragments(CppConfiguration.class)
- .add(
- attr(CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME, LABEL)
- .value(CppRuleClasses.ccToolchainAttribute(env)))
- .add(
- attr(CcToolchain.CC_TOOLCHAIN_TYPE_ATTRIBUTE_NAME, NODEP_LABEL)
- .value(CppRuleClasses.ccToolchainTypeAttribute(env)))
- .add(attr(":stl", LABEL).value(BazelCppRuleClasses.STL))
- .build();
- }
-
- @Override
- public Metadata getMetadata() {
- return RuleDefinition.Metadata.builder()
- .name("cc_inc_library")
- .ancestors(BaseRuleClasses.RuleBase.class, CcIncLibraryRule.class)
- .factoryClass(BazelCcIncLibrary.class)
- .build();
- }
-}
-
-/*<!-- #BLAZE_RULE (NAME = cc_inc_library, TYPE = LIBRARY, FAMILY = C / C++) -->
-
-<p>
-Bazel creates a subdirectory below
-<code>includes</code> (relative to WORKSPACE) for each such rule, and makes sure that all
-dependent rules have a corresponding <code>-isystem</code> directive to add this
-directory into the compiler's header file search path for all compilations. Note
-that if a rule has multiple <code>cc_inc_library</code> rules from the same
-package in its dependencies, the first such rule will take precedence.
-</p>
-
-<p>
-One use case for the <code>cc_inc_library</code> rule is to allow C++
-<code>#include</code> directives to work with external
-libraries that are placed in a version-specific subdirectory, without the
-version number. For example, it allows including a header file in
-<code>/library/v1/a.h</code> using the path
-<code>/library/a.h</code>. This is useful to avoid changing a lot of
-code when upgrading to a newer version. In this case, there should be one
-<code>cc_inc_library</code> rule per public target. Note that only files that are declared in the
-hdrs attribute are available with the rewritten path.
-</p>
-
-<p>
-In this case, the <code>cc_inc_library</code> represents the interface of the package, and should be
-the public top-level rule so that strict header inclusion checks can be performed.
-</p>
-
-<pre class="code">
-# This rule makes the header file v1/library.h available for inclusion via the
-# path /library/library.h.
-cc_inc_library(
- name = "library",
- hdrs = ["v1/library.h"],
- prefix = "v1",
- deps = [":library_impl"],
-)
-
-cc_library(
- name = "library_impl",
- srcs = [
- "v1/library.c",
- "v1/library.h",
- ],
- visibility = ["//visibility:private"],
-)
-</pre>
-
-<!-- #END_BLAZE_RULE -->*/
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcIncLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcIncLibrary.java
deleted file mode 100644
index f65f6c69a9..0000000000
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcIncLibrary.java
+++ /dev/null
@@ -1,170 +0,0 @@
-// Copyright 2016 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.common.collect.ImmutableSortedMap;
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.actions.ArtifactRoot;
-import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder;
-import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory;
-import com.google.devtools.build.lib.analysis.RuleContext;
-import com.google.devtools.build.lib.analysis.Runfiles;
-import com.google.devtools.build.lib.analysis.RunfilesProvider;
-import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode;
-import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider;
-import com.google.devtools.build.lib.rules.cpp.CcCompilationHelper.CompilationInfo;
-import com.google.devtools.build.lib.rules.cpp.CcLinkingHelper.LinkingInfo;
-import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration;
-import com.google.devtools.build.lib.syntax.Type;
-import com.google.devtools.build.lib.vfs.Path;
-import com.google.devtools.build.lib.vfs.PathFragment;
-import java.util.ArrayList;
-import java.util.Arrays;
-
-/**
- * An inclusion library that maps header files into a different directory. This
- * is mostly used for third party libraries that have version-specific sub-directories,
- * and also for libraries that provide architecture-dependent header files.
- * In both cases, we want normal code to be able to include files without requiring
- * the version number or the architecture name in the include statement.
- *
- * <p>Example: a <code>cc_inc_library</code> rule in
- * <code>third_party/foo</code> has the name <code>bar</code>. It will create a
- * symlink in <code>include_directory/third_party/foo/bar/third_party/foo</code>
- * pointing to <code>third_party/foo/1.0</code>. This results in the include
- * directory <code>include_directory/third_party/foo/bar</code> to be used for
- * compilations, which makes inclusions like
- * <code>#include "third_party/foo/header.h"</code> work.
- */
-public abstract class CcIncLibrary implements RuleConfiguredTargetFactory {
-
- private final CppSemantics semantics;
-
- protected CcIncLibrary(CppSemantics semantics) {
- this.semantics = semantics;
- }
-
- @Override
- public ConfiguredTarget create(final RuleContext ruleContext)
- throws RuleErrorException, InterruptedException {
- CcToolchainProvider ccToolchain =
- CppHelper.getToolchainUsingDefaultCcToolchainAttribute(ruleContext);
- FeatureConfiguration featureConfiguration =
- CcCommon.configureFeatures(ruleContext, ccToolchain);
- PathFragment packageFragment = ruleContext.getPackageDirectory();
-
- // The rule needs a unique location for the include directory, which doesn't conflict with any
- // other rule. For that reason, the include directory is at:
- // configuration/package_name/_/target_name
- // And then the symlink is placed at:
- // configuration/package_name/_/target_name/package_name
- // So that these inclusions can be resolved correctly:
- // #include "package_name/a.h"
- //
- // The target of the symlink is:
- // package_name/targetPrefix/
- // All declared header files must be below that directory.
- String expandedIncSymlinkAttr = ruleContext.attributes().get("prefix", Type.STRING);
-
- // We use an additional "_" directory here to avoid conflicts between this and previous Blaze
- // versions. Previous Blaze versions created a directory symlink; the new version does not
- // detect that the output directory isn't a directory, and tries to put the symlinks into what
- // is actually a symlink into the source tree.
- PathFragment includeDirectory = PathFragment.create("_")
- .getRelative(ruleContext.getTarget().getName());
- ArtifactRoot configIncludeDirectory =
- ruleContext.getConfiguration().getIncludeDirectory(ruleContext.getRule().getRepository());
- PathFragment includePath =
- configIncludeDirectory
- .getExecPath()
- .getRelative(packageFragment)
- .getRelative(includeDirectory);
- Path includeRoot =
- configIncludeDirectory.getRoot().getRelative(packageFragment).getRelative(includeDirectory);
-
- // For every source artifact, we compute a virtual artifact that is below the include directory.
- // These are used for include checking.
- if (!PathFragment.isNormalized(expandedIncSymlinkAttr)) {
- ruleContext.attributeWarning("prefix", "should not contain '.' or '..' elements");
- }
- PathFragment prefixFragment = packageFragment.getRelative(expandedIncSymlinkAttr);
- ImmutableSortedMap.Builder<Artifact, Artifact> virtualArtifactMapBuilder =
- ImmutableSortedMap.orderedBy(Artifact.EXEC_PATH_COMPARATOR);
- ImmutableList<Artifact> hdrs = ruleContext.getPrerequisiteArtifacts("hdrs", Mode.TARGET).list();
- for (Artifact src : hdrs) {
- // All declared header files must start with package/targetPrefix.
- if (!src.getRootRelativePath().startsWith(prefixFragment)) {
- ruleContext.attributeError("hdrs", src + " does not start with '"
- + prefixFragment.getPathString() + "'");
- return null;
- }
-
- // Remove the targetPrefix from within the exec path of the source file, and prepend the
- // unique directory prefix, e.g.:
- // third_party/foo/1.2/bar/a.h -> third_party/foo/name/third_party/foo/bar/a.h
- PathFragment suffix = src.getRootRelativePath().relativeTo(prefixFragment);
- PathFragment virtualPath = includeDirectory.getRelative(packageFragment)
- .getRelative(suffix);
-
- // These virtual artifacts have the symlink action as generating action.
- Artifact virtualArtifact =
- ruleContext.getPackageRelativeArtifact(virtualPath, configIncludeDirectory);
- virtualArtifactMapBuilder.put(virtualArtifact, src);
- }
- ImmutableSortedMap<Artifact, Artifact> virtualArtifactMap = virtualArtifactMapBuilder.build();
- ruleContext.registerAction(
- new CreateIncSymlinkAction(ruleContext.getActionOwner(), virtualArtifactMap, includeRoot));
- FdoSupportProvider fdoSupport =
- CppHelper.getFdoSupportUsingDefaultCcToolchainAttribute(ruleContext);
- CompilationInfo compilationInfo =
- new CcCompilationHelper(
- ruleContext, semantics, featureConfiguration, ccToolchain, fdoSupport)
- .addIncludeDirs(Arrays.asList(includePath))
- .addPublicHeaders(virtualArtifactMap.keySet())
- .addDeps(ruleContext.getPrerequisites("deps", Mode.TARGET))
- .compile();
- LinkingInfo linkingInfo =
- new CcLinkingHelper(
- ruleContext,
- semantics,
- featureConfiguration,
- ccToolchain,
- fdoSupport,
- ruleContext.getConfiguration())
- .addDeps(ruleContext.getPrerequisites("deps", Mode.TARGET))
- .link(
- compilationInfo.getCcCompilationOutputs(), compilationInfo.getCcCompilationInfo());
-
- // cc_inc_library doesn't compile any file - no compilation outputs available.
- InstrumentedFilesProvider instrumentedFilesProvider =
- new CcCommon(ruleContext).getInstrumentedFilesProvider(
- new ArrayList<Artifact>(),
- /*withBaselineCoverage=*/true);
-
- return new RuleConfiguredTargetBuilder(ruleContext)
- .addProviders(compilationInfo.getProviders())
- .addProviders(linkingInfo.getProviders())
- .addSkylarkTransitiveInfo(CcSkylarkApiProvider.NAME, new CcSkylarkApiProvider())
- .addOutputGroups(
- CcCommon.mergeOutputGroups(
- ImmutableList.of(compilationInfo.getOutputGroups(), linkingInfo.getOutputGroups())))
- .add(InstrumentedFilesProvider.class, instrumentedFilesProvider)
- .add(RunfilesProvider.class, RunfilesProvider.simple(Runfiles.EMPTY))
- .build();
- }
-}
-
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcIncLibraryRule.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcIncLibraryRule.java
deleted file mode 100644
index b6916a86b7..0000000000
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcIncLibraryRule.java
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2016 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 static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
-import static com.google.devtools.build.lib.syntax.Type.STRING;
-
-import com.google.devtools.build.lib.analysis.BaseRuleClasses;
-import com.google.devtools.build.lib.analysis.RuleDefinition;
-import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
-import com.google.devtools.build.lib.packages.RuleClass;
-import com.google.devtools.build.lib.packages.RuleClass.Builder;
-import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
-
-/**
- * Rule definition for the cc_inc_library class.
- */
-public class CcIncLibraryRule implements RuleDefinition {
- @Override
- public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
- return builder
- /*<!-- #BLAZE_RULE(cc_inc_library).ATTRIBUTE(prefix) -->
- A prefix for this rule.
- This prefix is the directory that is removed from the beginning of all
- declared header files. The relative paths of all files have to start with
- this prefix. If no trailing slash is present, it is added automatically.
- <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
- .add(attr("prefix", STRING))
- /*<!-- #BLAZE_RULE(cc_inc_library).ATTRIBUTE(hdrs) -->
- A list of header files.
- These are the header files that are exported by this rule. The relative
- paths of all files have to start with the prefix, in the sense that they
- have to be below the directory indicated by the prefix. Only header files
- are allowed.
- <!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
- .add(
- attr("hdrs", LABEL_LIST)
- .mandatory()
- .nonEmpty()
- .orderIndependent()
- .direct_compile_time_input()
- .allowedFileTypes(CppFileTypes.CPP_HEADER))
- .build();
- }
-
- @Override
- public Metadata getMetadata() {
- return RuleDefinition.Metadata.builder()
- .name("$cc_inc_library")
- .ancestors(BaseRuleClasses.RuleBase.class)
- .type(RuleClassType.ABSTRACT)
- .build();
- }
-}