Search in sources :

Example 11 with ExplicitBuildTargetSourcePath

use of com.facebook.buck.rules.ExplicitBuildTargetSourcePath in project buck by facebook.

the class SwiftLibraryIntegrationTest method testSwiftCompileAndLinkArgs.

@Test
public void testSwiftCompileAndLinkArgs() throws NoSuchBuildTargetException {
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//foo:bar#iphoneos-x86_64");
    BuildTarget swiftCompileTarget = buildTarget.withAppendedFlavors(SwiftLibraryDescription.SWIFT_COMPILE_FLAVOR);
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(swiftCompileTarget).build();
    SwiftLibraryDescription.Arg args = createDummySwiftArg();
    SwiftCompile buildRule = (SwiftCompile) FakeAppleRuleDescriptions.SWIFT_LIBRARY_DESCRIPTION.createBuildRule(TargetGraph.EMPTY, params, resolver, args);
    resolver.addToIndex(buildRule);
    ImmutableList<Arg> astArgs = buildRule.getAstLinkArgs();
    assertThat(astArgs, Matchers.hasSize(3));
    assertThat(astArgs.get(0), Matchers.equalTo(StringArg.of("-Xlinker")));
    assertThat(astArgs.get(1), Matchers.equalTo(StringArg.of("-add_ast_path")));
    assertThat(astArgs.get(2), Matchers.instanceOf(SourcePathArg.class));
    SourcePathArg sourcePathArg = (SourcePathArg) astArgs.get(2);
    assertThat(sourcePathArg.getPath(), Matchers.equalTo(new ExplicitBuildTargetSourcePath(swiftCompileTarget, pathResolver.getRelativePath(buildRule.getSourcePathToOutput()).resolve("bar.swiftmodule"))));
    Arg objArg = buildRule.getFileListLinkArg();
    assertThat(objArg, Matchers.instanceOf(FileListableLinkerInputArg.class));
    FileListableLinkerInputArg fileListArg = (FileListableLinkerInputArg) objArg;
    ExplicitBuildTargetSourcePath fileListSourcePath = new ExplicitBuildTargetSourcePath(swiftCompileTarget, pathResolver.getRelativePath(buildRule.getSourcePathToOutput()).resolve("bar.o"));
    assertThat(fileListArg.getPath(), Matchers.equalTo(fileListSourcePath));
    BuildTarget linkTarget = buildTarget.withAppendedFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR);
    CxxLink linkRule = (CxxLink) FakeAppleRuleDescriptions.SWIFT_LIBRARY_DESCRIPTION.createBuildRule(TargetGraphFactory.newInstance(FakeTargetNodeBuilder.build(buildRule)), params.withBuildTarget(linkTarget), resolver, args);
    assertThat(linkRule.getArgs(), Matchers.hasItem(objArg));
    assertThat(linkRule.getArgs(), Matchers.not(Matchers.hasItem(SourcePathArg.of(fileListSourcePath))));
}
Also used : SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FileListableLinkerInputArg(com.facebook.buck.rules.args.FileListableLinkerInputArg) BuildTarget(com.facebook.buck.model.BuildTarget) 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) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) CxxLink(com.facebook.buck.cxx.CxxLink) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Test(org.junit.Test)

Example 12 with ExplicitBuildTargetSourcePath

use of com.facebook.buck.rules.ExplicitBuildTargetSourcePath in project buck by facebook.

the class PrebuiltJarDescription method createGwtModule.

@VisibleForTesting
static BuildRule createGwtModule(BuildRuleParams params, Arg arg) {
    // Because a PrebuiltJar rarely requires any building whatsoever (it could if the source_jar
    // is a BuildTargetSourcePath), we make the PrebuiltJar a dependency of the GWT module. If this
    // becomes a performance issue in practice, then we will explore reducing the dependencies of
    // the GWT module.
    final SourcePath input;
    if (arg.gwtJar.isPresent()) {
        input = arg.gwtJar.get();
    } else if (arg.sourceJar.isPresent()) {
        input = arg.sourceJar.get();
    } else {
        input = arg.binaryJar;
    }
    class ExistingOuputs extends AbstractBuildRule {

        @AddToRuleKey
        private final SourcePath source;

        private final Path output;

        protected ExistingOuputs(BuildRuleParams params, SourcePath source) {
            super(params);
            this.source = source;
            BuildTarget target = params.getBuildTarget();
            this.output = BuildTargets.getGenPath(getProjectFilesystem(), target, String.format("%s/%%s-gwt.jar", target.getShortName()));
        }

        @Override
        public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
            buildableContext.recordArtifact(context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()));
            ImmutableList.Builder<Step> steps = ImmutableList.builder();
            steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), output.getParent()));
            steps.add(CopyStep.forFile(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(source), output));
            return steps.build();
        }

        @Override
        public SourcePath getSourcePathToOutput() {
            return new ExplicitBuildTargetSourcePath(getBuildTarget(), output);
        }
    }
    return new ExistingOuputs(params, input);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ImmutableList(com.google.common.collect.ImmutableList) Step(com.facebook.buck.step.Step) CopyStep(com.facebook.buck.step.fs.CopyStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildContext(com.facebook.buck.rules.BuildContext) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) BuildableContext(com.facebook.buck.rules.BuildableContext) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 13 with ExplicitBuildTargetSourcePath

use of com.facebook.buck.rules.ExplicitBuildTargetSourcePath in project buck by facebook.

the class AbstractCxxSandboxInclude method from.

public static CxxSandboxInclude from(SymlinkTree symlinkTree, String includeDir, CxxPreprocessables.IncludeType includeType) {
    CxxSandboxInclude.Builder builder = CxxSandboxInclude.builder();
    builder.setIncludeType(includeType);
    builder.setRoot(new ExplicitBuildTargetSourcePath(symlinkTree.getBuildTarget(), symlinkTree.getRoot().resolve(includeDir)));
    builder.setIncludeDir(includeDir);
    return builder.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 14 with ExplicitBuildTargetSourcePath

use of com.facebook.buck.rules.ExplicitBuildTargetSourcePath in project buck by facebook.

the class AbstractCxxSourceRuleFactory method getSandboxedCxxSource.

private CxxSource getSandboxedCxxSource(CxxSource source) {
    if (getSandboxTree().isPresent()) {
        SymlinkTree sandboxTree = getSandboxTree().get();
        Path sourcePath = Paths.get(getPathResolver().getSourcePathName(getParams().getBuildTarget(), source.getPath()));
        Path sandboxPath = BuildTargets.getGenPath(getParams().getProjectFilesystem(), sandboxTree.getBuildTarget(), "%s");
        ExplicitBuildTargetSourcePath path = new ExplicitBuildTargetSourcePath(sandboxTree.getBuildTarget(), sandboxPath.resolve(sourcePath));
        source = CxxSource.copyOf(source).withPath(path);
    }
    return source;
}
Also used : FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SymlinkTree(com.facebook.buck.rules.SymlinkTree) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 15 with ExplicitBuildTargetSourcePath

use of com.facebook.buck.rules.ExplicitBuildTargetSourcePath in project buck by facebook.

the class AbstractCxxSymlinkTreeHeaders method from.

/**
   * @return a {@link CxxHeaders} constructed from the given {@link HeaderSymlinkTree}.
   */
public static CxxSymlinkTreeHeaders from(HeaderSymlinkTree symlinkTree, CxxPreprocessables.IncludeType includeType) {
    CxxSymlinkTreeHeaders.Builder builder = CxxSymlinkTreeHeaders.builder();
    builder.setIncludeType(includeType);
    builder.setRoot(new ExplicitBuildTargetSourcePath(symlinkTree.getBuildTarget(), symlinkTree.getRoot()));
    if (includeType == CxxPreprocessables.IncludeType.LOCAL) {
        builder.setIncludeRoot(new ExplicitBuildTargetSourcePath(symlinkTree.getBuildTarget(), symlinkTree.getIncludePath()));
        if (symlinkTree.getHeaderMap().isPresent()) {
            builder.setHeaderMap(new ExplicitBuildTargetSourcePath(symlinkTree.getBuildTarget(), symlinkTree.getHeaderMap().get()));
        }
    } else {
        builder.setIncludeRoot(new ExplicitBuildTargetSourcePath(symlinkTree.getBuildTarget(), symlinkTree.getRoot()));
    }
    builder.putAllNameToPathMap(symlinkTree.getLinks());
    return builder.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Aggregations

ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)21 SourcePath (com.facebook.buck.rules.SourcePath)13 BuildTarget (com.facebook.buck.model.BuildTarget)10 Path (java.nio.file.Path)9 BuildRule (com.facebook.buck.rules.BuildRule)8 Test (org.junit.Test)8 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)7 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)7 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)7 ImmutableList (com.google.common.collect.ImmutableList)6 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)3 NativeLinkableInput (com.facebook.buck.cxx.NativeLinkableInput)3 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)3 Flavor (com.facebook.buck.model.Flavor)3 InternalFlavor (com.facebook.buck.model.InternalFlavor)3 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)3 PathSourcePath (com.facebook.buck.rules.PathSourcePath)3 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)3 Step (com.facebook.buck.step.Step)3 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)3