Search in sources :

Example 56 with SourcePath

use of com.facebook.buck.rules.SourcePath in project buck by facebook.

the class AppleBundle method addStoryboardProcessingSteps.

private void addStoryboardProcessingSteps(SourcePathResolver resolver, Path sourcePath, Path destinationPath, ImmutableList.Builder<Step> stepsBuilder) {
    if (platform.getName().contains("watch") || isLegacyWatchApp()) {
        LOG.debug("Compiling storyboard %s to storyboardc %s and linking", sourcePath, destinationPath);
        Path compiledStoryboardPath = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s.storyboardc");
        stepsBuilder.add(new IbtoolStep(getProjectFilesystem(), ibtool.getEnvironment(resolver), ibtool.getCommandPrefix(resolver), ImmutableList.of("--target-device", "watch", "--compile"), sourcePath, compiledStoryboardPath));
        stepsBuilder.add(new IbtoolStep(getProjectFilesystem(), ibtool.getEnvironment(resolver), ibtool.getCommandPrefix(resolver), ImmutableList.of("--target-device", "watch", "--link"), compiledStoryboardPath, destinationPath.getParent()));
    } else {
        LOG.debug("Compiling storyboard %s to storyboardc %s", sourcePath, destinationPath);
        String compiledStoryboardFilename = Files.getNameWithoutExtension(destinationPath.toString()) + ".storyboardc";
        Path compiledStoryboardPath = destinationPath.getParent().resolve(compiledStoryboardFilename);
        stepsBuilder.add(new IbtoolStep(getProjectFilesystem(), ibtool.getEnvironment(resolver), ibtool.getCommandPrefix(resolver), ImmutableList.of("--compile"), sourcePath, compiledStoryboardPath));
    }
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) NSString(com.dd.plist.NSString)

Example 57 with SourcePath

use of com.facebook.buck.rules.SourcePath in project buck by facebook.

the class AppleBundle method addResourceProcessingSteps.

private void addResourceProcessingSteps(SourcePathResolver resolver, Path sourcePath, Path destinationPath, ImmutableList.Builder<Step> stepsBuilder) {
    String sourcePathExtension = Files.getFileExtension(sourcePath.toString()).toLowerCase(Locale.US);
    switch(sourcePathExtension) {
        case "plist":
        case "stringsdict":
            LOG.debug("Converting plist %s to binary plist %s", sourcePath, destinationPath);
            stepsBuilder.add(new PlistProcessStep(getProjectFilesystem(), sourcePath, Optional.empty(), destinationPath, ImmutableMap.of(), ImmutableMap.of(), PlistProcessStep.OutputFormat.BINARY));
            break;
        case "storyboard":
            addStoryboardProcessingSteps(resolver, sourcePath, destinationPath, stepsBuilder);
            break;
        case "xib":
            String compiledNibFilename = Files.getNameWithoutExtension(destinationPath.toString()) + ".nib";
            Path compiledNibPath = destinationPath.getParent().resolve(compiledNibFilename);
            LOG.debug("Compiling XIB %s to NIB %s", sourcePath, destinationPath);
            stepsBuilder.add(new IbtoolStep(getProjectFilesystem(), ibtool.getEnvironment(resolver), ibtool.getCommandPrefix(resolver), ImmutableList.of("--compile"), sourcePath, compiledNibPath));
            break;
        default:
            stepsBuilder.add(CopyStep.forFile(getProjectFilesystem(), sourcePath, destinationPath));
            break;
    }
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) NSString(com.dd.plist.NSString)

Example 58 with SourcePath

use of com.facebook.buck.rules.SourcePath in project buck by facebook.

the class AppleDescriptions method createBuildRuleForTransitiveAssetCatalogDependencies.

public static Optional<AppleAssetCatalog> createBuildRuleForTransitiveAssetCatalogDependencies(TargetGraph targetGraph, BuildRuleParams params, SourcePathResolver sourcePathResolver, ApplePlatform applePlatform, Tool actool) {
    TargetNode<?, ?> targetNode = targetGraph.get(params.getBuildTarget());
    ImmutableSet<AppleAssetCatalogDescription.Arg> assetCatalogArgs = AppleBuildRules.collectRecursiveAssetCatalogs(targetGraph, Optional.empty(), ImmutableList.of(targetNode));
    ImmutableSortedSet.Builder<SourcePath> assetCatalogDirsBuilder = ImmutableSortedSet.naturalOrder();
    Optional<String> appIcon = Optional.empty();
    Optional<String> launchImage = Optional.empty();
    AppleAssetCatalogDescription.Optimization optimization = null;
    for (AppleAssetCatalogDescription.Arg arg : assetCatalogArgs) {
        if (optimization == null) {
            optimization = arg.optimization;
        }
        assetCatalogDirsBuilder.addAll(arg.dirs);
        if (arg.appIcon.isPresent()) {
            if (appIcon.isPresent()) {
                throw new HumanReadableException("At most one asset catalog in the dependencies of %s " + "can have a app_icon", params.getBuildTarget());
            }
            appIcon = arg.appIcon;
        }
        if (arg.launchImage.isPresent()) {
            if (launchImage.isPresent()) {
                throw new HumanReadableException("At most one asset catalog in the dependencies of %s " + "can have a launch_image", params.getBuildTarget());
            }
            launchImage = arg.launchImage;
        }
        if (arg.optimization != optimization) {
            throw new HumanReadableException("At most one asset catalog optimisation style can be " + "specified in the dependencies %s", params.getBuildTarget());
        }
    }
    ImmutableSortedSet<SourcePath> assetCatalogDirs = assetCatalogDirsBuilder.build();
    if (assetCatalogDirs.isEmpty()) {
        return Optional.empty();
    }
    Preconditions.checkNotNull(optimization, "optimization was null even though assetCatalogArgs was not empty");
    for (SourcePath assetCatalogDir : assetCatalogDirs) {
        Path baseName = sourcePathResolver.getRelativePath(assetCatalogDir).getFileName();
        if (!baseName.toString().endsWith(".xcassets")) {
            throw new HumanReadableException("Target %s had asset catalog dir %s - asset catalog dirs must end with .xcassets", params.getBuildTarget(), assetCatalogDir);
        }
    }
    BuildRuleParams assetCatalogParams = params.withAppendedFlavor(AppleAssetCatalog.FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()));
    return Optional.of(new AppleAssetCatalog(assetCatalogParams, applePlatform.getName(), actool, assetCatalogDirs, appIcon, launchImage, optimization, MERGED_ASSET_CATALOG_NAME));
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) HumanReadableException(com.facebook.buck.util.HumanReadableException) CxxConstructorArg(com.facebook.buck.cxx.CxxConstructorArg) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet)

Example 59 with SourcePath

use of com.facebook.buck.rules.SourcePath in project buck by facebook.

the class NdkLibraryDescription method findSources.

@VisibleForTesting
protected ImmutableSortedSet<SourcePath> findSources(final ProjectFilesystem filesystem, final Path buildRulePath) {
    final ImmutableSortedSet.Builder<SourcePath> srcs = ImmutableSortedSet.naturalOrder();
    try {
        final Path rootDirectory = filesystem.resolve(buildRulePath);
        Files.walkFileTree(rootDirectory, EnumSet.of(FileVisitOption.FOLLOW_LINKS), /* maxDepth */
        Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                if (EXTENSIONS_REGEX.matcher(file.toString()).matches()) {
                    srcs.add(new PathSourcePath(filesystem, buildRulePath.resolve(rootDirectory.relativize(file))));
                }
                return super.visitFile(file, attrs);
            }
        });
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return srcs.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 60 with SourcePath

use of com.facebook.buck.rules.SourcePath in project buck by facebook.

the class AppleDescriptions method collectFirstLevelAppleDependencyBundles.

private static ImmutableMap<SourcePath, String> collectFirstLevelAppleDependencyBundles(ImmutableSortedSet<BuildRule> deps, AppleBundleDestinations destinations) {
    ImmutableMap.Builder<SourcePath, String> extensionBundlePaths = ImmutableMap.builder();
    // do not get pulled in to the top-level Bundle.
    for (BuildRule rule : deps) {
        if (rule instanceof AppleBundle) {
            AppleBundle appleBundle = (AppleBundle) rule;
            SourcePath sourcePath = Preconditions.checkNotNull(appleBundle.getSourcePathToOutput(), "Path cannot be null for AppleBundle [%s].", appleBundle);
            if (AppleBundleExtension.APPEX.toFileExtension().equals(appleBundle.getExtension()) || AppleBundleExtension.APP.toFileExtension().equals(appleBundle.getExtension())) {
                Path destinationPath;
                String platformName = appleBundle.getPlatformName();
                if ((platformName.equals(ApplePlatform.WATCHOS.getName()) || platformName.equals(ApplePlatform.WATCHSIMULATOR.getName())) && appleBundle.getExtension().equals(AppleBundleExtension.APP.toFileExtension())) {
                    destinationPath = destinations.getWatchAppPath();
                } else if (appleBundle.isLegacyWatchApp()) {
                    destinationPath = destinations.getResourcesPath();
                } else {
                    destinationPath = destinations.getPlugInsPath();
                }
                extensionBundlePaths.put(sourcePath, destinationPath.toString());
            } else if (AppleBundleExtension.FRAMEWORK.toFileExtension().equals(appleBundle.getExtension())) {
                extensionBundlePaths.put(sourcePath, destinations.getFrameworksPath().toString());
            }
        }
    }
    return extensionBundlePaths.build();
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) BuildRule(com.facebook.buck.rules.BuildRule) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

SourcePath (com.facebook.buck.rules.SourcePath)285 Path (java.nio.file.Path)151 BuildTarget (com.facebook.buck.model.BuildTarget)111 Test (org.junit.Test)105 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)102 PathSourcePath (com.facebook.buck.rules.PathSourcePath)100 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)96 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)90 BuildRule (com.facebook.buck.rules.BuildRule)79 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)69 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)69 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)64 ImmutableList (com.google.common.collect.ImmutableList)64 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)53 ImmutableMap (com.google.common.collect.ImmutableMap)48 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)43 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)42 HumanReadableException (com.facebook.buck.util.HumanReadableException)39 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)37 ImmutableSet (com.google.common.collect.ImmutableSet)34