Search in sources :

Example 21 with PBXFileReference

use of com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference in project bazel by bazelbuild.

the class PBXFileReferences method get.

/**
   * Supplies a reference, containing values for fields specified in {@code reference}.
   */
public PBXFileReference get(FileReference reference) {
    for (PBXFileReference existing : Mapping.of(cache, reference).asSet()) {
        return existing;
    }
    PBXFileReference result = new PBXFileReference(reference.name(), reference.path().orNull(), reference.sourceTree());
    result.setExplicitFileType(reference.explicitFileType());
    cache.put(reference, result);
    return result;
}
Also used : PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)

Example 22 with PBXFileReference

use of com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference in project bazel by bazelbuild.

the class CurrentVersionSetter method trySetCurrentVersion.

private void trySetCurrentVersion(XCVersionGroup group) {
    if (group.getSourceTree() != SourceTree.GROUP) {
        return;
    }
    Path groupPath = workspaceRoot.resolve(group.getPath());
    Path currentVersionPlist = groupPath.resolve(".xccurrentversion");
    if (!Files.isReadable(currentVersionPlist)) {
        return;
    }
    NSDictionary plist;
    try {
        plist = PlistMerging.readPlistFile(currentVersionPlist);
    } catch (IOException e) {
        return;
    }
    NSString currentVersion = (NSString) plist.get("_XCCurrentVersionName");
    if (currentVersion == null) {
        return;
    }
    for (PBXFileReference child : group.getChildren()) {
        child.setExplicitFileType(Optional.of("wrapper.xcdatamodel"));
        if (child.getName().equals(currentVersion.getContent())) {
            group.setCurrentVersion(Optional.of(child));
        }
    }
}
Also used : Path(java.nio.file.Path) NSDictionary(com.dd.plist.NSDictionary) IOException(java.io.IOException) NSString(com.dd.plist.NSString) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)

Example 23 with PBXFileReference

use of com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference in project buck by facebook.

the class NewNativeTargetProjectMutatorTest method testSourceGroups.

@Test
public void testSourceGroups() throws NoSuchBuildTargetException {
    NewNativeTargetProjectMutator mutator = mutatorWithCommonDefaults();
    SourcePath foo = new FakeSourcePath("Group1/foo.m");
    SourcePath bar = new FakeSourcePath("Group1/bar.m");
    SourcePath baz = new FakeSourcePath("Group2/baz.m");
    mutator.setSourcesWithFlags(ImmutableSet.of(SourceWithFlags.of(foo), SourceWithFlags.of(bar, ImmutableList.of("-Wall")), SourceWithFlags.of(baz)));
    NewNativeTargetProjectMutator.Result result = mutator.buildTargetAndAddToProject(generatedProject, true);
    PBXGroup sourcesGroup = result.targetGroup.get().getOrCreateChildGroupByName("Sources");
    PBXGroup group1 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 0);
    assertEquals("Group1", group1.getName());
    assertThat(group1.getChildren(), hasSize(2));
    PBXFileReference fileRefBar = (PBXFileReference) Iterables.get(group1.getChildren(), 0);
    assertEquals("bar.m", fileRefBar.getName());
    PBXFileReference fileRefFoo = (PBXFileReference) Iterables.get(group1.getChildren(), 1);
    assertEquals("foo.m", fileRefFoo.getName());
    PBXGroup group2 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 1);
    assertEquals("Group2", group2.getName());
    assertThat(group2.getChildren(), hasSize(1));
    PBXFileReference fileRefBaz = (PBXFileReference) Iterables.get(group2.getChildren(), 0);
    assertEquals("baz.m", fileRefBaz.getName());
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) Test(org.junit.Test)

Example 24 with PBXFileReference

use of com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference in project buck by facebook.

the class NewNativeTargetProjectMutatorTest method testFrameworkBuildPhase.

@Test
public void testFrameworkBuildPhase() throws NoSuchBuildTargetException {
    NewNativeTargetProjectMutator mutator = mutatorWithCommonDefaults();
    mutator.setFrameworks(ImmutableSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SDKROOT, Paths.get("Foo.framework"), Optional.empty()))));
    mutator.setArchives(ImmutableSet.of(new PBXFileReference("libdep.a", "libdep.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty())));
    NewNativeTargetProjectMutator.Result result = mutator.buildTargetAndAddToProject(generatedProject, true);
    assertHasSingletonFrameworksPhaseWithFrameworkEntries(result.target, ImmutableList.of("$SDKROOT/Foo.framework", "$BUILT_PRODUCTS_DIR/libdep.a"));
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) Test(org.junit.Test)

Example 25 with PBXFileReference

use of com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference in project buck by facebook.

the class NewNativeTargetProjectMutatorTest method testPrefixHeaderInSourceGroup.

@Test
public void testPrefixHeaderInSourceGroup() throws NoSuchBuildTargetException {
    NewNativeTargetProjectMutator mutator = mutatorWithCommonDefaults();
    SourcePath prefixHeader = new FakeSourcePath("Group1/prefix.pch");
    mutator.setPrefixHeader(Optional.of(prefixHeader));
    NewNativeTargetProjectMutator.Result result = mutator.buildTargetAndAddToProject(generatedProject, true);
    // No matter where the prefixHeader file is it should always be directly inside Sources
    PBXGroup sourcesGroup = result.targetGroup.get().getOrCreateChildGroupByName("Sources");
    assertThat(sourcesGroup.getChildren(), hasSize(1));
    PBXFileReference fileRef = (PBXFileReference) Iterables.get(sourcesGroup.getChildren(), 0);
    assertEquals("prefix.pch", fileRef.getName());
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) Test(org.junit.Test)

Aggregations

PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)40 Test (org.junit.Test)26 Path (java.nio.file.Path)19 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)18 PBXGroup (com.facebook.buck.apple.xcode.xcodeproj.PBXGroup)17 BuildTarget (com.facebook.buck.model.BuildTarget)14 PBXNativeTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget)13 NSString (com.dd.plist.NSString)12 PBXProject (com.facebook.buck.apple.xcode.xcodeproj.PBXProject)12 ImmutableMap (com.google.common.collect.ImmutableMap)12 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)11 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)11 SourcePath (com.facebook.buck.rules.SourcePath)10 DocumentBuilder (javax.xml.parsers.DocumentBuilder)10 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)10 XPath (javax.xml.xpath.XPath)10 XPathExpression (javax.xml.xpath.XPathExpression)10 XPathFactory (javax.xml.xpath.XPathFactory)10 Document (org.w3c.dom.Document)10 NodeList (org.w3c.dom.NodeList)10