Search in sources :

Example 16 with AllExistingProjectFilesystem

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()));
}
Also used : DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) VisibilityPattern(com.facebook.buck.rules.VisibilityPattern) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) TargetNodeFactory(com.facebook.buck.rules.TargetNodeFactory) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 17 with AllExistingProjectFilesystem

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="));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) ReactNativeBuckConfig(com.facebook.buck.js.ReactNativeBuckConfig) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) PBXProject(com.facebook.buck.apple.xcode.xcodeproj.PBXProject) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 18 with AllExistingProjectFilesystem

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());
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 19 with AllExistingProjectFilesystem

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));
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 20 with AllExistingProjectFilesystem

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))));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Aggregations

ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)26 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)26 Test (org.junit.Test)26 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)24 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)22 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)22 TargetGraph (com.facebook.buck.rules.TargetGraph)18 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)10 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)9 PathSourcePath (com.facebook.buck.rules.PathSourcePath)9 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)8 BuildTarget (com.facebook.buck.model.BuildTarget)5 SourcePath (com.facebook.buck.rules.SourcePath)4 Path (java.nio.file.Path)3 PBXShellScriptBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase)2 ReactNativeBuckConfig (com.facebook.buck.js.ReactNativeBuckConfig)2 CellPathResolver (com.facebook.buck.rules.CellPathResolver)2 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)2 RuleKey (com.facebook.buck.rules.RuleKey)2 LinkOption (java.nio.file.LinkOption)2