use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class SchemeGenerator method writeScheme.
public Path writeScheme() throws IOException {
Map<PBXTarget, XCScheme.BuildableReference> buildTargetToBuildableReferenceMap = Maps.newHashMap();
for (PBXTarget target : Iterables.concat(orderedBuildTargets, orderedBuildTestTargets)) {
String blueprintName = target.getProductName();
if (blueprintName == null) {
blueprintName = target.getName();
}
Path outputPath = outputDirectory.getParent();
String buildableReferencePath;
Path projectPath = Preconditions.checkNotNull(targetToProjectPathMap.get(target));
if (outputPath == null) {
//Root directory project
buildableReferencePath = projectPath.toString();
} else {
buildableReferencePath = outputPath.relativize(projectPath).toString();
}
XCScheme.BuildableReference buildableReference = new XCScheme.BuildableReference(buildableReferencePath, Preconditions.checkNotNull(target.getGlobalID()), target.getProductReference() != null ? target.getProductReference().getName() : Preconditions.checkNotNull(target.getProductName()), blueprintName);
buildTargetToBuildableReferenceMap.put(target, buildableReference);
}
XCScheme.BuildAction buildAction = new XCScheme.BuildAction(parallelizeBuild);
// For aesthetic reasons put all non-test build actions before all test build actions.
for (PBXTarget target : orderedBuildTargets) {
addBuildActionForBuildTarget(buildTargetToBuildableReferenceMap.get(target), !primaryTargetIsBuildWithBuck || !primaryTarget.isPresent() || target.equals(primaryTarget.get()) ? XCScheme.BuildActionEntry.BuildFor.DEFAULT : XCScheme.BuildActionEntry.BuildFor.INDEXING, buildAction);
}
for (PBXTarget target : orderedBuildTestTargets) {
addBuildActionForBuildTarget(buildTargetToBuildableReferenceMap.get(target), XCScheme.BuildActionEntry.BuildFor.TEST_ONLY, buildAction);
}
XCScheme.TestAction testAction = new XCScheme.TestAction(Preconditions.checkNotNull(actionConfigNames.get(SchemeActionType.TEST)));
for (PBXTarget target : orderedRunTestTargets) {
XCScheme.BuildableReference buildableReference = buildTargetToBuildableReferenceMap.get(target);
XCScheme.TestableReference testableReference = new XCScheme.TestableReference(buildableReference);
testAction.addTestableReference(testableReference);
}
Optional<XCScheme.LaunchAction> launchAction = Optional.empty();
Optional<XCScheme.ProfileAction> profileAction = Optional.empty();
if (primaryTarget.isPresent()) {
XCScheme.BuildableReference primaryBuildableReference = buildTargetToBuildableReferenceMap.get(primaryTarget.get());
if (primaryBuildableReference != null) {
launchAction = Optional.of(new XCScheme.LaunchAction(primaryBuildableReference, Preconditions.checkNotNull(actionConfigNames.get(SchemeActionType.LAUNCH)), runnablePath, remoteRunnablePath, launchStyle));
profileAction = Optional.of(new XCScheme.ProfileAction(primaryBuildableReference, Preconditions.checkNotNull(actionConfigNames.get(SchemeActionType.PROFILE))));
}
}
XCScheme.AnalyzeAction analyzeAction = new XCScheme.AnalyzeAction(Preconditions.checkNotNull(actionConfigNames.get(SchemeActionType.ANALYZE)));
XCScheme.ArchiveAction archiveAction = new XCScheme.ArchiveAction(Preconditions.checkNotNull(actionConfigNames.get(SchemeActionType.ARCHIVE)));
XCScheme scheme = new XCScheme(schemeName, Optional.of(buildAction), Optional.of(testAction), launchAction, profileAction, Optional.of(analyzeAction), Optional.of(archiveAction));
outputScheme = Optional.of(scheme);
Path schemeDirectory = outputDirectory.resolve("xcshareddata/xcschemes");
projectFilesystem.mkdirs(schemeDirectory);
Path schemePath = schemeDirectory.resolve(schemeName + ".xcscheme");
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
serializeScheme(scheme, outputStream);
String contentsToWrite = outputStream.toString();
if (MoreProjectFilesystems.fileContentsDiffer(new ByteArrayInputStream(contentsToWrite.getBytes(Charsets.UTF_8)), schemePath, projectFilesystem)) {
projectFilesystem.writeContentsToPath(outputStream.toString(), schemePath);
}
}
return schemePath;
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class WorkspaceAndProjectGenerator method processGenerationResult.
private void processGenerationResult(ImmutableMultimap.Builder<BuildTarget, PBXTarget> buildTargetToPbxTargetMapBuilder, ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder, GenerationResult result) {
requiredBuildTargetsBuilder.addAll(result.getRequiredBuildTargets());
buildTargetToPbxTargetMapBuilder.putAll(result.getBuildTargetToGeneratedTargetMap());
for (PBXTarget target : result.getBuildTargetToGeneratedTargetMap().values()) {
targetToProjectPathMapBuilder.put(target, result.getProjectPath());
}
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGenerator method createXcodeProjects.
public void createXcodeProjects() throws IOException {
LOG.debug("Creating projects for targets %s", initialTargets);
boolean hasAtLeastOneTarget = false;
try (SimplePerfEvent.Scope scope = SimplePerfEvent.scope(buckEventBus, PerfEventId.of("xcode_project_generation"), ImmutableMap.of("Path", getProjectPath()))) {
for (TargetNode<?, ?> targetNode : targetGraph.getNodes()) {
if (isBuiltByCurrentProject(targetNode.getBuildTarget())) {
LOG.debug("Including rule %s in project", targetNode);
// Trigger the loading cache to call the generateProjectTarget function.
Optional<PBXTarget> target = targetNodeToProjectTarget.getUnchecked(targetNode);
if (target.isPresent()) {
targetNodeToGeneratedProjectTargetBuilder.put(targetNode, target.get());
}
if (targetNode.getBuildTarget().matchesUnflavoredTargets(focusModules)) {
// If the target is not included, we still need to do other operations to generate
// the required header maps.
hasAtLeastOneTarget = true;
}
} else {
LOG.verbose("Excluding rule %s (not built by current project)", targetNode);
}
}
if (!hasAtLeastOneTarget && focusModules.isPresent()) {
return;
}
if (targetToBuildWithBuck.isPresent()) {
generateBuildWithBuckTarget(targetGraph.get(targetToBuildWithBuck.get()));
}
for (String configName : targetConfigNamesBuilder.build()) {
XCBuildConfiguration outputConfig = project.getBuildConfigurationList().getBuildConfigurationsByName().getUnchecked(configName);
outputConfig.setBuildSettings(new NSDictionary());
}
if (!shouldGenerateHeaderSymlinkTreesOnly()) {
writeProjectFile(project);
}
projectGenerated = true;
} catch (UncheckedExecutionException e) {
// if any code throws an exception, they tend to get wrapped in LoadingCache's
// UncheckedExecutionException. Unwrap it if its cause is HumanReadable.
UncheckedExecutionException originalException = e;
while (e.getCause() instanceof UncheckedExecutionException) {
e = (UncheckedExecutionException) e.getCause();
}
if (e.getCause() instanceof HumanReadableException) {
throw (HumanReadableException) e.getCause();
} else {
throw originalException;
}
}
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method testFrameworkBundleDepIsNotCopiedToFrameworkBundle.
@Test
public void testFrameworkBundleDepIsNotCopiedToFrameworkBundle() throws IOException {
BuildTarget framework2Target = BuildTarget.builder(rootPath, "//foo", "framework_2").addFlavors(DEFAULT_FLAVOR, CxxDescriptionEnhancer.SHARED_FLAVOR).build();
BuildTarget framework2BinaryTarget = BuildTarget.builder(rootPath, "//foo", "framework_2_bin").addFlavors(DEFAULT_FLAVOR, CxxDescriptionEnhancer.SHARED_FLAVOR).build();
TargetNode<?, ?> framework2BinaryNode = AppleLibraryBuilder.createBuilder(framework2BinaryTarget).build();
TargetNode<?, ?> framework2Node = AppleBundleBuilder.createBuilder(framework2Target).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(framework2BinaryTarget).build();
BuildTarget framework1Target = BuildTarget.builder(rootPath, "//foo", "framework_1").addFlavors(DEFAULT_FLAVOR, CxxDescriptionEnhancer.SHARED_FLAVOR).build();
BuildTarget framework1BinaryTarget = BuildTarget.builder(rootPath, "//foo", "framework_1_bin").addFlavors(DEFAULT_FLAVOR, CxxDescriptionEnhancer.SHARED_FLAVOR).build();
TargetNode<?, ?> framework1BinaryNode = AppleLibraryBuilder.createBuilder(framework1BinaryTarget).build();
TargetNode<?, ?> framework1Node = AppleBundleBuilder.createBuilder(framework1Target).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(framework1BinaryTarget).setDeps(ImmutableSortedSet.of(framework2Target)).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(framework1Target)).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(framework1Node, framework2Node, framework1BinaryNode, framework2BinaryNode, sharedLibraryNode, bundleNode), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:framework_1#default,shared");
assertEquals(target.getProductType(), ProductType.FRAMEWORK);
for (PBXBuildPhase buildPhase : target.getBuildPhases()) {
if (buildPhase instanceof PBXCopyFilesBuildPhase) {
PBXCopyFilesBuildPhase copyFilesBuildPhase = (PBXCopyFilesBuildPhase) buildPhase;
assertThat(copyFilesBuildPhase.getDstSubfolderSpec().getDestination(), Matchers.not(PBXCopyFilesBuildPhase.Destination.FRAMEWORKS));
}
}
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.
the class ProjectGeneratorTest method testAppleLibraryExportedLinkerFlags.
@Test
public void testAppleLibraryExportedLinkerFlags() throws IOException {
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setExportedLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("-Xlinker"), StringWithMacrosUtils.format("-lhello"))).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
ImmutableMap<String, String> settings = getBuildSettings(buildTarget, target, "Debug");
assertEquals("$(inherited) -Xlinker -lhello", settings.get("OTHER_LDFLAGS"));
}
Aggregations