Search in sources :

Example 1 with AllExistingProjectFilesystem

use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.

the class NewNativeTargetProjectMutatorTest method testScriptBuildPhaseWithReactNative.

@Test
public void testScriptBuildPhaseWithReactNative() throws NoSuchBuildTargetException {
    NewNativeTargetProjectMutator mutator = mutatorWithCommonDefaults();
    BuildTarget depBuildTarget = BuildTargetFactory.newInstance("//foo:dep");
    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<?, ?> reactNativeNode = IosReactNativeLibraryBuilder.builder(depBuildTarget, buckConfig).setBundleName("Apps/Foo/FooBundle.js").setEntryPath(new PathSourcePath(filesystem, Paths.get("js/FooApp.js"))).build();
    mutator.setPostBuildRunScriptPhasesFromTargetNodes(ImmutableList.of(reactNativeNode));
    NewNativeTargetProjectMutator.Result result = mutator.buildTargetAndAddToProject(generatedProject, true);
    PBXShellScriptBuildPhase phase = getSingletonPhaseByType(result.target, PBXShellScriptBuildPhase.class);
    String shellScript = phase.getShellScript();
    assertThat(shellScript, startsWith("BASE_DIR=${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}\n" + "JS_OUT=${BASE_DIR}/Apps/Foo/FooBundle.js\n" + "SOURCE_MAP=${TEMP_DIR}/rn_source_map/Apps/Foo/FooBundle.js.map\n"));
}
Also used : 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) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 2 with AllExistingProjectFilesystem

use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.

the class PrebuiltCxxLibraryDescriptionTest method platformMacro.

@Test
public void platformMacro() {
    Optional<String> libDir = Optional.of("libs/$(platform)");
    Optional<String> libName = Optional.of("test-$(platform)");
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
    CellPathResolver cellRoots = TestCellBuilder.createCellRoots(filesystem);
    CxxPlatform platform1 = CxxPlatformUtils.DEFAULT_PLATFORM.withFlavor(InternalFlavor.of("PLATFORM1"));
    CxxPlatform platform2 = CxxPlatformUtils.DEFAULT_PLATFORM.withFlavor(InternalFlavor.of("PLATFORM2"));
    assertEquals(filesystem.resolve(TARGET.getBasePath().resolve(String.format("libs/PLATFORM1/libtest-PLATFORM1.%s", platform1.getSharedLibraryExtension()))), pathResolver.getAbsolutePath(PrebuiltCxxLibraryDescription.getSharedLibraryPath(TARGET, cellRoots, filesystem, resolver, platform1, Optional.empty(), libDir, libName)));
    assertEquals(filesystem.resolve(TARGET.getBasePath().resolve("libs/PLATFORM1/libtest-PLATFORM1.a")), pathResolver.getAbsolutePath(PrebuiltCxxLibraryDescription.getStaticLibraryPath(TARGET, cellRoots, filesystem, resolver, platform1, Optional.empty(), libDir, libName)));
    assertEquals(filesystem.resolve(TARGET.getBasePath().resolve(String.format("libs/PLATFORM2/libtest-PLATFORM2.%s", platform2.getSharedLibraryExtension()))), pathResolver.getAbsolutePath(PrebuiltCxxLibraryDescription.getSharedLibraryPath(TARGET, cellRoots, filesystem, resolver, platform2, Optional.empty(), libDir, libName)));
    assertEquals(filesystem.resolve(TARGET.getBasePath().resolve("libs/PLATFORM2/libtest-PLATFORM2.a")), pathResolver.getAbsolutePath(PrebuiltCxxLibraryDescription.getStaticLibraryPath(TARGET, cellRoots, filesystem, resolver, platform2, Optional.empty(), libDir, libName)));
}
Also used : CellPathResolver(com.facebook.buck.rules.CellPathResolver) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 3 with AllExistingProjectFilesystem

use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.

the class PrebuiltCxxLibraryDescriptionTest method linkWithoutSoname.

@Test
public void linkWithoutSoname() throws Exception {
    ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
    PrebuiltCxxLibraryBuilder prebuiltCxxLibraryBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:rule")).setLinkWithoutSoname(true);
    TargetGraph targetGraph = TargetGraphFactory.newInstance(prebuiltCxxLibraryBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    PrebuiltCxxLibrary rule = (PrebuiltCxxLibrary) prebuiltCxxLibraryBuilder.build(resolver, filesystem, targetGraph);
    NativeLinkableInput input = rule.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.SHARED);
    assertThat(Arg.stringify(input.getArgs(), pathResolver), Matchers.contains("-L" + filesystem.resolve(rule.getBuildTarget().getBasePath()).resolve("lib"), "-lrule"));
}
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) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 4 with AllExistingProjectFilesystem

use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.

the class PrebuiltCxxLibraryDescriptionTest method staticPicLibsUseCorrectPath.

@Test
public void staticPicLibsUseCorrectPath() throws Exception {
    ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
    PrebuiltCxxLibraryBuilder libBuilder = new PrebuiltCxxLibraryBuilder(TARGET);
    TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
    NativeLinkableInput nativeLinkableInput = lib.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.STATIC_PIC);
    assertThat(Arg.stringify(nativeLinkableInput.getArgs(), pathResolver).get(0), Matchers.endsWith(getStaticPicLibraryPath(libBuilder.build().getConstructorArg()).toString()));
}
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) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 5 with AllExistingProjectFilesystem

use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.

the class PrebuiltCxxLibraryDescriptionTest method createBuildRuleExternal.

@Test
public void createBuildRuleExternal() throws Exception {
    ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
    PrebuiltCxxLibraryBuilder libBuilder = new PrebuiltCxxLibraryBuilder(TARGET).setProvided(true);
    TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
    PrebuiltCxxLibraryDescription.Arg arg = libBuilder.build().getConstructorArg();
    // Verify shared native linkable input.
    NativeLinkableInput expectedSharedLinkableInput = NativeLinkableInput.of(ImmutableList.of(SourcePathArg.of(new PathSourcePath(filesystem, getSharedLibraryPath(arg)))), ImmutableSet.of(), ImmutableSet.of());
    assertEquals(expectedSharedLinkableInput, lib.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.SHARED));
}
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)

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