From 4a11a0207b416299e76b9c6cba740939b74c0e6b Mon Sep 17 00:00:00 2001 From: plf Date: Tue, 10 Jul 2018 09:57:06 -0700 Subject: [PATCH] C++: Exposes new parameters of C++ Skylark API. This will be needed by py_wrap_cc in a follow up CL. RELNOTES:none PiperOrigin-RevId: 203964457 --- .../lib/rules/cpp/CcCompilationInfo.java | 21 +++++++++++ .../build/lib/rules/cpp/CcLinkingHelper.java | 1 + .../build/lib/rules/cpp/CcLinkingInfo.java | 28 +++++++++++++- .../build/lib/rules/cpp/CcLinkingOutputs.java | 24 ++++++++++-- .../cpp/CcLinkingOutputsApi.java | 37 +++++++++++++++++++ .../skylarkbuildapi/cpp/LibraryToLinkApi.java | 2 +- .../skylarkbuildapi/cpp/LinkerInputApi.java | 10 +++++ .../skylarkbuildapi/cpp/LinkingInfoApi.java | 5 ++- 8 files changed, 120 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcLinkingOutputsApi.java diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationInfo.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationInfo.java index 9278bea09a6944..0e540b6106e33a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationInfo.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationInfo.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.rules.cpp; +import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.Artifact; @@ -127,4 +128,24 @@ public static ImmutableList getCcCompilationContexts( } return ccCompilationContextsBuilder.build(); } + + @Override + public boolean equals(Object otherObject) { + if (!(otherObject instanceof CcCompilationInfo)) { + return false; + } + CcCompilationInfo other = (CcCompilationInfo) otherObject; + if (this == other) { + return true; + } + if (!this.ccCompilationContext.equals(other.ccCompilationContext)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + return Objects.hashCode(ccCompilationContext); + } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java index 36b41fdfddd63d..e2448cd425c46f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java @@ -106,6 +106,7 @@ public Map> getOutputGroups() { return outputGroups; } + @Override public CcLinkingOutputs getCcLinkingOutputs() { return linkingOutputs; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingInfo.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingInfo.java index 91df5b6aacb288..4f087f374afb1f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingInfo.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingInfo.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.rules.cpp; +import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; @@ -109,8 +110,11 @@ protected CcLinkingInfo createInstanceFromSkylark( }; private final CcLinkParamsStore ccLinkParamsStore; - private final CcRunfiles ccRunfiles; - private final CcDynamicLibrariesForRuntime ccDynamicLibrariesForRuntime; + // TODO(b/111289526): These providers are not useful. All the information they provide can be + // obtained from CcLinkParams. CcRunfiles is already dead code and can be removed. + // CcDynamicLibrariesForRuntime is not dead code yet. + @Deprecated private final CcRunfiles ccRunfiles; + @Deprecated private final CcDynamicLibrariesForRuntime ccDynamicLibrariesForRuntime; @AutoCodec.Instantiator @VisibleForSerialization @@ -170,4 +174,24 @@ public CcLinkingInfo build() { return new CcLinkingInfo(ccLinkParamsStore, ccRunfiles, ccDynamicLibrariesForRuntime); } } + + @Override + public boolean equals(Object otherObject) { + if (!(otherObject instanceof CcLinkingInfo)) { + return false; + } + CcLinkingInfo other = (CcLinkingInfo) otherObject; + if (this == other) { + return true; + } + if (!this.ccLinkParamsStore.equals(other.ccLinkParamsStore)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + return Objects.hashCode(ccLinkParamsStore); + } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingOutputs.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingOutputs.java index a294a2dcb1db44..26115f8aa143d4 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingOutputs.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingOutputs.java @@ -21,6 +21,9 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.rules.cpp.Link.LinkingMode; import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink; +import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcLinkingOutputsApi; +import com.google.devtools.build.lib.skylarkbuildapi.cpp.LibraryToLinkApi; +import com.google.devtools.build.lib.syntax.SkylarkList; import com.google.devtools.build.lib.vfs.FileSystemUtils; import java.util.ArrayList; import java.util.HashSet; @@ -28,10 +31,8 @@ import java.util.List; import java.util.Set; -/** - * A structured representation of the link outputs of a C++ rule. - */ -public class CcLinkingOutputs { +/** A structured representation of the link outputs of a C++ rule. */ +public class CcLinkingOutputs implements CcLinkingOutputsApi { public static final CcLinkingOutputs EMPTY = new Builder().build(); @@ -66,14 +67,29 @@ private CcLinkingOutputs( this.dynamicLibrariesForRuntime = dynamicLibrariesForRuntime; } + @Override + public SkylarkList getSkylarkStaticLibraries() { + return SkylarkList.createImmutable(staticLibraries); + } + public ImmutableList getStaticLibraries() { return staticLibraries; } + @Override + public SkylarkList getSkylarkPicStaticLibraries() { + return SkylarkList.createImmutable(picStaticLibraries); + } + public ImmutableList getPicStaticLibraries() { return picStaticLibraries; } + @Override + public SkylarkList getSkylarkDynamicLibrariesForLinking() { + return SkylarkList.createImmutable(dynamicLibrariesForLinking); + } + public ImmutableList getDynamicLibrariesForLinking() { return dynamicLibrariesForLinking; } diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcLinkingOutputsApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcLinkingOutputsApi.java new file mode 100644 index 00000000000000..93d81e5af690a4 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcLinkingOutputsApi.java @@ -0,0 +1,37 @@ +// Copyright 2018 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.skylarkbuildapi.cpp; + +import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; +import com.google.devtools.build.lib.syntax.SkylarkList; + +/** Interface for a structured representation of the linking outputs of a C++ rule. */ +@SkylarkModule( + name = "CcLinkingOutputs", + category = SkylarkModuleCategory.BUILTIN, + documented = false, + doc = "Helper class containing CC compilation outputs.") +public interface CcLinkingOutputsApi { + @SkylarkCallable(name = "dynamic_libraries_for_linking", documented = false) + SkylarkList getSkylarkDynamicLibrariesForLinking(); + + @SkylarkCallable(name = "static_libraries", documented = false) + SkylarkList getSkylarkStaticLibraries(); + + @SkylarkCallable(name = "pic_static_libraries", documented = false) + SkylarkList getSkylarkPicStaticLibraries(); +} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LibraryToLinkApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LibraryToLinkApi.java index a8421654c76a24..ff3b6214d07f08 100644 --- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LibraryToLinkApi.java +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LibraryToLinkApi.java @@ -26,4 +26,4 @@ category = SkylarkModuleCategory.BUILTIN, documented = false, doc = "A library the user can link to.") -public interface LibraryToLinkApi {} +public interface LibraryToLinkApi extends LinkerInputApi {} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LinkerInputApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LinkerInputApi.java index 13707d21e6232a..3d33a7eb8ae601 100644 --- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LinkerInputApi.java +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LinkerInputApi.java @@ -16,14 +16,24 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; /** * Something that appears on the command line of the linker. Since we sometimes expand archive files * to their constituent object files, we need to keep information whether a certain file contains * embedded objects and if so, the list of the object files themselves. */ +@SkylarkModule( + name = "LinkerInputApi", + category = SkylarkModuleCategory.BUILTIN, + documented = false, + doc = "An input that appears in the command line of the linker.") public interface LinkerInputApi { /** Returns the artifact that is the input of the linker. */ @SkylarkCallable(name = "artifact", doc = "Artifact passed to the linker.") Artifact getArtifact(); + + @SkylarkCallable(name = "original_artifact", doc = "Artifact passed to the linker.") + Artifact getOriginalLibraryArtifact(); } diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LinkingInfoApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LinkingInfoApi.java index d572708906438b..6b72b92edeab14 100644 --- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LinkingInfoApi.java +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LinkingInfoApi.java @@ -30,5 +30,8 @@ public interface LinkingInfoApi { @SkylarkCallable(name = "cc_linking_info", documented = false) - public CcLinkingInfoApi getCcLinkingInfo(); + CcLinkingInfoApi getCcLinkingInfo(); + + @SkylarkCallable(name = "cc_linking_outputs", documented = false) + CcLinkingOutputsApi getCcLinkingOutputs(); }