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;
}
}
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));
}
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();
}
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();
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class AppleDescriptions method convertToFlatCxxHeaders.
/**
* Convert {@link SourcePath} to a mapping of {@code include path -> file path}.
* <p/>
* {@code include path} is the path that can be referenced in {@code #include} directives.
* {@code file path} is the actual path to the file on disk.
*
* @throws HumanReadableException when two {@code SourcePath} yields the same IncludePath.
*/
@VisibleForTesting
static ImmutableSortedMap<String, SourcePath> convertToFlatCxxHeaders(Path headerPathPrefix, Function<SourcePath, Path> sourcePathResolver, Set<SourcePath> headerPaths) {
Set<String> includeToFile = new HashSet<String>(headerPaths.size());
ImmutableSortedMap.Builder<String, SourcePath> builder = ImmutableSortedMap.naturalOrder();
for (SourcePath headerPath : headerPaths) {
Path fileName = sourcePathResolver.apply(headerPath).getFileName();
String key = headerPathPrefix.resolve(fileName).toString();
if (includeToFile.contains(key)) {
ImmutableSortedMap<String, SourcePath> result = builder.build();
throw new HumanReadableException("The same include path maps to multiple files:\n" + " Include path: %s\n" + " Conflicting files:\n" + " %s\n" + " %s", key, headerPath, result.get(key));
}
includeToFile.add(key);
builder.put(key, headerPath);
}
return builder.build();
}
Aggregations