use of com.facebook.buck.rules.args.Arg in project buck by facebook.
the class AbstractPrebuiltCxxLibraryGroupDescription method getSharedLinkArgs.
/**
* @return the link args formed from the user-provided shared link line after resolving library
* macro references.
*/
private Iterable<Arg> getSharedLinkArgs(BuildTarget target, ImmutableMap<String, SourcePath> libs, ImmutableList<String> args) {
ImmutableList.Builder<Arg> builder = ImmutableList.builder();
for (String arg : args) {
Optional<Pair<String, String>> libRef = getLibRef(ImmutableSet.of(LIB_MACRO, REL_LIB_MACRO), arg);
if (libRef.isPresent()) {
SourcePath lib = libs.get(libRef.get().getSecond());
if (lib == null) {
throw new HumanReadableException("%s: library \"%s\" (in \"%s\") must refer to keys in the `sharedLibs` parameter", target, libRef.get().getSecond(), arg);
}
Arg libArg;
if (libRef.get().getFirst().equals(LIB_MACRO)) {
libArg = SourcePathArg.of(lib);
} else if (libRef.get().getFirst().equals(REL_LIB_MACRO)) {
if (!(lib instanceof PathSourcePath)) {
throw new HumanReadableException("%s: can only link prebuilt DSOs without sonames", target);
}
libArg = new RelativeLinkArg((PathSourcePath) lib);
} else {
throw new IllegalStateException();
}
builder.add(libArg);
} else {
builder.add(StringArg.of(arg));
}
}
return builder.build();
}
use of com.facebook.buck.rules.args.Arg in project buck by facebook.
the class ReDexStepTest method constructorArgsAreUsedToCreateShellCommand.
@Test
public void constructorArgsAreUsedToCreateShellCommand() {
Path workingDirectory = Paths.get("/where/the/code/is");
List<String> redexBinaryArgs = ImmutableList.of("/usr/bin/redex");
Map<String, String> redexEnvironmentVariables = ImmutableMap.of("REDEX_DEBUG", "1");
Path inputApkPath = Paths.get("buck-out/gen/app.apk.zipalign");
Path outputApkPath = Paths.get("buck-out/gen/app.apk");
Path keystorePath = Paths.get("keystores/debug.keystore");
KeystoreProperties keystoreProperties = new KeystoreProperties(keystorePath, "storepass", "keypass", "alias");
Supplier<KeystoreProperties> keystorePropertiesSupplier = Suppliers.ofInstance(keystoreProperties);
Path redexConfigPath = Paths.get("redex/redex-config.json");
Optional<Path> redexConfig = Optional.of(redexConfigPath);
ImmutableList<Arg> redexExtraArgs = ImmutableList.of(StringArg.of("foo"), StringArg.of("bar"));
Path proguardMap = Paths.get("buck-out/gen/app/__proguard__/mapping.txt");
Path proguardConfig = Paths.get("app.proguard.config");
Path seeds = Paths.get("buck-out/gen/app/__proguard__/seeds.txt");
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
ReDexStep redex = new ReDexStep(workingDirectory, redexBinaryArgs, redexEnvironmentVariables, inputApkPath, outputApkPath, keystorePropertiesSupplier, redexConfig, redexExtraArgs, proguardMap, proguardConfig, seeds, pathResolver);
assertEquals("redex", redex.getShortName());
AndroidPlatformTarget androidPlatform = EasyMock.createMock(AndroidPlatformTarget.class);
Path sdkDirectory = Paths.get("/Users/user/android-sdk-macosx");
EasyMock.expect(androidPlatform.getSdkDirectory()).andReturn(Optional.of(sdkDirectory));
EasyMock.replay(androidPlatform);
ExecutionContext context = TestExecutionContext.newBuilder().setAndroidPlatformTargetSupplier(Suppliers.ofInstance(androidPlatform)).build();
assertEquals(ImmutableMap.of("ANDROID_SDK", sdkDirectory.toString(), "REDEX_DEBUG", "1"), redex.getEnvironmentVariables(context));
EasyMock.verify(androidPlatform);
assertEquals(ImmutableList.of("/usr/bin/redex", "--config", redexConfigPath.toString(), "--sign", "--keystore", keystorePath.toString(), "--keyalias", "alias", "--keypass", "keypass", "--proguard-map", proguardMap.toString(), "-P", proguardConfig.toString(), "--keep", seeds.toString(), "--out", outputApkPath.toString(), "foo", "bar", inputApkPath.toString()), redex.getShellCommandInternal(context));
}
use of com.facebook.buck.rules.args.Arg in project buck by facebook.
the class AbstractPrebuiltCxxLibraryGroupDescription method getStaticLinkArgs.
/**
* @return the link args formed from the user-provided static link line after resolving library
* macro references.
*/
private Iterable<Arg> getStaticLinkArgs(BuildTarget target, ImmutableList<SourcePath> libs, ImmutableList<String> args) {
ImmutableList.Builder<Arg> builder = ImmutableList.builder();
for (String arg : args) {
Optional<Pair<String, String>> libRef = getLibRef(ImmutableSet.of(LIB_MACRO), arg);
if (libRef.isPresent()) {
int index;
try {
index = Integer.parseInt(libRef.get().getSecond());
} catch (NumberFormatException e) {
throw new HumanReadableException("%s: ", target);
}
if (index < 0 || index >= libs.size()) {
throw new HumanReadableException("%s: ", target);
}
builder.add(SourcePathArg.of(libs.get(index)));
} else {
builder.add(StringArg.of(arg));
}
}
return builder.build();
}
use of com.facebook.buck.rules.args.Arg in project buck by facebook.
the class OcamlBuildRulesGenerator method generateSingleMLBytecodeCompilation.
/**
* Compiles a single .ml file to a .cmo
*/
private void generateSingleMLBytecodeCompilation(Map<Path, ImmutableSortedSet<BuildRule>> sourceToRule, ImmutableList.Builder<SourcePath> cmoFiles, Path mlSource, ImmutableMap<Path, ImmutableList<Path>> sources, ImmutableList<Path> cycleDetector) {
ImmutableList<Path> newCycleDetector = ImmutableList.<Path>builder().addAll(cycleDetector).add(mlSource).build();
if (cycleDetector.contains(mlSource)) {
throw new HumanReadableException("Dependency cycle detected: %s", Joiner.on(" -> ").join(newCycleDetector));
}
if (sourceToRule.containsKey(mlSource)) {
return;
}
ImmutableSortedSet.Builder<BuildRule> depsBuilder = ImmutableSortedSet.naturalOrder();
if (sources.containsKey(mlSource)) {
for (Path dep : checkNotNull(sources.get(mlSource))) {
generateSingleMLBytecodeCompilation(sourceToRule, cmoFiles, dep, sources, newCycleDetector);
depsBuilder.addAll(checkNotNull(sourceToRule.get(dep)));
}
}
ImmutableSortedSet<BuildRule> deps = depsBuilder.build();
String name = mlSource.toFile().getName();
BuildTarget buildTarget = createMLBytecodeCompileBuildTarget(params.getBuildTarget(), name);
BuildRuleParams compileParams = params.withBuildTarget(buildTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().add(this.cleanRule).addAll(params.getDeclaredDeps().get()).addAll(deps).addAll(ocamlContext.getBytecodeCompileDeps()).addAll(cCompiler.getDeps(ruleFinder)).build()), params.getExtraDeps());
String outputFileName = getMLBytecodeOutputName(name);
Path outputPath = ocamlContext.getCompileBytecodeOutputDir().resolve(outputFileName);
final ImmutableList<Arg> compileFlags = getCompileFlags(/* isBytecode */
true, /* excludeDeps */
false);
BuildRule compileBytecode = new OcamlMLCompile(compileParams, new OcamlMLCompileStep.Args(params.getProjectFilesystem()::resolve, cCompiler.getEnvironment(pathResolver), cCompiler.getCommandPrefix(pathResolver), ocamlContext.getOcamlBytecodeCompiler().get(), ocamlContext.getOcamlInteropIncludesDir(), outputPath, mlSource, compileFlags));
resolver.addToIndex(compileBytecode);
sourceToRule.put(mlSource, ImmutableSortedSet.<BuildRule>naturalOrder().add(compileBytecode).addAll(deps).build());
if (!outputFileName.endsWith(OcamlCompilables.OCAML_CMI)) {
cmoFiles.add(compileBytecode.getSourcePathToOutput());
}
}
use of com.facebook.buck.rules.args.Arg in project buck by facebook.
the class OcamlBuildRulesGenerator method generateNativeLinking.
/**
* Links the .cmx files generated by the native compilation
*/
private BuildRule generateNativeLinking(ImmutableList<SourcePath> allInputs) {
BuildRuleParams linkParams = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(allInputs)).addAll(ocamlContext.getNativeLinkableInput().getArgs().stream().flatMap(arg -> arg.getDeps(ruleFinder).stream()).iterator()).addAll(ocamlContext.getCLinkableInput().getArgs().stream().flatMap(arg -> arg.getDeps(ruleFinder).stream()).iterator()).addAll(cxxCompiler.getDeps(ruleFinder)).build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
ImmutableList.Builder<Arg> flags = ImmutableList.builder();
flags.addAll(ocamlContext.getFlags());
flags.addAll(StringArg.from(ocamlContext.getCommonCLinkerFlags()));
OcamlLink link = new OcamlLink(linkParams, allInputs, cxxCompiler.getEnvironment(pathResolver), cxxCompiler.getCommandPrefix(pathResolver), ocamlContext.getOcamlCompiler().get(), flags.build(), ocamlContext.getOcamlInteropIncludesDir(), ocamlContext.getNativeOutput(), ocamlContext.getNativePluginOutput(), ocamlContext.getNativeLinkableInput().getArgs(), ocamlContext.getCLinkableInput().getArgs(), ocamlContext.isLibrary(), /* isBytecode */
false, buildNativePlugin);
resolver.addToIndex(link);
return link;
}
Aggregations