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