Search in sources :

Example 26 with Arg

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;
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) Arg(com.facebook.buck.rules.args.Arg) StringArg(com.facebook.buck.rules.args.StringArg) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Example 27 with Arg

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);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) StringArg(com.facebook.buck.rules.args.StringArg) FileListableLinkerInputArg(com.facebook.buck.rules.args.FileListableLinkerInputArg) Arg(com.facebook.buck.rules.args.Arg) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver)

Example 28 with Arg

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);
}
Also used : DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) StringArg(com.facebook.buck.rules.args.StringArg) SanitizedArg(com.facebook.buck.rules.args.SanitizedArg) Arg(com.facebook.buck.rules.args.Arg) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SanitizedArg(com.facebook.buck.rules.args.SanitizedArg) Test(org.junit.Test)

Aggregations

Arg (com.facebook.buck.rules.args.Arg)28 StringArg (com.facebook.buck.rules.args.StringArg)21 BuildTarget (com.facebook.buck.model.BuildTarget)14 ImmutableList (com.google.common.collect.ImmutableList)14 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)13 SourcePath (com.facebook.buck.rules.SourcePath)13 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)13 BuildRule (com.facebook.buck.rules.BuildRule)12 SourcePathArg (com.facebook.buck.rules.args.SourcePathArg)12 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)11 Path (java.nio.file.Path)11 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)10 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)10 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)8 Test (org.junit.Test)8 HumanReadableException (com.facebook.buck.util.HumanReadableException)7 Linker (com.facebook.buck.cxx.Linker)6 InternalFlavor (com.facebook.buck.model.InternalFlavor)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 CxxPreprocessorInput (com.facebook.buck.cxx.CxxPreprocessorInput)5