Search in sources :

Example 1 with PBXVariantGroup

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);
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) PBXVariantGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXVariantGroup) HumanReadableException(com.facebook.buck.util.HumanReadableException) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) NSString(com.dd.plist.NSString) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)

Example 2 with PBXVariantGroup

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());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXReference(com.facebook.buck.apple.xcode.xcodeproj.PBXReference) PBXVariantGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXVariantGroup) BuildTarget(com.facebook.buck.model.BuildTarget) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) PBXProject(com.facebook.buck.apple.xcode.xcodeproj.PBXProject) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) Test(org.junit.Test)

Example 3 with PBXVariantGroup

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()));
    }
}
Also used : Path(java.nio.file.Path) PBXReference(com.facebook.buck.apple.xcode.xcodeproj.PBXReference) PBXVariantGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXVariantGroup)

Aggregations

PBXVariantGroup (com.facebook.buck.apple.xcode.xcodeproj.PBXVariantGroup)3 PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)2 PBXGroup (com.facebook.buck.apple.xcode.xcodeproj.PBXGroup)2 PBXReference (com.facebook.buck.apple.xcode.xcodeproj.PBXReference)2 Path (java.nio.file.Path)2 NSString (com.dd.plist.NSString)1 PBXProject (com.facebook.buck.apple.xcode.xcodeproj.PBXProject)1 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)1 SourcePath (com.facebook.buck.rules.SourcePath)1 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1 Test (org.junit.Test)1