From fb20d20580456280b0e64162fdbe86dafca75388 Mon Sep 17 00:00:00 2001 From: elenairina Date: Wed, 9 Aug 2017 15:03:30 +0200 Subject: Add reexports to cc rules and cc_shared_library and cc_static_library semantics Relevant document: https://docs.google.com/document/d/1d4SPgVX-OTCiEK_l24DNWiFlT14XS5ZxD7XhttFbvrI/edit PiperOrigin-RevId: 164715084 --- .../lib/bazel/rules/cpp/BazelCcSharedLibrary.java | 26 +++++++++++ .../bazel/rules/cpp/BazelCcSharedLibraryRule.java | 49 +++++++++++++++++++++ .../lib/bazel/rules/cpp/BazelCcStaticLibrary.java | 26 +++++++++++ .../bazel/rules/cpp/BazelCcStaticLibraryRule.java | 50 ++++++++++++++++++++++ .../lib/bazel/rules/cpp/BazelCppRuleClasses.java | 3 ++ .../build/lib/rules/cpp/CcSharedLibrary.java | 37 ++++++++++++++++ .../build/lib/rules/cpp/CcStaticLibrary.java | 37 ++++++++++++++++ 7 files changed, 228 insertions(+) create mode 100644 src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcSharedLibrary.java create mode 100644 src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcSharedLibraryRule.java create mode 100644 src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcStaticLibrary.java create mode 100644 src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcStaticLibraryRule.java create mode 100644 src/main/java/com/google/devtools/build/lib/rules/cpp/CcSharedLibrary.java create mode 100644 src/main/java/com/google/devtools/build/lib/rules/cpp/CcStaticLibrary.java (limited to 'src/main/java/com/google/devtools/build') diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcSharedLibrary.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcSharedLibrary.java new file mode 100644 index 0000000000..05a65ea18c --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcSharedLibrary.java @@ -0,0 +1,26 @@ +// 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.bazel.rules.cpp; + +import com.google.devtools.build.lib.rules.cpp.CcSharedLibrary; + +/** + * {@code cc_shared_library} rule with Bazel semantics. + */ +public class BazelCcSharedLibrary extends CcSharedLibrary { + public BazelCcSharedLibrary() { + super(BazelCppSemantics.INSTANCE); + } +} diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcSharedLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcSharedLibraryRule.java new file mode 100644 index 0000000000..8143a6caa3 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcSharedLibraryRule.java @@ -0,0 +1,49 @@ +// 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.bazel.rules.cpp; + +import static com.google.devtools.build.lib.bazel.rules.cpp.BazelCppRuleClasses.DEPS_ALLOWED_RULES; +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_LIST; + +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.bazel.rules.cpp.BazelCppRuleClasses.CcBaseRule; +import com.google.devtools.build.lib.packages.RuleClass; +import com.google.devtools.build.lib.packages.RuleClass.Builder; + +/** Rule definition for the cc_shared_library rule. */ +public final class BazelCcSharedLibraryRule implements RuleDefinition { + @Override + public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { + return builder + .add(attr("reexport_deps", LABEL_LIST) + .allowedRuleClasses(DEPS_ALLOWED_RULES) + .allowedFileTypes()) + .add(attr("linkopts", STRING_LIST)) + .build(); + } + + @Override + public Metadata getMetadata() { + return RuleDefinition.Metadata.builder() + .name("cc_shared_library") + .ancestors(CcBaseRule.class, BaseRuleClasses.MakeVariableExpandingRule.class) + .factoryClass(BazelCcSharedLibrary.class) + .build(); + } +} diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcStaticLibrary.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcStaticLibrary.java new file mode 100644 index 0000000000..d7a9c2fc6e --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcStaticLibrary.java @@ -0,0 +1,26 @@ +// 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.bazel.rules.cpp; + +import com.google.devtools.build.lib.rules.cpp.CcStaticLibrary; + +/** + * {@code cc_static_library} rule with Bazel semantics. + */ +public class BazelCcStaticLibrary extends CcStaticLibrary { + public BazelCcStaticLibrary() { + super(BazelCppSemantics.INSTANCE); + } +} diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcStaticLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcStaticLibraryRule.java new file mode 100644 index 0000000000..a05f4423df --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcStaticLibraryRule.java @@ -0,0 +1,50 @@ +// 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.bazel.rules.cpp; + +import static com.google.devtools.build.lib.bazel.rules.cpp.BazelCppRuleClasses.DEPS_ALLOWED_RULES; +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_LIST; + +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.bazel.rules.cpp.BazelCppRuleClasses.CcBaseRule; +import com.google.devtools.build.lib.packages.RuleClass; +import com.google.devtools.build.lib.packages.RuleClass.Builder; + +/** Rule definition for the cc_static_library rule. */ +public final class BazelCcStaticLibraryRule implements RuleDefinition { + @Override + public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { + return builder + .add( + attr("reexport_deps", LABEL_LIST) + .allowedRuleClasses(DEPS_ALLOWED_RULES) + .allowedFileTypes()) + .add(attr("linkopts", STRING_LIST)) + .build(); + } + + @Override + public Metadata getMetadata() { + return RuleDefinition.Metadata.builder() + .name("cc_shared_library") + .ancestors(CcBaseRule.class, BaseRuleClasses.MakeVariableExpandingRule.class) + .factoryClass(BazelCcStaticLibrary.class) + .build(); + } +} diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java index d8bd7f7697..206e439b0f 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java @@ -339,6 +339,9 @@ public class BazelCppRuleClasses { .allowedRuleClasses(DEPS_ALLOWED_RULES) .allowedFileTypes(CppFileTypes.LINKER_SCRIPT) .skipAnalysisTimeFileTypeCheck()) + .add(attr("reexport_deps", LABEL_LIST) + .allowedRuleClasses(DEPS_ALLOWED_RULES) + .allowedFileTypes()) /* Add these flags to the C++ linker command. Subject to "Make" variable substitution, diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSharedLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSharedLibrary.java new file mode 100644 index 0000000000..289c4fdb4f --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSharedLibrary.java @@ -0,0 +1,37 @@ +// Copyright 2014 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.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; + +/** + * A ConfiguredTarget for cc_shared_library rules. + */ +public abstract class CcSharedLibrary implements RuleConfiguredTargetFactory { + private final CppSemantics semantics; + + protected CcSharedLibrary(CppSemantics semantics) { + this.semantics = semantics; + } + + @Override + public ConfiguredTarget create(RuleContext context) + throws RuleErrorException, InterruptedException { + return new RuleConfiguredTargetBuilder(context).build(); + } +} \ No newline at end of file diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcStaticLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcStaticLibrary.java new file mode 100644 index 0000000000..d7c2006a0d --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcStaticLibrary.java @@ -0,0 +1,37 @@ +// 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.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; + +/** + * A ConfiguredTarget for cc_static_library rules. + */ +public abstract class CcStaticLibrary implements RuleConfiguredTargetFactory { + private final CppSemantics semantics; + + protected CcStaticLibrary(CppSemantics semantics) { + this.semantics = semantics; + } + + @Override + public ConfiguredTarget create(RuleContext context) + throws RuleErrorException, InterruptedException { + return new RuleConfiguredTargetBuilder(context).build(); + } +} \ No newline at end of file -- cgit v1.2.3