use of com.facebook.buck.apple.xcode.xcodeproj.PBXGroup in project buck by facebook.
the class NewNativeTargetProjectMutator method addPhasesAndGroupsForSources.
private void addPhasesAndGroupsForSources(PBXNativeTarget target, PBXGroup targetGroup) {
PBXGroup sourcesGroup = targetGroup.getOrCreateChildGroupByName("Sources");
// Sources groups stay in the order in which they're declared in the BUCK file.
sourcesGroup.setSortPolicy(PBXGroup.SortPolicy.UNSORTED);
PBXSourcesBuildPhase sourcesBuildPhase = new PBXSourcesBuildPhase();
PBXHeadersBuildPhase headersBuildPhase = new PBXHeadersBuildPhase();
traverseGroupsTreeAndHandleSources(sourcesGroup, sourcesBuildPhase, RuleUtils.createGroupsFromSourcePaths(pathRelativizer::outputPathToSourcePath, sourcesWithFlags, extraXcodeSources, publicHeaders, privateHeaders));
if (prefixHeader.isPresent()) {
SourceTreePath prefixHeaderSourceTreePath = new SourceTreePath(PBXReference.SourceTree.GROUP, pathRelativizer.outputPathToSourcePath(prefixHeader.get()), Optional.empty());
sourcesGroup.getOrCreateFileReferenceBySourceTreePath(prefixHeaderSourceTreePath);
}
if (infoPlist.isPresent()) {
SourceTreePath infoPlistSourceTreePath = new SourceTreePath(PBXReference.SourceTree.GROUP, pathRelativizer.outputPathToSourcePath(infoPlist.get()), Optional.empty());
sourcesGroup.getOrCreateFileReferenceBySourceTreePath(infoPlistSourceTreePath);
}
if (bridgingHeader.isPresent()) {
SourceTreePath bridgingHeaderSourceTreePath = new SourceTreePath(PBXReference.SourceTree.GROUP, pathRelativizer.outputPathToSourcePath(bridgingHeader.get()), Optional.empty());
sourcesGroup.getOrCreateFileReferenceBySourceTreePath(bridgingHeaderSourceTreePath);
}
if (!sourcesBuildPhase.getFiles().isEmpty()) {
target.getBuildPhases().add(sourcesBuildPhase);
}
if (!headersBuildPhase.getFiles().isEmpty()) {
target.getBuildPhases().add(headersBuildPhase);
}
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXGroup in project buck by facebook.
the class NewNativeTargetProjectMutator method addResourcesFileReference.
private void addResourcesFileReference(PBXGroup targetGroup, ImmutableSet<Path> resourceFiles, ImmutableSet<Path> resourceDirs, ImmutableSet<Path> variantResourceFiles, Consumer<? super PBXFileReference> resourceCallback, Consumer<? super PBXVariantGroup> variantGroupCallback) {
if (resourceFiles.isEmpty() && resourceDirs.isEmpty() && variantResourceFiles.isEmpty()) {
return;
}
PBXGroup resourcesGroup = targetGroup.getOrCreateChildGroupByName("Resources");
for (Path path : resourceFiles) {
PBXFileReference fileReference = resourcesGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(path), Optional.empty()));
resourceCallback.accept(fileReference);
}
for (Path path : resourceDirs) {
PBXFileReference fileReference = resourcesGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(path), Optional.of("folder")));
resourceCallback.accept(fileReference);
}
Map<String, PBXVariantGroup> variantGroups = Maps.newHashMap();
for (Path variantFilePath : variantResourceFiles) {
String lprojSuffix = ".lproj";
Path variantDirectory = variantFilePath.getParent();
if (variantDirectory == null || !variantDirectory.toString().endsWith(lprojSuffix)) {
throw new HumanReadableException("Variant files have to be in a directory with name ending in '.lproj', " + "but '%s' is not.", variantFilePath);
}
String variantDirectoryName = variantDirectory.getFileName().toString();
String variantLocalization = variantDirectoryName.substring(0, variantDirectoryName.length() - lprojSuffix.length());
String variantFileName = variantFilePath.getFileName().toString();
PBXVariantGroup variantGroup = variantGroups.get(variantFileName);
if (variantGroup == null) {
variantGroup = resourcesGroup.getOrCreateChildVariantGroupByName(variantFileName);
variantGroupCallback.accept(variantGroup);
variantGroups.put(variantFileName, variantGroup);
}
SourceTreePath sourceTreePath = new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(variantFilePath), Optional.empty());
variantGroup.getOrCreateVariantFileReferenceByNameAndSourceTreePath(variantLocalization, sourceTreePath);
}
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXGroup in project buck by facebook.
the class NewNativeTargetProjectMutator method traverseGroupsTreeAndHandleSources.
private void traverseGroupsTreeAndHandleSources(final PBXGroup sourcesGroup, final PBXSourcesBuildPhase sourcesBuildPhase, Iterable<GroupedSource> groupedSources) {
GroupedSource.Visitor visitor = new GroupedSource.Visitor() {
@Override
public void visitSourceWithFlags(SourceWithFlags sourceWithFlags) {
addSourcePathToSourcesBuildPhase(sourceWithFlags, sourcesGroup, sourcesBuildPhase);
}
@Override
public void visitPublicHeader(SourcePath publicHeader) {
addSourcePathToHeadersBuildPhase(publicHeader, sourcesGroup, HeaderVisibility.PUBLIC);
}
@Override
public void visitPrivateHeader(SourcePath privateHeader) {
addSourcePathToHeadersBuildPhase(privateHeader, sourcesGroup, HeaderVisibility.PRIVATE);
}
@Override
public void visitSourceGroup(String sourceGroupName, Path sourceGroupPathRelativeToTarget, List<GroupedSource> sourceGroup) {
PBXGroup newSourceGroup = sourcesGroup.getOrCreateChildGroupByName(sourceGroupName);
newSourceGroup.setSourceTree(PBXReference.SourceTree.SOURCE_ROOT);
newSourceGroup.setPath(sourceGroupPathRelativeToTarget.toString());
// Sources groups stay in the order in which they're in the GroupedSource.
newSourceGroup.setSortPolicy(PBXGroup.SortPolicy.UNSORTED);
traverseGroupsTreeAndHandleSources(newSourceGroup, sourcesBuildPhase, sourceGroup);
}
};
for (GroupedSource groupedSource : groupedSources) {
groupedSource.visit(visitor);
}
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXGroup 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);
}
use of com.facebook.buck.apple.xcode.xcodeproj.PBXGroup in project buck by facebook.
the class ProjectGeneratorTest method testAppleLibraryHeaderGroupsWithMappedHeaders.
@Test
public void testAppleLibraryHeaderGroupsWithMappedHeaders() throws IOException {
BuildTarget privateGeneratedTarget = BuildTarget.builder(rootPath, "//foo", "generated1.h").build();
BuildTarget publicGeneratedTarget = BuildTarget.builder(rootPath, "//foo", "generated2.h").build();
TargetNode<?, ?> privateGeneratedNode = ExportFileBuilder.newExportFileBuilder(privateGeneratedTarget).build();
TargetNode<?, ?> publicGeneratedNode = ExportFileBuilder.newExportFileBuilder(publicGeneratedTarget).build();
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setSrcs(ImmutableSortedSet.of()).setHeaders(ImmutableSortedMap.of("any/name.h", new FakeSourcePath("HeaderGroup1/foo.h"), "different/name.h", new FakeSourcePath("HeaderGroup2/baz.h"), "one/more/name.h", new DefaultBuildTargetSourcePath(privateGeneratedTarget))).setExportedHeaders(ImmutableSortedMap.of("yet/another/name.h", new FakeSourcePath("HeaderGroup1/bar.h"), "and/one/more.h", new DefaultBuildTargetSourcePath(publicGeneratedTarget))).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node, privateGeneratedNode, publicGeneratedNode));
projectGenerator.createXcodeProjects();
PBXProject project = projectGenerator.getGeneratedProject();
PBXGroup targetGroup = project.getMainGroup().getOrCreateChildGroupByName(buildTarget.getFullyQualifiedName());
PBXGroup sourcesGroup = targetGroup.getOrCreateChildGroupByName("Sources");
assertThat(sourcesGroup.getChildren(), hasSize(3));
PBXGroup group1 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 0);
assertEquals("HeaderGroup1", group1.getName());
assertThat(group1.getChildren(), hasSize(2));
PBXFileReference fileRefFoo = (PBXFileReference) Iterables.get(group1.getChildren(), 0);
assertEquals("bar.h", fileRefFoo.getName());
PBXFileReference fileRefBar = (PBXFileReference) Iterables.get(group1.getChildren(), 1);
assertEquals("foo.h", fileRefBar.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());
PBXGroup group3 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 2);
assertEquals("foo", group3.getName());
assertThat(group3.getChildren(), hasSize(2));
PBXFileReference fileRefGenerated1 = (PBXFileReference) Iterables.get(group3.getChildren(), 0);
assertEquals("generated1.h", fileRefGenerated1.getName());
PBXFileReference fileRefGenerated2 = (PBXFileReference) Iterables.get(group3.getChildren(), 1);
assertEquals("generated2.h", fileRefGenerated2.getName());
// There should be no PBXHeadersBuildPhase in the 'Buck header map mode'.
PBXTarget target = assertTargetExistsAndReturnTarget(project, "//foo:lib");
assertEquals(0, target.getBuildPhases().stream().filter(input -> input instanceof PBXHeadersBuildPhase).count());
List<Path> headerSymlinkTrees = projectGenerator.getGeneratedHeaderSymlinkTrees();
assertThat(headerSymlinkTrees, hasSize(2));
assertEquals("buck-out/gen/_p/CwkbTNOBmb-pub", headerSymlinkTrees.get(0).toString());
assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-pub"), ImmutableMap.of("yet/another/name.h", "HeaderGroup1/bar.h", "and/one/more.h", "foo/generated2.h"));
assertEquals("buck-out/gen/_p/CwkbTNOBmb-priv", headerSymlinkTrees.get(1).toString());
assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-priv"), ImmutableMap.of("any/name.h", "HeaderGroup1/foo.h", "different/name.h", "HeaderGroup2/baz.h", "one/more/name.h", "foo/generated1.h"));
}
Aggregations