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))));
}
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);
}
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();
}
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;
}
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();
}
Aggregations