use of com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction in project bazel by bazelbuild.
the class BazelPythonSemantics method createExecutable.
@Override
public void createExecutable(RuleContext ruleContext, PyCommon common, CcLinkParamsStore ccLinkParamsStore, NestedSet<PathFragment> imports) throws InterruptedException {
String main = common.determineMainExecutableSource(/*withWorkspaceName=*/
true);
Artifact executable = common.getExecutable();
BazelPythonConfiguration config = ruleContext.getFragment(BazelPythonConfiguration.class);
String pythonBinary;
switch(common.getVersion()) {
case PY2:
pythonBinary = config.getPython2Path();
break;
case PY3:
pythonBinary = config.getPython3Path();
break;
default:
throw new IllegalStateException();
}
if (!ruleContext.getConfiguration().buildPythonZip()) {
ruleContext.registerAction(new TemplateExpansionAction(ruleContext.getActionOwner(), executable, STUB_TEMPLATE, ImmutableList.of(Substitution.of("%main%", main), Substitution.of("%python_binary%", pythonBinary), Substitution.of("%imports%", Joiner.on(":").join(imports)), Substitution.of("%workspace_name%", ruleContext.getWorkspaceName()), Substitution.of("%is_zipfile%", "False"), Substitution.of("%import_all%", config.getImportAllRepositories() ? "True" : "False")), true));
} else {
Artifact zipFile = getPythonZipArtifact(ruleContext, executable);
Artifact templateMain = getPythonTemplateMainArtifact(ruleContext, executable);
// The executable zip file will unzip itself into a tmp directory and then run from there
ruleContext.registerAction(new TemplateExpansionAction(ruleContext.getActionOwner(), templateMain, STUB_TEMPLATE, ImmutableList.of(Substitution.of("%main%", main), Substitution.of("%python_binary%", pythonBinary), Substitution.of("%imports%", Joiner.on(":").join(imports)), Substitution.of("%workspace_name%", ruleContext.getWorkspaceName()), Substitution.of("%is_zipfile%", "True"), Substitution.of("%import_all%", config.getImportAllRepositories() ? "True" : "False")), true));
ruleContext.registerAction(new SpawnAction.Builder().addInput(zipFile).addOutput(executable).setShellCommand("echo '#!/usr/bin/env python' | cat - " + zipFile.getExecPathString() + " > " + executable.getExecPathString()).useDefaultShellEnvironment().setMnemonic("BuildBinary").build(ruleContext));
}
}
use of com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction in project bazel by bazelbuild.
the class ReleaseBundlingSupport method registerGenerateRunnerScriptAction.
/**
* Registers an action to generate a runner script based on a template.
*/
ReleaseBundlingSupport registerGenerateRunnerScriptAction(Artifact runnerScript, Artifact ipaInput) {
ObjcConfiguration objcConfiguration = ObjcRuleClasses.objcConfiguration(ruleContext);
String escapedSimDevice = ShellUtils.shellEscape(objcConfiguration.getIosSimulatorDevice());
String escapedSdkVersion = ShellUtils.shellEscape(objcConfiguration.getIosSimulatorVersion().toString());
ImmutableList<Substitution> substitutions = ImmutableList.of(Substitution.of("%app_name%", ruleContext.getLabel().getName()), Substitution.of("%ipa_file%", ipaInput.getRunfilesPathString()), Substitution.of("%sim_device%", escapedSimDevice), Substitution.of("%sdk_version%", escapedSdkVersion), Substitution.of("%std_redirect_dylib_path%", attributes.stdRedirectDylib().getRunfilesPathString()));
ruleContext.registerAction(new TemplateExpansionAction(ruleContext.getActionOwner(), attributes.runnerScriptTemplate(), runnerScript, substitutions, true));
return this;
}
Aggregations