use of com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath 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.SourceTreePath 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.SourceTreePath in project buck by facebook.
the class NewNativeTargetProjectMutator method addSourcePathToHeadersBuildPhase.
private void addSourcePathToHeadersBuildPhase(SourcePath headerPath, PBXGroup headersGroup, HeaderVisibility visibility) {
PBXFileReference fileReference = headersGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputPathToSourcePath(headerPath), Optional.empty()));
PBXBuildFile buildFile = new PBXBuildFile(fileReference);
if (visibility != HeaderVisibility.PRIVATE) {
NSDictionary settings = new NSDictionary();
settings.put("ATTRIBUTES", new NSArray(new NSString(AppleHeaderVisibilities.toXcodeAttribute(visibility))));
buildFile.setSettings(Optional.of(settings));
} else {
buildFile.setSettings(Optional.empty());
}
}
use of com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath in project buck by facebook.
the class FrameworkPathTypeCoercer method coerce.
@Override
public FrameworkPath coerce(CellPathResolver cellRoots, ProjectFilesystem filesystem, Path pathRelativeToProjectRoot, Object object) throws CoerceFailedException {
if (object instanceof String) {
Path path = Paths.get((String) object);
String firstElement = Preconditions.checkNotNull(Iterables.getFirst(path, Paths.get(""))).toString();
if (firstElement.startsWith("$")) {
// NOPMD - length() > 0 && charAt(0) == '$' is ridiculous
Optional<PBXReference.SourceTree> sourceTree = PBXReference.SourceTree.fromBuildSetting(firstElement);
if (sourceTree.isPresent()) {
int nameCount = path.getNameCount();
if (nameCount < 2) {
throw new HumanReadableException("Invalid source tree path: '%s'. Should have at least one path component after" + "'%s'.", path, firstElement);
}
return FrameworkPath.ofSourceTreePath(new SourceTreePath(sourceTree.get(), path.subpath(1, path.getNameCount()), Optional.empty()));
} else {
throw new HumanReadableException("Unknown SourceTree: '%s'. Should be one of: %s", firstElement, Joiner.on(", ").join(Iterables.transform(ImmutableList.copyOf(PBXReference.SourceTree.values()), input -> "$" + input.toString())));
}
} else {
return FrameworkPath.ofSourcePath(sourcePathTypeCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, object));
}
}
throw CoerceFailedException.simple(object, getOutputClass(), "input should be either a source tree path or a source path");
}
use of com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath in project buck by facebook.
the class ProjectGeneratorTest method testAppleBinaryRule.
@Test
public void testAppleBinaryRule() throws IOException {
BuildTarget depTarget = BuildTarget.builder(rootPath, "//dep", "dep").build();
TargetNode<?, ?> depNode = AppleLibraryBuilder.createBuilder(depTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("e.m")))).build();
BuildTarget binaryTarget = BuildTarget.builder(rootPath, "//foo", "binary").build();
TargetNode<?, ?> binaryNode = AppleBinaryBuilder.createBuilder(binaryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.m"), ImmutableList.of("-foo")))).setExtraXcodeSources(ImmutableList.of(new FakeSourcePath("libsomething.a"))).setHeaders(ImmutableSortedSet.of(new FakeSourcePath("foo.h"))).setFrameworks(ImmutableSortedSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SDKROOT, Paths.get("Foo.framework"), Optional.empty())))).setDeps(ImmutableSortedSet.of(depTarget)).setHeaderPathPrefix(Optional.empty()).setPrefixHeader(Optional.empty()).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(depNode, binaryNode));
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:binary");
assertHasConfigurations(target, "Debug");
assertEquals(target.getProductType(), ProductType.TOOL);
assertEquals("Should have exact number of build phases", 2, target.getBuildPhases().size());
assertHasSingletonSourcesPhaseWithSourcesAndFlags(target, ImmutableMap.of("foo.m", Optional.of("-foo"), "libsomething.a", Optional.empty()));
ProjectGeneratorTestUtils.assertHasSingletonFrameworksPhaseWithFrameworkEntries(target, ImmutableList.of("$SDKROOT/Foo.framework", // Propagated library from deps.
"$BUILT_PRODUCTS_DIR/libdep.a"));
// this test does not have a dependency on any asset catalogs, so verify no build phase for them
// exists.
assertTrue(FluentIterable.from(target.getBuildPhases()).filter(PBXResourcesBuildPhase.class).isEmpty());
}
Aggregations