use of com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference in project buck by facebook.
the class NewNativeTargetProjectMutatorTest method testLibraryHeaderGroups.
@Test
public void testLibraryHeaderGroups() throws NoSuchBuildTargetException {
NewNativeTargetProjectMutator mutator = mutatorWithCommonDefaults();
SourcePath foo = new FakeSourcePath("HeaderGroup1/foo.h");
SourcePath bar = new FakeSourcePath("HeaderGroup1/bar.h");
SourcePath baz = new FakeSourcePath("HeaderGroup2/baz.h");
mutator.setPublicHeaders(ImmutableSet.of(bar, baz));
mutator.setPrivateHeaders(ImmutableSet.of(foo));
NewNativeTargetProjectMutator.Result result = mutator.buildTargetAndAddToProject(generatedProject, true);
PBXGroup sourcesGroup = result.targetGroup.get().getOrCreateChildGroupByName("Sources");
assertThat(sourcesGroup.getChildren(), hasSize(2));
PBXGroup group1 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 0);
assertEquals("HeaderGroup1", group1.getName());
assertThat(group1.getChildren(), hasSize(2));
PBXFileReference fileRefBar = (PBXFileReference) Iterables.get(group1.getChildren(), 0);
assertEquals("bar.h", fileRefBar.getName());
PBXFileReference fileRefFoo = (PBXFileReference) Iterables.get(group1.getChildren(), 1);
assertEquals("foo.h", fileRefFoo.getName());
PBXGroup group2 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 1);
assertEquals("HeaderGroup2", group2.getName());
assertThat(group2.getChildren(), hasSize(1));
PBXFileReference fileRefBaz = (PBXFileReference) Iterables.get(group2.getChildren(), 0);
assertEquals("baz.h", fileRefBaz.getName());
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference in project buck by facebook.
the class ProjectGeneratorTest method testAppleResourceWithVariantGroupSetsFileTypeBasedOnPath.
@Test
public void testAppleResourceWithVariantGroupSetsFileTypeBasedOnPath() throws IOException {
BuildTarget resourceTarget = BuildTarget.builder(rootPath, "//foo", "resource").addFlavors(DEFAULT_FLAVOR).build();
TargetNode<?, ?> resourceNode = AppleResourceBuilder.createBuilder(resourceTarget).setFiles(ImmutableSet.of()).setDirs(ImmutableSet.of()).setVariants(ImmutableSet.of(new FakeSourcePath("Base.lproj/Bar.storyboard"))).build();
BuildTarget fooLibraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> fooLibraryNode = AppleLibraryBuilder.createBuilder(fooLibraryTarget).setDeps(ImmutableSortedSet.of(resourceTarget)).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(fooLibraryTarget).setDeps(ImmutableSortedSet.of(resourceTarget)).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(fooLibraryNode, bundleNode, resourceNode), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXProject project = projectGenerator.getGeneratedProject();
PBXGroup targetGroup = project.getMainGroup().getOrCreateChildGroupByName(bundleTarget.getFullyQualifiedName());
PBXGroup resourcesGroup = targetGroup.getOrCreateChildGroupByName("Resources");
PBXVariantGroup storyboardGroup = (PBXVariantGroup) Iterables.get(resourcesGroup.getChildren(), 0);
List<PBXReference> storyboardGroupChildren = storyboardGroup.getChildren();
assertEquals(1, storyboardGroupChildren.size());
assertTrue(storyboardGroupChildren.get(0) instanceof PBXFileReference);
PBXFileReference baseStoryboardReference = (PBXFileReference) storyboardGroupChildren.get(0);
assertEquals("Base", baseStoryboardReference.getName());
// Make sure the file type is set from the path.
assertEquals(Optional.of("file.storyboard"), baseStoryboardReference.getLastKnownFileType());
assertEquals(Optional.empty(), baseStoryboardReference.getExplicitFileType());
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference in project buck by facebook.
the class ProjectGeneratorTest method testConfigurationSerializationWithoutExistingXcconfig.
@Test
public void testConfigurationSerializationWithoutExistingXcconfig() throws IOException {
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of("CUSTOM_SETTING", "VALUE"))).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
assertThat(target.isa(), equalTo("PBXNativeTarget"));
assertThat(target.getProductType(), equalTo(ProductType.STATIC_LIBRARY));
assertHasConfigurations(target, "Debug");
assertKeepsConfigurationsInMainGroup(projectGenerator.getGeneratedProject(), target);
XCBuildConfiguration configuration = target.getBuildConfigurationList().getBuildConfigurationsByName().asMap().get("Debug");
assertEquals(configuration.getBuildSettings().count(), 0);
PBXFileReference xcconfigReference = configuration.getBaseConfigurationReference();
assertEquals(xcconfigReference.getPath(), "../buck-out/gen/foo/lib-Debug.xcconfig");
ImmutableMap<String, String> settings = getBuildSettings(buildTarget, target, "Debug");
assertEquals("$SYMROOT/$CONFIGURATION$EFFECTIVE_PLATFORM_NAME", settings.get("BUILT_PRODUCTS_DIR"));
assertEquals("$BUILT_PRODUCTS_DIR", settings.get("CONFIGURATION_BUILD_DIR"));
assertEquals("VALUE", settings.get("CUSTOM_SETTING"));
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference in project buck by facebook.
the class ProjectGeneratorTestUtils method getBuildSettings.
public static ImmutableMap<String, String> getBuildSettings(ProjectFilesystem projectFilesystem, BuildTarget buildTarget, PBXTarget target, String config) {
XCBuildConfiguration configuration = target.getBuildConfigurationList().getBuildConfigurationsByName().asMap().get(config);
assertEquals(configuration.getBuildSettings().count(), 0);
PBXFileReference xcconfigReference = configuration.getBaseConfigurationReference();
Path xcconfigPath = buildTarget.getBasePath().resolve(xcconfigReference.getPath());
String contents = projectFilesystem.readFileIfItExists(xcconfigPath).get();
// Use a HashMap to allow for duplicate keys.
HashMap<String, String> builder = new HashMap<String, String>();
for (String line : contents.split("\n")) {
String[] parts = line.split(" = ");
builder.put(parts[0], parts[1]);
}
return ImmutableMap.copyOf(builder);
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference 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));
}
Aggregations