Search in sources :

Example 11 with PBXShellScriptBuildPhase

use of com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase in project buck by facebook.

the class ProjectGeneratorTest method testAggregateTargetForBinaryForBuildWithBuck.

@Test
public void testAggregateTargetForBinaryForBuildWithBuck() throws IOException {
    BuildTarget binaryTarget = BuildTarget.builder(rootPath, "//foo", "binary").build();
    TargetNode<?, ?> binaryNode = AppleBinaryBuilder.createBuilder(binaryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.m"), ImmutableList.of("-foo")))).build();
    ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(binaryNode);
    final TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
    final AppleDependenciesCache cache = new AppleDependenciesCache(targetGraph);
    ProjectGenerator projectGenerator = new ProjectGenerator(targetGraph, cache, nodes.stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet()), projectCell, OUTPUT_DIRECTORY, PROJECT_NAME, "BUCK", ImmutableSet.of(), Optional.of(binaryTarget), ImmutableList.of("--flag", "value with spaces"), false, Optional.empty(), ImmutableSet.of(), Optional.empty(), new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, getBuildRuleResolverNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
    projectGenerator.createXcodeProjects();
    PBXTarget buildWithBuckTarget = null;
    for (PBXTarget target : projectGenerator.getGeneratedProject().getTargets()) {
        if (target.getProductName() != null && target.getProductName().endsWith("-Buck")) {
            buildWithBuckTarget = target;
        }
    }
    assertThat(buildWithBuckTarget, is(notNullValue()));
    assertHasConfigurations(buildWithBuckTarget, "Debug");
    assertKeepsConfigurationsInMainGroup(projectGenerator.getGeneratedProject(), buildWithBuckTarget);
    assertEquals("Should have exact number of build phases", 1, buildWithBuckTarget.getBuildPhases().size());
    PBXBuildPhase buildPhase = Iterables.getOnlyElement(buildWithBuckTarget.getBuildPhases());
    assertThat(buildPhase, instanceOf(PBXShellScriptBuildPhase.class));
    PBXShellScriptBuildPhase shellScriptBuildPhase = (PBXShellScriptBuildPhase) buildPhase;
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("buck -- \"--show-output --report-absolute-paths --flag 'value with spaces'\" " + binaryTarget.getFullyQualifiedName() + " dwarf dwarf-and-dsym"));
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    Path fixUUIDScriptPath = ProjectGenerator.getFixUUIDScriptPath(filesystem);
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("python " + fixUUIDScriptPath + " --verbose " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/binary-unsanitised/binary.app") + " " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/binary-unsanitised/binary.dSYM") + " " + binaryTarget.getShortName()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) TargetNode(com.facebook.buck.rules.TargetNode) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase) AppleDependenciesCache(com.facebook.buck.apple.AppleDependenciesCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 12 with PBXShellScriptBuildPhase

use of com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase 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 13 with PBXShellScriptBuildPhase

use of com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase in project buck by facebook.

the class NewNativeTargetProjectMutator method createScriptsForTargetNodes.

private ImmutableList<PBXShellScriptBuildPhase> createScriptsForTargetNodes(Iterable<TargetNode<?, ?>> nodes) throws IllegalStateException {
    ImmutableList.Builder<PBXShellScriptBuildPhase> builder = ImmutableList.builder();
    for (TargetNode<?, ?> node : nodes) {
        PBXShellScriptBuildPhase shellScriptBuildPhase = new PBXShellScriptBuildPhase();
        boolean nodeIsPrebuildScript = node.getDescription() instanceof XcodePrebuildScriptDescription;
        boolean nodeIsPostbuildScript = node.getDescription() instanceof XcodePostbuildScriptDescription;
        if (nodeIsPrebuildScript || nodeIsPostbuildScript) {
            XcodeScriptDescriptionArg arg = (XcodeScriptDescriptionArg) node.getConstructorArg();
            shellScriptBuildPhase.getInputPaths().addAll(FluentIterable.from(arg.srcs).transform(sourcePathResolver).transform(pathRelativizer::outputDirToRootRelative).transform(Object::toString).toSet());
            shellScriptBuildPhase.getOutputPaths().addAll(arg.outputs);
            shellScriptBuildPhase.setShellScript(arg.cmd);
        } else if (node.getDescription() instanceof IosReactNativeLibraryDescription) {
            shellScriptBuildPhase.setShellScript(generateXcodeShellScript(node));
        } else {
            // unreachable
            throw new IllegalStateException("Invalid rule type for shell script build phase");
        }
        builder.add(shellScriptBuildPhase);
    }
    return builder.build();
}
Also used : XcodeScriptDescriptionArg(com.facebook.buck.apple.XcodeScriptDescriptionArg) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) XcodePostbuildScriptDescription(com.facebook.buck.apple.XcodePostbuildScriptDescription) ImmutableList(com.google.common.collect.ImmutableList) XcodePrebuildScriptDescription(com.facebook.buck.apple.XcodePrebuildScriptDescription) IosReactNativeLibraryDescription(com.facebook.buck.js.IosReactNativeLibraryDescription)

Aggregations

PBXShellScriptBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase)13 BuildTarget (com.facebook.buck.model.BuildTarget)10 Test (org.junit.Test)9 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)8 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)7 PathSourcePath (com.facebook.buck.rules.PathSourcePath)5 PBXProject (com.facebook.buck.apple.xcode.xcodeproj.PBXProject)4 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)4 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)4 Path (java.nio.file.Path)4 NSString (com.dd.plist.NSString)3 AppleDependenciesCache (com.facebook.buck.apple.AppleDependenciesCache)3 PBXBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase)3 PBXResourcesBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXResourcesBuildPhase)3 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)3 AlwaysFoundExecutableFinder (com.facebook.buck.io.AlwaysFoundExecutableFinder)3 SourcePath (com.facebook.buck.rules.SourcePath)3 TargetGraph (com.facebook.buck.rules.TargetGraph)3 TargetNode (com.facebook.buck.rules.TargetNode)3 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)3