use of com.facebook.buck.rules.CellPathResolver in project buck by facebook.
the class BuildTargetPatternParserTest method visibilityCanContainCrossCellReference.
@Test
public void visibilityCanContainCrossCellReference() {
BuildTargetPatternParser<BuildTargetPattern> buildTargetPatternParser = BuildTargetPatternParser.forVisibilityArgument();
final ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
CellPathResolver cellNames = new FakeCellPathResolver(ImmutableMap.of("other", filesystem.getRootPath()));
assertEquals(new SingletonBuildTargetPattern(filesystem.getRootPath(), "//:something"), buildTargetPatternParser.parse(cellNames, "other//:something"));
assertEquals(new SubdirectoryBuildTargetPattern(filesystem.getRootPath(), filesystem.getPath("sub")), buildTargetPatternParser.parse(cellNames, "other//sub/..."));
}
use of com.facebook.buck.rules.CellPathResolver in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method locationMacro.
@Test
public void locationMacro() throws NoSuchBuildTargetException {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
CellPathResolver cellRoots = TestCellBuilder.createCellRoots(filesystem);
Optional<String> libName = Optional.of("test");
Optional<String> libDir = Optional.of("$(location //other:gen_lib)/");
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
BuildTarget genTarget = BuildTargetFactory.newInstance("//other:gen_lib");
GenruleBuilder genruleBuilder = GenruleBuilder.newGenruleBuilder(genTarget).setOut("lib_dir");
BuildRule genRule = genruleBuilder.build(resolver);
CxxPlatform platform = CxxPlatformUtils.DEFAULT_PLATFORM.withFlavor(InternalFlavor.of("PLATFORM1"));
Path path = pathResolver.getAbsolutePath(Preconditions.checkNotNull(genRule.getSourcePathToOutput()));
final SourcePath staticLibraryPath = PrebuiltCxxLibraryDescription.getStaticLibraryPath(TARGET, cellRoots, filesystem, resolver, platform, Optional.empty(), libDir, libName);
assertEquals(TARGET.getBasePath().resolve(String.format("%s/libtest.a", path)), pathResolver.getAbsolutePath(staticLibraryPath));
}
use of com.facebook.buck.rules.CellPathResolver in project buck by facebook.
the class JavacExecutionContextSerializer method deserialize.
@SuppressWarnings("unchecked")
public static JavacExecutionContext deserialize(Map<String, Object> data, JavacEventSink eventSink, PrintStream stdErr, ClassLoaderCache classLoaderCache, ObjectMapper objectMapper, Console console) {
Verbosity verbosity = Verbosity.valueOf((String) Preconditions.checkNotNull(data.get(VERBOSITY)));
CellPathResolver cellPathResolver = CellPathResolverSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(CELL_PATH_RESOLVER)));
JavaPackageFinder javaPackageFinder = JavaPackageFinderSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(JAVA_PACKAGE_FINDER)));
ProjectFilesystem projectFilesystem = new ProjectFilesystem(Paths.get((String) Preconditions.checkNotNull(data.get(PROJECT_FILE_SYSTEM_ROOT))));
ClassUsageFileWriter classUsageFileWriter = ClassUsageFileWriterSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(CLASS_USAGE_FILE_WRITER)));
ProcessExecutor processExecutor = ProcessExecutorSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(PROCESS_EXECUTOR)), console);
ImmutableList<Path> absolutePathsForInputs = ImmutableList.copyOf(((List<String>) Preconditions.checkNotNull(data.get(ABSOLUTE_PATHS_FOR_INPUTS))).stream().map(s -> Paths.get(s)).iterator());
Optional<DirectToJarOutputSettings> directToJarOutputSettings = Optional.empty();
if (data.containsKey(DIRECT_TO_JAR_SETTINGS)) {
directToJarOutputSettings = Optional.of(DirectToJarOutputSettingsSerializer.deserialize((Map<String, Object>) Preconditions.checkNotNull(data.get(DIRECT_TO_JAR_SETTINGS))));
}
return JavacExecutionContext.of(eventSink, stdErr, classLoaderCache, objectMapper, verbosity, cellPathResolver, javaPackageFinder, projectFilesystem, classUsageFileWriter, (Map<String, String>) Preconditions.checkNotNull(data.get(ENVIRONMENT), "Missing environment when deserializing JavacExectionContext"), processExecutor, absolutePathsForInputs, directToJarOutputSettings);
}
use of com.facebook.buck.rules.CellPathResolver in project buck by facebook.
the class AppleBundleDescription method findDepsForTargetFromConstructorArgs.
/**
* Propagate the bundle's platform, debug symbol and strip flavors to its dependents
* which are other bundles (e.g. extensions)
*/
@Override
public ImmutableSet<BuildTarget> findDepsForTargetFromConstructorArgs(BuildTarget buildTarget, CellPathResolver cellRoots, AppleBundleDescription.Arg constructorArg) {
if (!cxxPlatformFlavorDomain.containsAnyOf(buildTarget.getFlavors())) {
buildTarget = BuildTarget.builder(buildTarget).addAllFlavors(ImmutableSet.of(defaultCxxPlatform.getFlavor())).build();
}
Optional<MultiarchFileInfo> fatBinaryInfo = MultiarchFileInfos.create(appleCxxPlatformsFlavorDomain, buildTarget);
CxxPlatform cxxPlatform;
if (fatBinaryInfo.isPresent()) {
AppleCxxPlatform appleCxxPlatform = fatBinaryInfo.get().getRepresentativePlatform();
cxxPlatform = appleCxxPlatform.getCxxPlatform();
} else {
cxxPlatform = ApplePlatforms.getCxxPlatformForBuildTarget(cxxPlatformFlavorDomain, defaultCxxPlatform, buildTarget);
}
String platformName = cxxPlatform.getFlavor().getName();
final Flavor actualWatchFlavor;
if (ApplePlatform.isSimulator(platformName)) {
actualWatchFlavor = WATCH_SIMULATOR_FLAVOR;
} else if (platformName.startsWith(ApplePlatform.IPHONEOS.getName()) || platformName.startsWith(ApplePlatform.WATCHOS.getName())) {
actualWatchFlavor = WATCH_OS_FLAVOR;
} else {
actualWatchFlavor = InternalFlavor.of(platformName);
}
FluentIterable<BuildTarget> depsExcludingBinary = FluentIterable.from(constructorArg.deps).filter(Predicates.not(constructorArg.binary::equals));
// Propagate platform flavors. Need special handling for watch to map the pseudo-flavor
// watch to the actual watch platform (simulator or device) so can't use
// BuildTargets.propagateFlavorsInDomainIfNotPresent()
{
FluentIterable<BuildTarget> targetsWithPlatformFlavors = depsExcludingBinary.filter(BuildTargets.containsFlavors(cxxPlatformFlavorDomain));
FluentIterable<BuildTarget> targetsWithoutPlatformFlavors = depsExcludingBinary.filter(Predicates.not(BuildTargets.containsFlavors(cxxPlatformFlavorDomain)));
FluentIterable<BuildTarget> watchTargets = targetsWithoutPlatformFlavors.filter(BuildTargets.containsFlavor(WATCH)).transform(input -> BuildTarget.builder(input.withoutFlavors(WATCH)).addFlavors(actualWatchFlavor).build());
targetsWithoutPlatformFlavors = targetsWithoutPlatformFlavors.filter(Predicates.not(BuildTargets.containsFlavor(WATCH)));
// Gather all the deps now that we've added platform flavors to everything.
depsExcludingBinary = targetsWithPlatformFlavors.append(watchTargets).append(BuildTargets.propagateFlavorDomains(buildTarget, ImmutableSet.of(cxxPlatformFlavorDomain), targetsWithoutPlatformFlavors));
}
// Propagate some flavors
depsExcludingBinary = BuildTargets.propagateFlavorsInDomainIfNotPresent(StripStyle.FLAVOR_DOMAIN, buildTarget, depsExcludingBinary);
depsExcludingBinary = BuildTargets.propagateFlavorsInDomainIfNotPresent(AppleDebugFormat.FLAVOR_DOMAIN, buildTarget, depsExcludingBinary);
depsExcludingBinary = BuildTargets.propagateFlavorsInDomainIfNotPresent(LinkerMapMode.FLAVOR_DOMAIN, buildTarget, depsExcludingBinary);
if (fatBinaryInfo.isPresent()) {
depsExcludingBinary = depsExcludingBinary.append(fatBinaryInfo.get().getRepresentativePlatform().getCodesignProvider().getParseTimeDeps());
} else {
depsExcludingBinary = depsExcludingBinary.append(appleCxxPlatformsFlavorDomain.getValue(buildTarget).map(platform -> platform.getCodesignProvider().getParseTimeDeps()).orElse(ImmutableSet.of()));
}
return ImmutableSet.copyOf(depsExcludingBinary);
}
use of com.facebook.buck.rules.CellPathResolver in project buck by facebook.
the class BuildConfigFieldsTypeCoercer method coerce.
@Override
public BuildConfigFields coerce(CellPathResolver cellRoots, ProjectFilesystem filesystem, Path pathRelativeToProjectRoot, Object object) throws CoerceFailedException {
if (!(object instanceof List)) {
throw CoerceFailedException.simple(object, getOutputClass());
}
List<?> list = (List<?>) object;
List<String> values = list.stream().map(input -> {
if (input instanceof String) {
return (String) input;
} else {
throw new HumanReadableException("Expected string for build config values but was: %s", input);
}
}).collect(MoreCollectors.toImmutableList());
return BuildConfigFields.fromFieldDeclarations(values);
}
Aggregations