Skip to content

Commit

Permalink
Automated rollback of commit f137cea.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

See linked bug.

*** Original change description ***

C++: Refactors PyWrapCc to make it easier to migrate to Skylark

RELNOTES:none
PiperOrigin-RevId: 199702630
  • Loading branch information
janakdr authored and Copybara-Service committed Jun 7, 2018
1 parent 5e89362 commit 6afc2eb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.devtools.build.lib.analysis.RunfilesProvider;
import com.google.devtools.build.lib.analysis.RunfilesSupport;
import com.google.devtools.build.lib.analysis.ShToolchain;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.LauncherFileWriteAction;
import com.google.devtools.build.lib.analysis.actions.LauncherFileWriteAction.LaunchInfo;
Expand All @@ -41,9 +40,6 @@
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.rules.cpp.AbstractCcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcLinkParams;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.rules.python.PyCommon;
import com.google.devtools.build.lib.rules.python.PythonConfiguration;
import com.google.devtools.build.lib.rules.python.PythonSemantics;
Expand Down Expand Up @@ -74,10 +70,7 @@ public void validate(RuleContext ruleContext, PyCommon common) {

@Override
public void collectRunfilesForBinary(
RuleContext ruleContext,
Runfiles.Builder builder,
PyCommon common,
CcLinkingInfo ccLinkingInfo) {
RuleContext ruleContext, Runfiles.Builder builder, PyCommon common) {
addRuntime(ruleContext, builder);
}

Expand Down Expand Up @@ -135,7 +128,7 @@ public Artifact getPythonTemplateMainArtifact(RuleContext ruleContext, Artifact
public Artifact createExecutable(
RuleContext ruleContext,
PyCommon common,
CcLinkingInfo ccLinkingInfo,
AbstractCcLinkParamsStore ccLinkParamsStore,
NestedSet<PathFragment> imports)
throws InterruptedException {
String main = common.determineMainExecutableSource(/*withWorkspaceName=*/ true);
Expand Down Expand Up @@ -361,20 +354,4 @@ private static String getPythonBinary(
return pythonBinary;
}

@Override
public CcLinkingInfo buildCcLinkingInfoProvider(
Iterable<? extends TransitiveInfoCollection> deps) {
CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create();
AbstractCcLinkParamsStore ccLinkParamsStore =
new AbstractCcLinkParamsStore() {
@Override
protected void collect(
CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) {
builder.addTransitiveTargets(deps, CcLinkParamsStore.TO_LINK_PARAMS);
}
};
// TODO(plf): return empty CcLinkingInfo.
ccLinkingInfoBuilder.setCcLinkParamsStore(new CcLinkParamsStore(ccLinkParamsStore));
return ccLinkingInfoBuilder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
import com.google.devtools.build.lib.analysis.RunfilesSupport;
import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.rules.cpp.AbstractCcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcCommon.CcFlagsSupplier;
import com.google.devtools.build.lib.rules.cpp.CcLinkParams;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.vfs.PathFragment;
Expand Down Expand Up @@ -57,6 +60,7 @@ public ConfiguredTarget create(RuleContext ruleContext)
static RuleConfiguredTargetBuilder init(RuleContext ruleContext, PythonSemantics semantics,
PyCommon common) throws InterruptedException {
ruleContext.initConfigurationMakeVariableContext(new CcFlagsSupplier(ruleContext));
AbstractCcLinkParamsStore ccLinkParamsStore = initializeCcLinkParamStore(ruleContext);

List<Artifact> srcs = common.validateSrcs();
List<Artifact> allOutputs =
Expand All @@ -76,10 +80,9 @@ static RuleConfiguredTargetBuilder init(RuleContext ruleContext, PythonSemantics
return null;
}

CcLinkingInfo ccLinkingInfo =
semantics.buildCcLinkingInfoProvider(ruleContext.getPrerequisites("deps", Mode.TARGET));

Runfiles commonRunfiles = collectCommonRunfiles(ruleContext, common, semantics, ccLinkingInfo);
Artifact realExecutable =
semantics.createExecutable(ruleContext, common, ccLinkParamsStore, imports);
Runfiles commonRunfiles = collectCommonRunfiles(ruleContext, common, semantics);

Runfiles.Builder defaultRunfilesBuilder = new Runfiles.Builder(
ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles())
Expand Down Expand Up @@ -121,22 +124,19 @@ static RuleConfiguredTargetBuilder init(RuleContext ruleContext, PythonSemantics

semantics.postInitBinary(ruleContext, runfilesSupport, common);

Artifact realExecutable =
semantics.createExecutable(ruleContext, common, ccLinkingInfo, imports);
CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create();
ccLinkingInfoBuilder.setCcLinkParamsStore(new CcLinkParamsStore(ccLinkParamsStore));

return builder
.setFilesToBuild(common.getFilesToBuild())
.add(RunfilesProvider.class, runfilesProvider)
.setRunfilesSupport(runfilesSupport, realExecutable)
.addNativeDeclaredProvider(ccLinkingInfoBuilder.build())
.add(PythonImportsProvider.class, new PythonImportsProvider(imports));
}

private static Runfiles collectCommonRunfiles(
RuleContext ruleContext,
PyCommon common,
PythonSemantics semantics,
CcLinkingInfo ccLinkingInfo)
throws InterruptedException {
private static Runfiles collectCommonRunfiles(RuleContext ruleContext, PyCommon common,
PythonSemantics semantics) {
Runfiles.Builder builder = new Runfiles.Builder(
ruleContext.getWorkspaceName(), ruleContext.getConfiguration().legacyExternalRunfiles());
builder.addArtifact(common.getExecutable());
Expand All @@ -152,7 +152,20 @@ private static Runfiles collectCommonRunfiles(
|| ruleContext.attributes().get("legacy_create_init", Type.BOOLEAN)) {
builder.setEmptyFilesSupplier(PythonUtils.GET_INIT_PY_FILES);
}
semantics.collectRunfilesForBinary(ruleContext, builder, common, ccLinkingInfo);
semantics.collectRunfilesForBinary(ruleContext, builder, common);
return builder.build();
}

private static AbstractCcLinkParamsStore initializeCcLinkParamStore(
final RuleContext ruleContext) {
return new AbstractCcLinkParamsStore() {
@Override
protected void collect(
CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) {
builder.addTransitiveTargets(
ruleContext.getPrerequisites("deps", Mode.TARGET),
CcLinkParamsStore.TO_LINK_PARAMS);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.rules.cpp.AbstractCcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcLinkParams;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -60,6 +64,17 @@ public ConfiguredTarget create(final RuleContext ruleContext)
NestedSetBuilder.wrap(Order.STABLE_ORDER, allOutputs);
common.addPyExtraActionPseudoAction();

AbstractCcLinkParamsStore ccLinkParamsStore =
new AbstractCcLinkParamsStore() {
@Override
protected void collect(
CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) {
builder.addTransitiveTargets(
ruleContext.getPrerequisites("deps", Mode.TARGET),
CcLinkParamsStore.TO_LINK_PARAMS);
}
};

NestedSet<PathFragment> imports = common.collectImports(ruleContext, semantics);
if (ruleContext.hasErrors()) {
return null;
Expand All @@ -78,11 +93,13 @@ public ConfiguredTarget create(final RuleContext ruleContext)
RuleConfiguredTargetBuilder builder = new RuleConfiguredTargetBuilder(ruleContext);
common.addCommonTransitiveInfoProviders(builder, semantics, filesToBuild);

CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create();
ccLinkingInfoBuilder.setCcLinkParamsStore(new CcLinkParamsStore(ccLinkParamsStore));

return builder
.setFilesToBuild(filesToBuild)
.addNativeDeclaredProvider(
semantics.buildCcLinkingInfoProvider(ruleContext.getPrerequisites("deps", Mode.TARGET)))
.add(RunfilesProvider.class, RunfilesProvider.simple(runfilesBuilder.build()))
.addNativeDeclaredProvider(ccLinkingInfoBuilder.build())
.add(PythonImportsProvider.class, new PythonImportsProvider(imports))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.Runfiles;
import com.google.devtools.build.lib.analysis.RunfilesSupport;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector.InstrumentationSpec;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.rules.cpp.AbstractCcLinkParamsStore;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.Collection;
import java.util.List;
Expand All @@ -37,13 +36,10 @@ public interface PythonSemantics {
*/
void validate(RuleContext ruleContext, PyCommon common);

/** Extends for the default and data runfiles of {@code py_binary} rules with custom elements. */
void collectRunfilesForBinary(
RuleContext ruleContext,
Runfiles.Builder builder,
PyCommon common,
CcLinkingInfo ccLinkingInfo)
throws InterruptedException;
/**
* Extends for the default and data runfiles of {@code py_binary} rules with custom elements.
*/
void collectRunfilesForBinary(RuleContext ruleContext, Runfiles.Builder builder, PyCommon common);

/** Extends the default runfiles of {@code py_binary} rules with custom elements. */
void collectDefaultRunfilesForBinary(RuleContext ruleContext, Runfiles.Builder builder)
Expand Down Expand Up @@ -76,7 +72,7 @@ Collection<Artifact> precompiledPythonFiles(
Artifact createExecutable(
RuleContext ruleContext,
PyCommon common,
CcLinkingInfo ccLinkingInfo,
AbstractCcLinkParamsStore ccLinkParamsStore,
NestedSet<PathFragment> imports)
throws InterruptedException;

Expand All @@ -86,6 +82,4 @@ Artifact createExecutable(
*/
void postInitBinary(RuleContext ruleContext, RunfilesSupport runfilesSupport,
PyCommon common) throws InterruptedException;

CcLinkingInfo buildCcLinkingInfoProvider(Iterable<? extends TransitiveInfoCollection> deps);
}

0 comments on commit 6afc2eb

Please sign in to comment.