use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class HeaderPathNormalizerTest method managedHeaderDir.
@Test
public void managedHeaderDir() {
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
Path header = filesystem.getPath("foo/bar.h");
SourcePath headerDirPath = new PathSourcePath(filesystem, header.getParent());
HeaderPathNormalizer normalizer = new HeaderPathNormalizer.Builder(pathResolver).addHeaderDir(headerDirPath).build();
assertThat(normalizer.getAbsolutePathForUnnormalizedPath(pathResolver.getAbsolutePath(headerDirPath)), Matchers.equalTo(Optional.of(pathResolver.getAbsolutePath(headerDirPath))));
assertThat(normalizer.getAbsolutePathForUnnormalizedPath(filesystem.resolve(header)), Matchers.equalTo(Optional.of(filesystem.resolve(header))));
assertThat(normalizer.getSourcePathForAbsolutePath(pathResolver.getAbsolutePath(headerDirPath)), Matchers.equalTo(headerDirPath));
assertThat(normalizer.getSourcePathForAbsolutePath(filesystem.resolve(header)), Matchers.equalTo(headerDirPath));
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class FakeJavaLibrary method setJavaSrcs.
public FakeJavaLibrary setJavaSrcs(ImmutableSortedSet<Path> srcs) {
Preconditions.checkNotNull(srcs);
this.srcs = FluentIterable.from(srcs).transform(p -> (SourcePath) new PathSourcePath(new FakeProjectFilesystem(), p)).toSortedSet(Ordering.natural());
return this;
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class CxxTestDescription method createBuildRule.
@SuppressWarnings("PMD.PrematureDeclaration")
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams inputParams, final BuildRuleResolver resolver, final A args) throws NoSuchBuildTargetException {
Optional<StripStyle> flavoredStripStyle = StripStyle.FLAVOR_DOMAIN.getValue(inputParams.getBuildTarget());
Optional<LinkerMapMode> flavoredLinkerMapMode = LinkerMapMode.FLAVOR_DOMAIN.getValue(inputParams.getBuildTarget());
inputParams = CxxStrip.removeStripStyleFlavorInParams(inputParams, flavoredStripStyle);
inputParams = LinkerMapMode.removeLinkerMapModeFlavorInParams(inputParams, flavoredLinkerMapMode);
final BuildRuleParams params = inputParams;
Optional<CxxPlatform> platform = cxxPlatforms.getValue(params.getBuildTarget());
CxxPlatform cxxPlatform = platform.orElse(defaultCxxPlatform);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
if (params.getBuildTarget().getFlavors().contains(CxxCompilationDatabase.COMPILATION_DATABASE)) {
BuildRuleParams paramsWithoutFlavor = params.withoutFlavor(CxxCompilationDatabase.COMPILATION_DATABASE);
CxxLinkAndCompileRules cxxLinkAndCompileRules = CxxDescriptionEnhancer.createBuildRulesForCxxBinaryDescriptionArg(targetGraph, paramsWithoutFlavor, resolver, cxxBuckConfig, cxxPlatform, args, flavoredStripStyle, flavoredLinkerMapMode);
return CxxCompilationDatabase.createCompilationDatabase(params, cxxLinkAndCompileRules.compileRules);
}
if (params.getBuildTarget().getFlavors().contains(CxxCompilationDatabase.UBER_COMPILATION_DATABASE)) {
return CxxDescriptionEnhancer.createUberCompilationDatabase(platform.isPresent() ? params : params.withAppendedFlavor(cxxPlatform.getFlavor()), resolver);
}
if (params.getBuildTarget().getFlavors().contains(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR)) {
return CxxDescriptionEnhancer.createSandboxTreeBuildRule(resolver, args, cxxPlatform, params);
}
// Generate the link rule that builds the test binary.
final CxxLinkAndCompileRules cxxLinkAndCompileRules = CxxDescriptionEnhancer.createBuildRulesForCxxBinaryDescriptionArg(targetGraph, params, resolver, cxxBuckConfig, cxxPlatform, args, flavoredStripStyle, flavoredLinkerMapMode);
// Construct the actual build params we'll use, notably with an added dependency on the
// CxxLink rule above which builds the test binary.
BuildRuleParams testParams = params.copyReplacingDeclaredAndExtraDeps(() -> cxxLinkAndCompileRules.deps, params.getExtraDeps()).copyAppendingExtraDeps(cxxLinkAndCompileRules.executable.getDeps(ruleFinder));
testParams = CxxStrip.restoreStripStyleFlavorInParams(testParams, flavoredStripStyle);
testParams = LinkerMapMode.restoreLinkerMapModeFlavorInParams(testParams, flavoredLinkerMapMode);
// Supplier which expands macros in the passed in test environment.
ImmutableMap<String, String> testEnv = ImmutableMap.copyOf(Maps.transformValues(args.env, CxxDescriptionEnhancer.MACRO_HANDLER.getExpander(params.getBuildTarget(), params.getCellRoots(), resolver)));
// Supplier which expands macros in the passed in test arguments.
Supplier<ImmutableList<String>> testArgs = () -> args.args.stream().map(CxxDescriptionEnhancer.MACRO_HANDLER.getExpander(params.getBuildTarget(), params.getCellRoots(), resolver)::apply).collect(MoreCollectors.toImmutableList());
Supplier<ImmutableSortedSet<BuildRule>> additionalDeps = () -> {
ImmutableSortedSet.Builder<BuildRule> deps = ImmutableSortedSet.naturalOrder();
// It's not uncommon for users to add dependencies onto other binaries that they run
// during the test, so make sure to add them as runtime deps.
deps.addAll(Sets.difference(params.getDeps(), cxxLinkAndCompileRules.getBinaryRule().getDeps()));
// Add any build-time from any macros embedded in the `env` or `args` parameter.
for (String part : Iterables.concat(args.args, args.env.values())) {
try {
deps.addAll(CxxDescriptionEnhancer.MACRO_HANDLER.extractBuildTimeDeps(params.getBuildTarget(), params.getCellRoots(), resolver, part));
} catch (MacroException e) {
throw new HumanReadableException(e, "%s: %s", params.getBuildTarget(), e.getMessage());
}
}
return deps.build();
};
CxxTest test;
CxxTestType type = args.framework.orElse(getDefaultTestType());
switch(type) {
case GTEST:
{
test = new CxxGtestTest(testParams, ruleFinder, cxxLinkAndCompileRules.getBinaryRule(), cxxLinkAndCompileRules.executable, testEnv, testArgs, FluentIterable.from(args.resources).transform(p -> new PathSourcePath(params.getProjectFilesystem(), p)).toSortedSet(Ordering.natural()), additionalDeps, args.labels, args.contacts, args.runTestSeparately.orElse(false), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), cxxBuckConfig.getMaximumTestOutputSize());
break;
}
case BOOST:
{
test = new CxxBoostTest(testParams, ruleFinder, cxxLinkAndCompileRules.getBinaryRule(), cxxLinkAndCompileRules.executable, testEnv, testArgs, FluentIterable.from(args.resources).transform(p -> new PathSourcePath(params.getProjectFilesystem(), p)).toSortedSet(Ordering.natural()), additionalDeps, args.labels, args.contacts, args.runTestSeparately.orElse(false), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs));
break;
}
default:
{
Preconditions.checkState(false, "Unhandled C++ test type: %s", type);
throw new RuntimeException();
}
}
return test;
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class AaptPackageResourcesTest method setUp.
@Before
public void setUp() throws NoSuchBuildTargetException {
filesystem = new FakeProjectFilesystem();
TargetNode<?, ?> resourceNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:resource1"), filesystem).setRDotJavaPackage("package1").setRes(Paths.get("res1")).setAssets(new PathSourcePath(filesystem, Paths.get("asset1"))).build();
TargetNode<?, ?> resourceNode2 = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:resource2"), filesystem).setRDotJavaPackage("package2").setRes(Paths.get("res2")).setAssets(new PathSourcePath(filesystem, Paths.get("asset2"))).build();
TargetNode<?, ?> assetsNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:assets"), filesystem).setAssets(new PathSourcePath(filesystem, Paths.get("justAssets"))).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(resourceNode, resourceNode2, assetsNode);
ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
resource1 = (AndroidResource) ruleResolver.requireRule(resourceNode.getBuildTarget());
resource2 = (AndroidResource) ruleResolver.requireRule(resourceNode2.getBuildTarget());
justAssets = (AndroidResource) ruleResolver.requireRule(assetsNode.getBuildTarget());
ruleFinder = new SourcePathRuleFinder(ruleResolver);
pathResolver = new SourcePathResolver(ruleFinder);
aaptTarget = BuildTargetFactory.newInstance("//foo:bar");
params = new FakeBuildRuleParamsBuilder(aaptTarget).build();
hashCache = new FakeFileHashCache(new HashMap<>());
createPathSourcePath("res1", "resources1");
createPathSourcePath("res2", "resources2");
createPathSourcePath("res3", "resources3");
createPathSourcePath("asset1", "assets1");
createPathSourcePath("asset2", "assets2");
createPathSourcePath("justAssets", "justAssets");
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class CxxLibraryDescriptionTest method staticPicLibUsedForStaticPicLinkage.
@Test
public void staticPicLibUsedForStaticPicLinkage() throws Exception {
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
ProjectFilesystem filesystem = new FakeProjectFilesystem();
CxxLibraryBuilder libBuilder = new CxxLibraryBuilder(target, cxxBuckConfig);
libBuilder.setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new PathSourcePath(filesystem, Paths.get("test.cpp")))));
TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
CxxLibrary lib = (CxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
NativeLinkableInput nativeLinkableInput = lib.getNativeLinkableInput(CxxLibraryBuilder.createDefaultPlatform(), Linker.LinkableDepType.STATIC_PIC);
Arg firstArg = nativeLinkableInput.getArgs().get(0);
assertThat(firstArg, instanceOf(FileListableLinkerInputArg.class));
ImmutableCollection<BuildRule> deps = firstArg.getDeps(new SourcePathRuleFinder(resolver));
assertThat(deps.size(), is(1));
BuildRule buildRule = deps.asList().get(0);
assertThat(buildRule.getBuildTarget().getFlavors(), hasItem(CxxDescriptionEnhancer.STATIC_PIC_FLAVOR));
}
Aggregations