use of com.facebook.buck.apple.xcode.xcodeproj.PBXVariantGroup 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.PBXVariantGroup 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.PBXVariantGroup in project bazel by bazelbuild.
the class PbxReferencesGrouper method dirOfContainingPbxGroup.
/**
* The directory of the PBXGroup that will contain the given reference. For most references, this
* is just the actual parent directory. For {@code PBXVariantGroup}s, whose children are not
* guaranteed to be in any common directory except the client root, this returns the deepest
* common container of each child in the group.
*/
private Path dirOfContainingPbxGroup(PBXReference reference) {
if (reference instanceof PBXVariantGroup) {
PBXVariantGroup variantGroup = (PBXVariantGroup) reference;
Path path = Paths.get(variantGroup.getChildren().get(0).getPath());
for (PBXReference child : variantGroup.getChildren()) {
path = deepestCommonContainer(path, path(child.getPath()));
}
return path;
} else {
return parent(path(reference.getPath()));
}
}
Aggregations