use of com.facebook.buck.apple.xcode.XCScheme 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.XCScheme in project buck by facebook.
the class WorkspaceAndProjectGeneratorTest method targetsForWorkspaceWithExtraTargets.
@Test
public void targetsForWorkspaceWithExtraTargets() throws IOException, InterruptedException {
BuildTarget fooLibTarget = BuildTarget.builder(rootCell.getRoot(), "//foo", "FooLib").build();
TargetNode<AppleLibraryDescription.Arg, ?> fooLib = AppleLibraryBuilder.createBuilder(fooLibTarget).build();
BuildTarget barLibTarget = BuildTarget.builder(rootCell.getRoot(), "//bar", "BarLib").build();
TargetNode<AppleLibraryDescription.Arg, ?> barLib = AppleLibraryBuilder.createBuilder(barLibTarget).build();
BuildTarget bazLibTarget = BuildTarget.builder(rootCell.getRoot(), "//baz", "BazLib").build();
TargetNode<AppleLibraryDescription.Arg, ?> bazLib = AppleLibraryBuilder.createBuilder(bazLibTarget).setDeps(ImmutableSortedSet.of(barLibTarget)).build();
TargetNode<XcodeWorkspaceConfigDescription.Arg, ?> workspaceNode = XcodeWorkspaceConfigBuilder.createBuilder(BuildTarget.builder(rootCell.getRoot(), "//foo", "workspace").build()).setWorkspaceName(Optional.of("workspace")).setSrcTarget(Optional.of(fooLibTarget)).setExtraTargets(ImmutableSortedSet.of(bazLibTarget)).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(fooLib, barLib, bazLib, workspaceNode);
WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(rootCell, targetGraph, workspaceNode.getConstructorArg(), workspaceNode.getBuildTarget(), ImmutableSet.of(ProjectGenerator.Option.INCLUDE_TESTS, ProjectGenerator.Option.INCLUDE_DEPENDENCIES_TESTS), false, /* combinedProject */
false, /* buildWithBuck */
ImmutableList.of(), Optional.empty(), false, /* parallelizeBuild */
new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, "BUCK", getBuildRuleResolverForNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
Map<Path, ProjectGenerator> projectGenerators = new HashMap<>();
generator.generateWorkspaceAndDependentProjects(projectGenerators, MoreExecutors.newDirectExecutorService());
ProjectGenerator fooProjectGenerator = projectGenerators.get(Paths.get("foo"));
ProjectGenerator barProjectGenerator = projectGenerators.get(Paths.get("bar"));
ProjectGenerator bazProjectGenerator = projectGenerators.get(Paths.get("baz"));
assertNotNull("The Foo project should have been generated", fooProjectGenerator);
assertNotNull("The Bar project should have been generated", barProjectGenerator);
assertNotNull("The Baz project should have been generated", bazProjectGenerator);
ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(fooProjectGenerator.getGeneratedProject(), "//foo:FooLib");
ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(barProjectGenerator.getGeneratedProject(), "//bar:BarLib");
ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(bazProjectGenerator.getGeneratedProject(), "//baz:BazLib");
XCScheme mainScheme = generator.getSchemeGenerators().get("workspace").getOutputScheme().get();
XCScheme.BuildAction mainSchemeBuildAction = mainScheme.getBuildAction().get();
// I wish we could use Hamcrest contains() here, but we hit
// https://code.google.com/p/hamcrest/issues/detail?id=190 if we do that.
assertThat(mainSchemeBuildAction.getBuildActionEntries(), hasSize(3));
assertThat(mainSchemeBuildAction.getBuildActionEntries().get(0), withNameAndBuildingFor("FooLib", equalTo(XCScheme.BuildActionEntry.BuildFor.DEFAULT)));
assertThat(mainSchemeBuildAction.getBuildActionEntries().get(1), withNameAndBuildingFor("BarLib", equalTo(XCScheme.BuildActionEntry.BuildFor.DEFAULT)));
assertThat(mainSchemeBuildAction.getBuildActionEntries().get(2), withNameAndBuildingFor("BazLib", equalTo(XCScheme.BuildActionEntry.BuildFor.DEFAULT)));
}
use of com.facebook.buck.apple.xcode.XCScheme in project buck by facebook.
the class WorkspaceAndProjectGeneratorTest method targetsForWorkspaceWithExtraSchemes.
@Test
public void targetsForWorkspaceWithExtraSchemes() throws IOException, InterruptedException {
setUpWorkspaceWithSchemeAndProjects();
WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(rootCell, targetGraph, workspaceWithExtraSchemeNode.getConstructorArg(), workspaceWithExtraSchemeNode.getBuildTarget(), ImmutableSet.of(ProjectGenerator.Option.INCLUDE_TESTS, ProjectGenerator.Option.INCLUDE_DEPENDENCIES_TESTS), false, /* combinedProject */
false, /* buildWithBuck */
ImmutableList.of(), Optional.empty(), false, /* parallelizeBuild */
new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, "BUCK", getBuildRuleResolverForNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
Map<Path, ProjectGenerator> projectGenerators = new HashMap<>();
generator.generateWorkspaceAndDependentProjects(projectGenerators, MoreExecutors.newDirectExecutorService());
ProjectGenerator fooProjectGenerator = projectGenerators.get(Paths.get("foo"));
ProjectGenerator barProjectGenerator = projectGenerators.get(Paths.get("bar"));
ProjectGenerator bazProjectGenerator = projectGenerators.get(Paths.get("baz"));
ProjectGenerator quxProjectGenerator = projectGenerators.get(Paths.get("qux"));
assertNotNull("The Qux project should have been generated", quxProjectGenerator);
assertNotNull("The Foo project should have been generated", fooProjectGenerator);
assertNotNull("The Bar project should have been generated", barProjectGenerator);
assertNotNull("The Baz project should have been generated", bazProjectGenerator);
ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(fooProjectGenerator.getGeneratedProject(), "//foo:FooBin");
ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(fooProjectGenerator.getGeneratedProject(), "//foo:FooLib");
ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(fooProjectGenerator.getGeneratedProject(), "//foo:FooBinTest");
ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(fooProjectGenerator.getGeneratedProject(), "//foo:FooLibTest");
ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(barProjectGenerator.getGeneratedProject(), "//bar:BarLib");
ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(bazProjectGenerator.getGeneratedProject(), "//baz:BazLib");
ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(quxProjectGenerator.getGeneratedProject(), "//qux:QuxBin");
XCScheme mainScheme = generator.getSchemeGenerators().get("workspace").getOutputScheme().get();
XCScheme.BuildAction mainSchemeBuildAction = mainScheme.getBuildAction().get();
// I wish we could use Hamcrest contains() here, but we hit
// https://code.google.com/p/hamcrest/issues/detail?id=190 if we do that.
assertThat(mainSchemeBuildAction.getBuildActionEntries(), hasSize(2));
assertThat(mainSchemeBuildAction.getBuildActionEntries().get(0), withNameAndBuildingFor("BarLib", equalTo(XCScheme.BuildActionEntry.BuildFor.DEFAULT)));
assertThat(mainSchemeBuildAction.getBuildActionEntries().get(1), withNameAndBuildingFor("QuxBin", equalTo(XCScheme.BuildActionEntry.BuildFor.DEFAULT)));
XCScheme fooScheme = generator.getSchemeGenerators().get("FooScheme").getOutputScheme().get();
XCScheme.BuildAction fooSchemeBuildAction = fooScheme.getBuildAction().get();
assertThat(fooSchemeBuildAction.getBuildActionEntries(), hasSize(6));
assertThat(fooSchemeBuildAction.getBuildActionEntries().get(0), withNameAndBuildingFor("BarLib", equalTo(XCScheme.BuildActionEntry.BuildFor.DEFAULT)));
assertThat(fooSchemeBuildAction.getBuildActionEntries().get(1), withNameAndBuildingFor("FooLib", equalTo(XCScheme.BuildActionEntry.BuildFor.DEFAULT)));
assertThat(fooSchemeBuildAction.getBuildActionEntries().get(2), withNameAndBuildingFor("FooBin", equalTo(XCScheme.BuildActionEntry.BuildFor.DEFAULT)));
assertThat(fooSchemeBuildAction.getBuildActionEntries().get(3), withNameAndBuildingFor("BazLib", equalTo(XCScheme.BuildActionEntry.BuildFor.TEST_ONLY)));
assertThat(fooSchemeBuildAction.getBuildActionEntries().get(4), withNameAndBuildingFor("FooLibTest", equalTo(XCScheme.BuildActionEntry.BuildFor.TEST_ONLY)));
assertThat(fooSchemeBuildAction.getBuildActionEntries().get(5), withNameAndBuildingFor("FooBinTest", equalTo(XCScheme.BuildActionEntry.BuildFor.TEST_ONLY)));
}
use of com.facebook.buck.apple.xcode.XCScheme in project buck by facebook.
the class WorkspaceAndProjectGeneratorTest method buildWithBuck.
@Test
public void buildWithBuck() throws IOException, InterruptedException {
Optional<Path> buck = new ExecutableFinder().getOptionalExecutable(Paths.get("buck"), ImmutableMap.of());
assumeThat(buck.isPresent(), is(true));
WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(rootCell, targetGraph, workspaceNode.getConstructorArg(), workspaceNode.getBuildTarget(), ImmutableSet.of(ProjectGenerator.Option.INCLUDE_TESTS, ProjectGenerator.Option.INCLUDE_DEPENDENCIES_TESTS), false, /* combinedProject */
true, /* buildWithBuck */
ImmutableList.of(), Optional.empty(), false, /* parallelizeBuild */
new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, "BUCK", getBuildRuleResolverForNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
Map<Path, ProjectGenerator> projectGenerators = new HashMap<>();
generator.generateWorkspaceAndDependentProjects(projectGenerators, MoreExecutors.newDirectExecutorService());
ProjectGenerator fooProjectGenerator = projectGenerators.get(Paths.get("foo"));
assertThat(fooProjectGenerator, is(notNullValue()));
PBXTarget buildWithBuckTarget = null;
for (PBXTarget target : fooProjectGenerator.getGeneratedProject().getTargets()) {
if (target.getProductName() != null && target.getProductName().endsWith("-Buck")) {
buildWithBuckTarget = target;
break;
}
}
assertThat(buildWithBuckTarget, is(notNullValue()));
assertThat(buildWithBuckTarget, is(instanceOf(PBXAggregateTarget.class)));
String gid = buildWithBuckTarget.getGlobalID();
Optional<XCScheme> scheme = Iterables.getOnlyElement(generator.getSchemeGenerators().values()).getOutputScheme();
assertThat(scheme.isPresent(), is(true));
XCScheme.BuildableReference buildWithBuckBuildableReference = null;
for (XCScheme.BuildActionEntry buildActionEntry : scheme.get().getBuildAction().get().getBuildActionEntries()) {
XCScheme.BuildableReference buildableReference = buildActionEntry.getBuildableReference();
if (buildableReference.getBlueprintIdentifier().equals(gid)) {
buildWithBuckBuildableReference = buildableReference;
}
}
assertThat(buildWithBuckBuildableReference, is(notNullValue()));
assertThat(buildWithBuckBuildableReference.getBuildableName(), equalTo("//foo:bin-Buck"));
}
use of com.facebook.buck.apple.xcode.XCScheme in project buck by facebook.
the class WorkspaceAndProjectGeneratorTest method workspaceAndProjectsWithoutDependenciesTests.
@Test
public void workspaceAndProjectsWithoutDependenciesTests() throws IOException, InterruptedException {
WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(rootCell, targetGraph, workspaceNode.getConstructorArg(), workspaceNode.getBuildTarget(), ImmutableSet.of(ProjectGenerator.Option.INCLUDE_TESTS), false, /* combinedProject */
false, /* buildWithBuck */
ImmutableList.of(), Optional.empty(), false, /* parallelizeBuild */
new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, "BUCK", getBuildRuleResolverForNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
Map<Path, ProjectGenerator> projectGenerators = new HashMap<>();
generator.generateWorkspaceAndDependentProjects(projectGenerators, MoreExecutors.newDirectExecutorService());
Optional<XCScheme> scheme = Iterables.getOnlyElement(generator.getSchemeGenerators().values()).getOutputScheme();
assertThat(scheme.isPresent(), is(true));
assertThat("Test for project FooBin should have been generated", scheme.get().getBuildAction().get().getBuildActionEntries(), hasItem(withNameAndBuildingFor("bin-xctest", equalTo(XCScheme.BuildActionEntry.BuildFor.TEST_ONLY))));
assertThat("Test for project FooLib should not be generated at all", scheme.get().getBuildAction().get().getBuildActionEntries(), not(hasItem(withNameAndBuildingFor("lib-xctest", equalTo(XCScheme.BuildActionEntry.BuildFor.TEST_ONLY)))));
}
Aggregations