use of com.facebook.buck.rules.args.Arg in project buck by facebook.
the class OcamlBuildStep method executeMLBytecodeCompilation.
private StepExecutionResult executeMLBytecodeCompilation(ExecutionContext context, Path workingDirectory, ImmutableList<Path> sortedInput, ImmutableList.Builder<Path> linkerInputs) throws IOException, InterruptedException {
MakeCleanDirectoryStep mkDir = new MakeCleanDirectoryStep(filesystem, ocamlContext.getCompileBytecodeOutputDir());
StepExecutionResult mkDirExecutionResult = mkDir.execute(context);
if (!mkDirExecutionResult.isSuccess()) {
return mkDirExecutionResult;
}
for (Path inputOutput : sortedInput) {
String inputFileName = inputOutput.getFileName().toString();
String outputFileName = inputFileName.replaceFirst(OcamlCompilables.OCAML_ML_REGEX, OcamlCompilables.OCAML_CMO).replaceFirst(OcamlCompilables.OCAML_RE_REGEX, OcamlCompilables.OCAML_CMO).replaceFirst(OcamlCompilables.OCAML_MLI_REGEX, OcamlCompilables.OCAML_CMI).replaceFirst(OcamlCompilables.OCAML_REI_REGEX, OcamlCompilables.OCAML_CMI);
Path outputPath = ocamlContext.getCompileBytecodeOutputDir().resolve(outputFileName);
if (!outputFileName.endsWith(OcamlCompilables.OCAML_CMI)) {
linkerInputs.add(outputPath);
}
final ImmutableList<Arg> compileFlags = getCompileFlags(/* isBytecode */
true, /* excludeDeps */
false);
Step compileBytecodeStep = new OcamlMLCompileStep(workingDirectory, resolver, new OcamlMLCompileStep.Args(filesystem::resolve, cCompilerEnvironment, cCompiler, ocamlContext.getOcamlBytecodeCompiler().get(), ocamlContext.getOcamlInteropIncludesDir(), outputPath, inputOutput, compileFlags));
StepExecutionResult compileExecutionResult = compileBytecodeStep.execute(context);
if (!compileExecutionResult.isSuccess()) {
return compileExecutionResult;
}
}
return StepExecutionResult.SUCCESS;
}
use of com.facebook.buck.rules.args.Arg in project buck by facebook.
the class CxxPrepareForLinkStepTest method runTestForArgFilePathAndOutputPath.
private void runTestForArgFilePathAndOutputPath(Path argFilePath, Path fileListPath, Path output, Path currentCellPath) throws IOException, InterruptedException {
ExecutionContext context = TestExecutionContext.newInstance();
BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(buildRuleResolver));
// Setup some dummy values for inputs to the CxxLinkStep
ImmutableList<Arg> args = ImmutableList.of(StringArg.of("-rpath"), StringArg.of("hello"), StringArg.of("a.o"), FileListableLinkerInputArg.withSourcePathArg(SourcePathArg.of(new FakeSourcePath("libb.a"))), StringArg.of("-lsysroot"), StringArg.of("/Library/Application Support/blabla"), StringArg.of("-F/System/Frameworks"), StringArg.of("-L/System/libraries"), StringArg.of("-lz"));
// Create our CxxLinkStep to test.
CxxPrepareForLinkStep step = CxxPrepareForLinkStep.create(argFilePath, fileListPath, ImmutableList.of(StringArg.of("-filelist"), StringArg.of(fileListPath.toString())), output, args, CxxPlatformUtils.DEFAULT_PLATFORM.getLd().resolve(buildRuleResolver), currentCellPath, pathResolver);
step.execute(context);
assertThat(Files.exists(argFilePath), Matchers.equalTo(true));
ImmutableList<String> expectedArgFileContents = ImmutableList.<String>builder().add("-o", output.toString()).add("-rpath").add("hello").add("a.o").add("-lsysroot").add("\"/Library/Application Support/blabla\"").add("-F/System/Frameworks").add("-L/System/libraries").add("-lz").add("-filelist").add(fileListPath.toString()).build();
ImmutableList<String> expectedFileListContents = ImmutableList.of(Paths.get("libb.a").toAbsolutePath().toString());
checkContentsOfFile(argFilePath, expectedArgFileContents);
checkContentsOfFile(fileListPath, expectedFileListContents);
Files.deleteIfExists(argFilePath);
Files.deleteIfExists(fileListPath);
}
use of com.facebook.buck.rules.args.Arg in project buck by facebook.
the class CxxLinkTest method sanitizedPathsInFlagsDoNotAffectRuleKey.
@Test
public void sanitizedPathsInFlagsDoNotAffectRuleKey() {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.of("ld", Strings.repeat("0", 40), "a.o", Strings.repeat("a", 40), "b.o", Strings.repeat("b", 40), "libc.a", Strings.repeat("c", 40), "different", Strings.repeat("d", 40))), pathResolver, ruleFinder);
// Set up a map to sanitize the differences in the flags.
int pathSize = 10;
DebugPathSanitizer sanitizer1 = new MungingDebugPathSanitizer(pathSize, File.separatorChar, Paths.get("PWD"), ImmutableBiMap.of(Paths.get("something"), Paths.get("A")));
DebugPathSanitizer sanitizer2 = new MungingDebugPathSanitizer(pathSize, File.separatorChar, Paths.get("PWD"), ImmutableBiMap.of(Paths.get("different"), Paths.get("A")));
// Generate a rule with a path we need to sanitize to a consistent value.
ImmutableList<Arg> args1 = ImmutableList.of(new SanitizedArg(sanitizer1.sanitize(Optional.empty()), "-Lsomething/foo"));
RuleKey ruleKey1 = ruleKeyFactory.build(new CxxLink(params, DEFAULT_LINKER, DEFAULT_OUTPUT, args1, Optional.empty(), /* cacheable */
true));
// Generate another rule with a different path we need to sanitize to the
// same consistent value as above.
ImmutableList<Arg> args2 = ImmutableList.of(new SanitizedArg(sanitizer2.sanitize(Optional.empty()), "-Ldifferent/foo"));
RuleKey ruleKey2 = ruleKeyFactory.build(new CxxLink(params, DEFAULT_LINKER, DEFAULT_OUTPUT, args2, Optional.empty(), /* cacheable */
true));
assertEquals(ruleKey1, ruleKey2);
}
Aggregations