@Test public void testScriptBuildPhase() throws NoSuchBuildTargetException { NewNativeTargetProjectMutator mutator = mutatorWithCommonDefaults(); TargetNode<?> prebuildNode = XcodePrebuildScriptBuilder.createBuilder(BuildTargetFactory.newInstance("//foo:script")) .setSrcs(ImmutableSortedSet.<SourcePath>of(new FakeSourcePath("script/input.png"))) .setOutputs(ImmutableSortedSet.of("helloworld.txt")) .setCmd("echo \"hello world!\"") .build(); mutator.setPostBuildRunScriptPhasesFromTargetNodes( ImmutableList.<TargetNode<?>>of(prebuildNode)); NewNativeTargetProjectMutator.Result result = mutator.buildTargetAndAddToProject(generatedProject); PBXShellScriptBuildPhase phase = getSingletonPhaseByType(result.target, PBXShellScriptBuildPhase.class); assertThat( "Should set input paths correctly", "../script/input.png", is(equalTo(Iterables.getOnlyElement(phase.getInputPaths())))); assertThat( "Should set output paths correctly", "helloworld.txt", is(equalTo(Iterables.getOnlyElement(phase.getOutputPaths())))); assertEquals("should set script correctly", "echo \"hello world!\"", phase.getShellScript()); }
@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.<TargetNode<?>>of(reactNativeNode)); NewNativeTargetProjectMutator.Result result = mutator.buildTargetAndAddToProject(generatedProject); 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")); }