use of com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget in project buck by facebook.
the class ProjectGenerator method generateAppleBinaryTarget.
private PBXNativeTarget generateAppleBinaryTarget(PBXProject project, TargetNode<AppleNativeTargetDescriptionArg, ?> targetNode) throws IOException {
PBXNativeTarget target = generateBinaryTarget(project, Optional.empty(), targetNode, ProductType.TOOL, "%s", Optional.empty(), /* includeFrameworks */
true, ImmutableSet.of(), AppleResources.collectDirectResources(targetGraph, targetNode), ImmutableSet.of(), AppleBuildRules.collectDirectAssetCatalogs(targetGraph, targetNode), ImmutableSet.of(), Optional.empty(), Optional.empty());
LOG.debug("Generated Apple binary target %s", target);
return target;
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget 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);
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget in project buck by facebook.
the class ProjectGenerator method generateAppleBundleTarget.
private PBXNativeTarget generateAppleBundleTarget(PBXProject project, TargetNode<? extends HasAppleBundleFields, ?> targetNode, TargetNode<? extends AppleNativeTargetDescriptionArg, ?> binaryNode, Optional<TargetNode<AppleBundleDescription.Arg, ?>> bundleLoaderNode) throws IOException {
Path infoPlistPath = Preconditions.checkNotNull(resolveSourcePath(targetNode.getConstructorArg().getInfoPlist()));
// -- copy any binary and bundle targets into this bundle
Iterable<TargetNode<?, ?>> copiedRules = AppleBuildRules.getRecursiveTargetNodeDependenciesOfTypes(targetGraph, Optional.of(dependenciesCache), AppleBuildRules.RecursiveDependenciesMode.COPYING, targetNode, Optional.of(AppleBuildRules.XCODE_TARGET_DESCRIPTION_CLASSES));
if (bundleRequiresRemovalOfAllTransitiveFrameworks(targetNode)) {
copiedRules = rulesWithoutFrameworkBundles(copiedRules);
} else if (bundleRequiresAllTransitiveFrameworks(binaryNode)) {
copiedRules = ImmutableSet.<TargetNode<?, ?>>builder().addAll(copiedRules).addAll(getTransitiveFrameworkNodes(targetNode)).build();
}
if (bundleLoaderNode.isPresent()) {
copiedRules = rulesWithoutBundleLoader(copiedRules, bundleLoaderNode.get());
}
ImmutableList<PBXBuildPhase> copyFilesBuildPhases = getCopyFilesBuildPhases(copiedRules);
PBXNativeTarget target = generateBinaryTarget(project, Optional.of(targetNode), binaryNode, bundleToTargetProductType(targetNode, binaryNode), "%s." + getExtensionString(targetNode.getConstructorArg().getExtension()), Optional.of(infoPlistPath), /* includeFrameworks */
true, AppleResources.collectRecursiveResources(targetGraph, Optional.of(dependenciesCache), ImmutableList.of(targetNode)), AppleResources.collectDirectResources(targetGraph, targetNode), AppleBuildRules.collectRecursiveAssetCatalogs(targetGraph, Optional.of(dependenciesCache), ImmutableList.of(targetNode)), AppleBuildRules.collectDirectAssetCatalogs(targetGraph, targetNode), AppleBuildRules.collectRecursiveWrapperResources(targetGraph, Optional.of(dependenciesCache), ImmutableList.of(targetNode)), Optional.of(copyFilesBuildPhases), bundleLoaderNode);
LOG.debug("Generated iOS bundle target %s", target);
return target;
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget in project buck by facebook.
the class SchemeGeneratorTest method schemeWithMultipleTargetsBuildsInCorrectOrder.
@Test
public void schemeWithMultipleTargetsBuildsInCorrectOrder() throws Exception {
ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder = ImmutableMap.builder();
PBXTarget rootTarget = new PBXNativeTarget("rootRule");
rootTarget.setGlobalID("rootGID");
rootTarget.setProductReference(new PBXFileReference("root.a", "root.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
rootTarget.setProductType(ProductType.STATIC_LIBRARY);
PBXTarget leftTarget = new PBXNativeTarget("leftRule");
leftTarget.setGlobalID("leftGID");
leftTarget.setProductReference(new PBXFileReference("left.a", "left.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
leftTarget.setProductType(ProductType.STATIC_LIBRARY);
PBXTarget rightTarget = new PBXNativeTarget("rightRule");
rightTarget.setGlobalID("rightGID");
rightTarget.setProductReference(new PBXFileReference("right.a", "right.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
rightTarget.setProductType(ProductType.STATIC_LIBRARY);
PBXTarget childTarget = new PBXNativeTarget("childRule");
childTarget.setGlobalID("childGID");
childTarget.setProductReference(new PBXFileReference("child.a", "child.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
childTarget.setProductType(ProductType.STATIC_LIBRARY);
Path pbxprojectPath = Paths.get("foo/Foo.xcodeproj/project.pbxproj");
targetToProjectPathMapBuilder.put(rootTarget, pbxprojectPath);
targetToProjectPathMapBuilder.put(leftTarget, pbxprojectPath);
targetToProjectPathMapBuilder.put(rightTarget, pbxprojectPath);
targetToProjectPathMapBuilder.put(childTarget, pbxprojectPath);
SchemeGenerator schemeGenerator = new SchemeGenerator(projectFilesystem, Optional.of(childTarget), ImmutableSet.of(rootTarget, leftTarget, rightTarget, childTarget), ImmutableSet.of(), ImmutableSet.of(), "TestScheme", Paths.get("_gen/Foo.xcworkspace/scshareddata/xcshemes"), false, /* primaryTargetIsBuildWithBuck */
false, /* parallelizeBuild */
Optional.empty(), /* runnablePath */
Optional.empty(), /* remoteRunnablePath */
SchemeActionType.DEFAULT_CONFIG_NAMES, targetToProjectPathMapBuilder.build(), XCScheme.LaunchAction.LaunchStyle.AUTO);
Path schemePath = schemeGenerator.writeScheme();
String schemeXml = projectFilesystem.readFileIfItExists(schemePath).get();
System.out.println(schemeXml);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document scheme = dBuilder.parse(projectFilesystem.newFileInputStream(schemePath));
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
XPathExpression expr = xpath.compile("//BuildAction//BuildableReference/@BlueprintIdentifier");
NodeList nodes = (NodeList) expr.evaluate(scheme, XPathConstants.NODESET);
List<String> expectedOrdering = ImmutableList.of("rootGID", "leftGID", "rightGID", "childGID");
List<String> actualOrdering = Lists.newArrayList();
for (int i = 0; i < nodes.getLength(); i++) {
actualOrdering.add(nodes.item(i).getNodeValue());
}
assertThat(actualOrdering, equalTo(expectedOrdering));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget in project buck by facebook.
the class SchemeGeneratorTest method whenProvidedAPrimaryTargetThatIsBuiltWithBuckLaunchesIt.
@Test
public void whenProvidedAPrimaryTargetThatIsBuiltWithBuckLaunchesIt() throws Exception {
ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder = ImmutableMap.builder();
PBXTarget rootTarget = new PBXNativeTarget("rootRule");
rootTarget.setGlobalID("rootGID");
rootTarget.setProductName("Foo");
String runnablePath = "buck-out/gen/Foo/Foo.app";
Path pbxprojectPath = Paths.get("foo/Foo.xcodeproj/project.pbxproj");
targetToProjectPathMapBuilder.put(rootTarget, pbxprojectPath);
SchemeGenerator schemeGenerator = new SchemeGenerator(projectFilesystem, Optional.of(rootTarget), ImmutableSet.of(rootTarget), ImmutableSet.of(), ImmutableSet.of(), "TestScheme", Paths.get("_gen/Foo.xcworkspace/scshareddata/xcshemes"), true, /* primaryTargetIsBuildWithBuck */
false, /* parallelizeBuild */
Optional.of(runnablePath), /* runnablePath */
Optional.empty(), /* remoteRunnablePath */
SchemeActionType.DEFAULT_CONFIG_NAMES, targetToProjectPathMapBuilder.build(), XCScheme.LaunchAction.LaunchStyle.AUTO);
Path schemePath = schemeGenerator.writeScheme();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document scheme = dBuilder.parse(projectFilesystem.newFileInputStream(schemePath));
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath runnableLaunchActionXPath = xpathFactory.newXPath();
XPathExpression runnableLaunchActionExpr = runnableLaunchActionXPath.compile("//LaunchAction/PathRunnable");
NodeList runnables = (NodeList) runnableLaunchActionExpr.evaluate(scheme, XPathConstants.NODESET);
assertThat(runnables.getLength(), equalTo(1));
Node runnable = runnables.item(0);
assertThat(runnable.getAttributes().getNamedItem("FilePath").getNodeValue(), equalTo(runnablePath));
}
Aggregations