Skip to content

Commit

Permalink
C++: Exposes new parameters of C++ Skylark API.
Browse files Browse the repository at this point in the history
This will be needed by py_wrap_cc in a follow up CL.

RELNOTES:none
PiperOrigin-RevId: 203964457
  • Loading branch information
oquenchil authored and Copybara-Service committed Jul 10, 2018
1 parent ccd7d76 commit 4a11a02
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -127,4 +128,24 @@ public static ImmutableList<CcCompilationContext> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public Map<String, NestedSet<Artifact>> getOutputGroups() {
return outputGroups;
}

@Override
public CcLinkingOutputs getCcLinkingOutputs() {
return linkingOutputs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@
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;
import java.util.LinkedHashSet;
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();

Expand Down Expand Up @@ -66,14 +67,29 @@ private CcLinkingOutputs(
this.dynamicLibrariesForRuntime = dynamicLibrariesForRuntime;
}

@Override
public SkylarkList<LibraryToLinkApi> getSkylarkStaticLibraries() {
return SkylarkList.createImmutable(staticLibraries);
}

public ImmutableList<LibraryToLink> getStaticLibraries() {
return staticLibraries;
}

@Override
public SkylarkList<LibraryToLinkApi> getSkylarkPicStaticLibraries() {
return SkylarkList.createImmutable(picStaticLibraries);
}

public ImmutableList<LibraryToLink> getPicStaticLibraries() {
return picStaticLibraries;
}

@Override
public SkylarkList<LibraryToLinkApi> getSkylarkDynamicLibrariesForLinking() {
return SkylarkList.createImmutable(dynamicLibrariesForLinking);
}

public ImmutableList<LibraryToLink> getDynamicLibrariesForLinking() {
return dynamicLibrariesForLinking;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<LibraryToLinkApi> getSkylarkDynamicLibrariesForLinking();

@SkylarkCallable(name = "static_libraries", documented = false)
SkylarkList<LibraryToLinkApi> getSkylarkStaticLibraries();

@SkylarkCallable(name = "pic_static_libraries", documented = false)
SkylarkList<LibraryToLinkApi> getSkylarkPicStaticLibraries();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 4a11a02

Please sign in to comment.