Search in sources :

Example 1 with PBXShellScriptBuildPhase

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

the class ProjectGenerator method generateBuildWithBuckTarget.

private void generateBuildWithBuckTarget(TargetNode<?, ?> targetNode) {
    final BuildTarget buildTarget = targetNode.getBuildTarget();
    String buckTargetProductName = getXcodeTargetName(buildTarget) + BUILD_WITH_BUCK_POSTFIX;
    PBXAggregateTarget buildWithBuckTarget = new PBXAggregateTarget(buckTargetProductName);
    buildWithBuckTarget.setProductName(buckTargetProductName);
    PBXShellScriptBuildPhase buildShellScriptBuildPhase = new PBXShellScriptBuildPhase();
    buildShellScriptBuildPhase.setShellScript(getBuildWithBuckShellScript(targetNode));
    buildWithBuckTarget.getBuildPhases().add(buildShellScriptBuildPhase);
    // Only add a shell script for fixing UUIDs if it is an AppleBundle
    if (targetNode.getDescription() instanceof AppleBundleDescription) {
        PBXShellScriptBuildPhase codesignPhase = new PBXShellScriptBuildPhase();
        codesignPhase.setShellScript(getCodesignShellScript(targetNode));
        buildWithBuckTarget.getBuildPhases().add(codesignPhase);
    }
    TargetNode<CxxLibraryDescription.Arg, ?> node = getAppleNativeNode(targetGraph, targetNode).get();
    ImmutableMap<String, ImmutableMap<String, String>> configs = getXcodeBuildConfigurationsForTargetNode(node, ImmutableMap.of()).get();
    XCConfigurationList configurationList = new XCConfigurationList();
    PBXGroup group = project.getMainGroup().getOrCreateDescendantGroupByPath(StreamSupport.stream(buildTarget.getBasePath().spliterator(), false).map(Object::toString).collect(MoreCollectors.toImmutableList())).getOrCreateChildGroupByName(getXcodeTargetName(buildTarget));
    for (String configurationName : configs.keySet()) {
        XCBuildConfiguration configuration = configurationList.getBuildConfigurationsByName().getUnchecked(configurationName);
        configuration.setBaseConfigurationReference(getConfigurationFileReference(group, getConfigurationNameToXcconfigPath(buildTarget).apply(configurationName)));
        NSDictionary inlineSettings = new NSDictionary();
        inlineSettings.put("HEADER_SEARCH_PATHS", "");
        inlineSettings.put("LIBRARY_SEARCH_PATHS", "");
        inlineSettings.put("FRAMEWORK_SEARCH_PATHS", "");
        configuration.setBuildSettings(inlineSettings);
    }
    buildWithBuckTarget.setBuildConfigurationList(configurationList);
    project.getTargets().add(buildWithBuckTarget);
    targetNodeToGeneratedProjectTargetBuilder.put(targetNode, buildWithBuckTarget);
}
Also used : XCBuildConfiguration(com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration) XCConfigurationList(com.facebook.buck.apple.xcode.xcodeproj.XCConfigurationList) NSDictionary(com.dd.plist.NSDictionary) NSString(com.dd.plist.NSString) PBXAggregateTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXAggregateTarget) ImmutableMap(com.google.common.collect.ImmutableMap) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) AppleNativeTargetDescriptionArg(com.facebook.buck.apple.AppleNativeTargetDescriptionArg) StringWithMacrosArg(com.facebook.buck.rules.args.StringWithMacrosArg) AppleWrapperResourceArg(com.facebook.buck.apple.AppleWrapperResourceArg) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) AppleBundleDescription(com.facebook.buck.apple.AppleBundleDescription)

Example 2 with PBXShellScriptBuildPhase

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

the class ProjectGenerator method generateHalideLibraryTarget.

private Optional<PBXTarget> generateHalideLibraryTarget(PBXProject project, TargetNode<HalideLibraryDescription.Arg, ?> targetNode) throws IOException {
    final BuildTarget buildTarget = targetNode.getBuildTarget();
    boolean isFocusedOnTarget = buildTarget.matchesUnflavoredTargets(focusModules);
    String productName = getProductNameForBuildTarget(buildTarget);
    Path outputPath = getHalideOutputPath(targetNode.getFilesystem(), buildTarget);
    Path scriptPath = halideBuckConfig.getXcodeCompileScriptPath();
    Optional<String> script = projectFilesystem.readFileIfItExists(scriptPath);
    PBXShellScriptBuildPhase scriptPhase = new PBXShellScriptBuildPhase();
    scriptPhase.setShellScript(script.orElse(""));
    NewNativeTargetProjectMutator mutator = new NewNativeTargetProjectMutator(pathRelativizer, this::resolveSourcePath);
    mutator.setTargetName(getXcodeTargetName(buildTarget)).setProduct(ProductType.STATIC_LIBRARY, productName, outputPath).setPreBuildRunScriptPhases(ImmutableList.of(scriptPhase));
    NewNativeTargetProjectMutator.Result targetBuilderResult;
    targetBuilderResult = mutator.buildTargetAndAddToProject(project, isFocusedOnTarget);
    BuildTarget compilerTarget = HalideLibraryDescription.createHalideCompilerBuildTarget(buildTarget);
    Path compilerPath = BuildTargets.getGenPath(projectFilesystem, compilerTarget, "%s");
    ImmutableMap<String, String> appendedConfig = ImmutableMap.of();
    ImmutableMap<String, String> extraSettings = ImmutableMap.of();
    ImmutableMap.Builder<String, String> defaultSettingsBuilder = ImmutableMap.builder();
    defaultSettingsBuilder.put("REPO_ROOT", projectFilesystem.getRootPath().toAbsolutePath().normalize().toString());
    defaultSettingsBuilder.put("HALIDE_COMPILER_PATH", compilerPath.toString());
    // pass the source list to the xcode script
    String halideCompilerSrcs;
    Iterable<Path> compilerSrcFiles = Iterables.transform(targetNode.getConstructorArg().srcs, input -> resolveSourcePath(input.getSourcePath()));
    halideCompilerSrcs = Joiner.on(" ").join(compilerSrcFiles);
    defaultSettingsBuilder.put("HALIDE_COMPILER_SRCS", halideCompilerSrcs);
    String halideCompilerFlags;
    halideCompilerFlags = Joiner.on(" ").join(targetNode.getConstructorArg().compilerFlags);
    defaultSettingsBuilder.put("HALIDE_COMPILER_FLAGS", halideCompilerFlags);
    defaultSettingsBuilder.put("HALIDE_OUTPUT_PATH", outputPath.toString());
    defaultSettingsBuilder.put("HALIDE_FUNC_NAME", buildTarget.getShortName());
    defaultSettingsBuilder.put(PRODUCT_NAME, productName);
    Optional<ImmutableSortedMap<String, ImmutableMap<String, String>>> configs = getXcodeBuildConfigurationsForTargetNode(targetNode, appendedConfig);
    PBXNativeTarget target = targetBuilderResult.target;
    setTargetBuildConfigurations(getConfigurationNameToXcconfigPath(buildTarget), target, project.getMainGroup(), configs.get(), extraSettings, defaultSettingsBuilder.build(), appendedConfig);
    return Optional.of(target);
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) PBXNativeTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) NSString(com.dd.plist.NSString) ImmutableMap(com.google.common.collect.ImmutableMap) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget)

Example 3 with PBXShellScriptBuildPhase

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

the class ProjectGeneratorTest method testAggregateTargetForLibraryForBuildWithBuck.

@Test
public void testAggregateTargetForLibraryForBuildWithBuck() throws IOException {
    BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "library").build();
    TargetNode<?, ?> binaryNode = AppleLibraryBuilder.createBuilder(libraryTarget).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(libraryTarget), 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'\" " + libraryTarget.getFullyQualifiedName() + " dwarf dwarf-and-dsym"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) TargetNode(com.facebook.buck.rules.TargetNode) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase) TargetGraph(com.facebook.buck.rules.TargetGraph) AppleDependenciesCache(com.facebook.buck.apple.AppleDependenciesCache) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 4 with PBXShellScriptBuildPhase

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

the class ProjectGeneratorTest method testAggregateTargetForBundleForBuildWithBuck.

@Test
public void testAggregateTargetForBundleForBuildWithBuck() throws IOException {
    BuildTarget binaryTarget = BuildTarget.builder(rootPath, "//foo", "binary").build();
    TargetNode<?, ?> binaryNode = AppleBinaryBuilder.createBuilder(binaryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).build();
    BuildTarget bundleTarget = BuildTarget.builder(rootPath, "//foo", "bundle").build();
    TargetNode<?, ?> bundleNode = AppleBundleBuilder.createBuilder(bundleTarget).setExtension(Either.ofLeft(AppleBundleExtension.APP)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(binaryTarget).build();
    ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(bundleNode, 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(bundleTarget), 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);
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    assertEquals("Should have exact number of build phases", 2, buildWithBuckTarget.getBuildPhases().size());
    PBXBuildPhase buildPhase = Iterables.get(buildWithBuckTarget.getBuildPhases(), 0);
    assertThat(buildPhase, instanceOf(PBXShellScriptBuildPhase.class));
    PBXShellScriptBuildPhase shellScriptBuildPhase = (PBXShellScriptBuildPhase) buildPhase;
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("-- \"--show-output --report-absolute-paths --flag 'value with spaces'\" " + bundleTarget.getFullyQualifiedName() + " dwarf dwarf-and-dsym"));
    Path fixUUIDScriptPath = ProjectGenerator.getFixUUIDScriptPath(filesystem);
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("python " + fixUUIDScriptPath + " --verbose " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.app") + " " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.dSYM") + " " + bundleTarget.getShortName()));
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("machoutils absolutify_object_paths --binary $BUCK_BUNDLE_OUTPUT_PATH/bundle " + "--output " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.app/bundle") + " --old_compdir " + "\"./////////////////////"));
    // skipping some slashes: ".//////////// ..... ///////"
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("////////\" --new_compdir \"" + filesystem.getRootPath().toString() + "\""));
    PBXBuildPhase codesignPhase = buildWithBuckTarget.getBuildPhases().get(1);
    assertThat(codesignPhase, instanceOf(PBXShellScriptBuildPhase.class));
    PBXShellScriptBuildPhase codesignShellScriptPhase = (PBXShellScriptBuildPhase) codesignPhase;
    Path codesignScriptPath = ProjectGenerator.getCodesignScriptPath(filesystem);
    assertThat(codesignShellScriptPhase.getShellScript(), containsString("python " + codesignScriptPath + " /usr/bin/codesign " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.app")));
}
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 5 with PBXShellScriptBuildPhase

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

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