use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.
the class GenruleDescriptionTest method testImplicitDepsAreAddedCorrectly.
@Test
public void testImplicitDepsAreAddedCorrectly() throws Exception {
Description<GenruleDescription.Arg> genruleDescription = new GenruleDescription();
Map<String, Object> instance = ImmutableMap.of("srcs", ImmutableList.of(":baz", "//biz:baz"), "out", "AndroidManifest.xml", "cmd", "$(exe //bin:executable) $(location :arg)");
ProjectFilesystem projectFilesystem = new AllExistingProjectFilesystem();
ConstructorArgMarshaller marshaller = new ConstructorArgMarshaller(new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance()));
ImmutableSet.Builder<BuildTarget> declaredDeps = ImmutableSet.builder();
ImmutableSet.Builder<VisibilityPattern> visibilityPatterns = ImmutableSet.builder();
GenruleDescription.Arg constructorArg = genruleDescription.createUnpopulatedConstructorArg();
BuildTarget buildTarget = BuildTargetFactory.newInstance("//foo:bar");
marshaller.populate(createCellRoots(projectFilesystem), projectFilesystem, buildTarget, constructorArg, declaredDeps, visibilityPatterns, instance);
TargetNode<GenruleDescription.Arg, ?> targetNode = new TargetNodeFactory(new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance())).create(Hashing.sha1().hashString(buildTarget.getFullyQualifiedName(), UTF_8), genruleDescription, constructorArg, projectFilesystem, buildTarget, declaredDeps.build(), visibilityPatterns.build(), createCellRoots(projectFilesystem));
assertEquals("SourcePaths and targets from cmd string should be extracted as extra deps.", ImmutableSet.of("//foo:baz", "//biz:baz", "//bin:executable", "//foo:arg"), targetNode.getExtraDeps().stream().map(Object::toString).collect(MoreCollectors.toImmutableSet()));
}
use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.
the class ProjectGeneratorTest method testAppleBundleRuleWithRNLibraryDependency.
@Test
public void testAppleBundleRuleWithRNLibraryDependency() throws IOException {
BuildTarget rnLibraryTarget = BuildTarget.builder(rootPath, "//foo", "rn_library").addFlavors(DEFAULT_FLAVOR).build();
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
ReactNativeBuckConfig buckConfig = new ReactNativeBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("react-native", ImmutableMap.of("packager_worker", "react-native/packager.sh"))).setFilesystem(filesystem).build());
TargetNode<?, ?> rnLibraryNode = IosReactNativeLibraryBuilder.builder(rnLibraryTarget, buckConfig).setBundleName("Apps/Foo/FooBundle.js").setEntryPath(new PathSourcePath(filesystem, Paths.get("js/FooApp.js"))).build();
BuildTarget sharedLibraryTarget = BuildTarget.builder(rootPath, "//dep", "shared").addFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR).build();
TargetNode<?, ?> sharedLibraryNode = AppleLibraryBuilder.createBuilder(sharedLibraryTarget).build();
BuildTarget bundleTarget = BuildTarget.builder(rootPath, "//foo", "bundle").build();
TargetNode<?, ?> bundleNode = AppleBundleBuilder.createBuilder(bundleTarget).setExtension(Either.ofLeft(AppleBundleExtension.BUNDLE)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(sharedLibraryTarget).setDeps(ImmutableSortedSet.of(rnLibraryTarget)).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(rnLibraryNode, sharedLibraryNode, bundleNode));
projectGenerator.createXcodeProjects();
PBXProject project = projectGenerator.getGeneratedProject();
PBXTarget target = assertTargetExistsAndReturnTarget(project, "//foo:bundle");
assertThat(target.getName(), equalTo("//foo:bundle"));
assertThat(target.isa(), equalTo("PBXNativeTarget"));
PBXShellScriptBuildPhase shellScriptBuildPhase = ProjectGeneratorTestUtils.getSingletonPhaseByType(target, PBXShellScriptBuildPhase.class);
assertThat(shellScriptBuildPhase.getShellScript(), startsWith("BASE_DIR="));
}
use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method existingStaticLibIsANativeLinkTargetSoname.
@Test
public void existingStaticLibIsANativeLinkTargetSoname() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
PrebuiltCxxLibraryBuilder prebuiltCxxLibraryBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:rule"));
TargetGraph targetGraph = TargetGraphFactory.newInstance(prebuiltCxxLibraryBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltCxxLibrary rule = (PrebuiltCxxLibrary) prebuiltCxxLibraryBuilder.build(resolver, filesystem, targetGraph);
assertTrue(rule.getNativeLinkTarget(CXX_PLATFORM).isPresent());
}
use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method addsLibsToAndroidPackageableCollector.
@Test
public void addsLibsToAndroidPackageableCollector() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
PrebuiltCxxLibraryBuilder libBuilder = new PrebuiltCxxLibraryBuilder(TARGET);
TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
PrebuiltCxxLibraryDescription.Arg arg = libBuilder.build().getConstructorArg();
assertEquals(ImmutableMap.<String, SourcePath>of(getSharedLibrarySoname(arg), new PathSourcePath(filesystem, getSharedLibraryPath(arg))), lib.getSharedLibraries(CXX_PLATFORM));
}
use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method exportedHeaders.
@Test
public void exportedHeaders() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
PrebuiltCxxLibraryBuilder libBuilder = new PrebuiltCxxLibraryBuilder(TARGET).setExportedHeaders(SourceList.ofNamedSources(ImmutableSortedMap.of("foo.h", new FakeSourcePath("foo.h"))));
TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
// Verify the preprocessable input is as expected.
CxxPreprocessorInput input = lib.getCxxPreprocessorInput(CXX_PLATFORM, HeaderVisibility.PUBLIC);
assertThat(getHeaderNames(input.getIncludes()), Matchers.hasItem(filesystem.getPath("foo.h")));
assertThat(ImmutableSortedSet.copyOf(input.getDeps(resolver, ruleFinder)), Matchers.equalTo(resolver.getAllRules(getInputRules(lib))));
}
Aggregations