Search in sources :

Example 1 with AppleWrapperResourceArg

use of com.facebook.buck.apple.AppleWrapperResourceArg in project buck by facebook.

the class NewNativeTargetProjectMutator method collectResourcePathsFromConstructorArgs.

private void collectResourcePathsFromConstructorArgs(Set<AppleResourceDescription.Arg> resourceArgs, Set<AppleAssetCatalogDescription.Arg> assetCatalogArgs, Set<AppleWrapperResourceArg> resourcePathArgs, ImmutableSet.Builder<Path> resourceFilesBuilder, ImmutableSet.Builder<Path> resourceDirsBuilder, ImmutableSet.Builder<Path> variantResourceFilesBuilder) {
    for (AppleResourceDescription.Arg arg : resourceArgs) {
        resourceFilesBuilder.addAll(Iterables.transform(arg.files, sourcePathResolver));
        resourceDirsBuilder.addAll(Iterables.transform(arg.dirs, sourcePathResolver));
        variantResourceFilesBuilder.addAll(Iterables.transform(arg.variants, sourcePathResolver));
    }
    for (AppleAssetCatalogDescription.Arg arg : assetCatalogArgs) {
        resourceDirsBuilder.addAll(Iterables.transform(arg.dirs, sourcePathResolver));
    }
    for (AppleWrapperResourceArg arg : resourcePathArgs) {
        resourceDirsBuilder.add(arg.path);
    }
}
Also used : AppleResourceDescription(com.facebook.buck.apple.AppleResourceDescription) AppleAssetCatalogDescription(com.facebook.buck.apple.AppleAssetCatalogDescription) AppleWrapperResourceArg(com.facebook.buck.apple.AppleWrapperResourceArg)

Example 2 with AppleWrapperResourceArg

use of com.facebook.buck.apple.AppleWrapperResourceArg in project buck by facebook.

the class ProjectGenerator method addSceneKitAssetsIntoTarget.

private void addSceneKitAssetsIntoTarget(TargetNode<? extends CxxLibraryDescription.Arg, ?> targetNode, PBXGroup targetGroup) throws IOException {
    ImmutableSet<AppleWrapperResourceArg> allSceneKitAssets = AppleBuildRules.collectTransitiveBuildRules(targetGraph, Optional.of(dependenciesCache), AppleBuildRules.SCENEKIT_ASSETS_DESCRIPTION_CLASSES, ImmutableList.of(targetNode));
    for (final AppleWrapperResourceArg sceneKitAssets : allSceneKitAssets) {
        PBXGroup resourcesGroup = targetGroup.getOrCreateChildGroupByName("Resources");
        resourcesGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(sceneKitAssets.path), Optional.empty()));
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) AppleWrapperResourceArg(com.facebook.buck.apple.AppleWrapperResourceArg)

Example 3 with AppleWrapperResourceArg

use of com.facebook.buck.apple.AppleWrapperResourceArg in project buck by facebook.

the class ProjectGenerator method addCoreDataModelBuildPhase.

private void addCoreDataModelBuildPhase(PBXGroup targetGroup, Iterable<AppleWrapperResourceArg> dataModels) throws IOException {
    for (final AppleWrapperResourceArg dataModel : dataModels) {
        // Core data models go in the resources group also.
        PBXGroup resourcesGroup = targetGroup.getOrCreateChildGroupByName("Resources");
        if (CoreDataModelDescription.isVersionedDataModel(dataModel)) {
            // It's safe to do I/O here to figure out the current version because we're returning all
            // the versions and the file pointing to the current version from
            // getInputsToCompareToOutput(), so the rule will be correctly detected as stale if any of
            // them change.
            final String currentVersionFileName = ".xccurrentversion";
            final String currentVersionKey = "_XCCurrentVersionName";
            final XCVersionGroup versionGroup = resourcesGroup.getOrCreateChildVersionGroupsBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(dataModel.path), Optional.empty()));
            projectFilesystem.walkRelativeFileTree(dataModel.path, new SimpleFileVisitor<Path>() {

                @Override
                public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
                    if (dir.equals(dataModel.path)) {
                        return FileVisitResult.CONTINUE;
                    }
                    versionGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(dir), Optional.empty()));
                    return FileVisitResult.SKIP_SUBTREE;
                }
            });
            Path currentVersionPath = dataModel.path.resolve(currentVersionFileName);
            try (InputStream in = projectFilesystem.newFileInputStream(currentVersionPath)) {
                NSObject rootObject;
                try {
                    rootObject = PropertyListParser.parse(in);
                } catch (IOException e) {
                    throw e;
                } catch (Exception e) {
                    rootObject = null;
                }
                if (!(rootObject instanceof NSDictionary)) {
                    throw new HumanReadableException("Malformed %s file.", currentVersionFileName);
                }
                NSDictionary rootDictionary = (NSDictionary) rootObject;
                NSObject currentVersionName = rootDictionary.objectForKey(currentVersionKey);
                if (!(currentVersionName instanceof NSString)) {
                    throw new HumanReadableException("Malformed %s file.", currentVersionFileName);
                }
                PBXFileReference ref = versionGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(dataModel.path.resolve(currentVersionName.toString())), Optional.empty()));
                versionGroup.setCurrentVersion(Optional.of(ref));
            } catch (NoSuchFileException e) {
                if (versionGroup.getChildren().size() == 1) {
                    versionGroup.setCurrentVersion(Optional.of(Iterables.get(versionGroup.getChildren(), 0)));
                }
            }
        } else {
            resourcesGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, pathRelativizer.outputDirToRootRelative(dataModel.path), Optional.empty()));
        }
    }
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) NSObject(com.dd.plist.NSObject) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NSDictionary(com.dd.plist.NSDictionary) NoSuchFileException(java.nio.file.NoSuchFileException) FileVisitResult(java.nio.file.FileVisitResult) NSString(com.dd.plist.NSString) IOException(java.io.IOException) NSString(com.dd.plist.NSString) MacroException(com.facebook.buck.model.MacroException) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) IOException(java.io.IOException) NoSuchFileException(java.nio.file.NoSuchFileException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) HumanReadableException(com.facebook.buck.util.HumanReadableException) XCVersionGroup(com.facebook.buck.apple.xcode.xcodeproj.XCVersionGroup) HumanReadableException(com.facebook.buck.util.HumanReadableException) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) AppleWrapperResourceArg(com.facebook.buck.apple.AppleWrapperResourceArg) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)

Aggregations

AppleWrapperResourceArg (com.facebook.buck.apple.AppleWrapperResourceArg)3 PBXGroup (com.facebook.buck.apple.xcode.xcodeproj.PBXGroup)2 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)2 NSDictionary (com.dd.plist.NSDictionary)1 NSObject (com.dd.plist.NSObject)1 NSString (com.dd.plist.NSString)1 AppleAssetCatalogDescription (com.facebook.buck.apple.AppleAssetCatalogDescription)1 AppleResourceDescription (com.facebook.buck.apple.AppleResourceDescription)1 PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)1 XCVersionGroup (com.facebook.buck.apple.xcode.xcodeproj.XCVersionGroup)1 MacroException (com.facebook.buck.model.MacroException)1 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)1 BuildTargetSourcePath (com.facebook.buck.rules.BuildTargetSourcePath)1 PathSourcePath (com.facebook.buck.rules.PathSourcePath)1 SourcePath (com.facebook.buck.rules.SourcePath)1 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1