use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project buck by facebook.
the class IjModuleGraph method createModules.
/**
* Create all the modules we are capable of representing in IntelliJ from the supplied graph.
*
* @param targetGraph graph whose nodes will be converted to {@link IjModule}s.
* @return map which for every BuildTarget points to the corresponding IjModule. Multiple
* BuildTarget can point to one IjModule (many:one mapping), the BuildTargets which
* can't be prepresented in IntelliJ are missing from this mapping.
*/
private static ImmutableMap<BuildTarget, IjModule> createModules(IjProjectConfig projectConfig, TargetGraph targetGraph, IjModuleFactory moduleFactory, final int minimumPathDepth) {
final BlockedPathNode blockedPathTree = createAggregationHaltPoints(projectConfig, targetGraph);
ImmutableListMultimap<Path, TargetNode<?, ?>> baseTargetPathMultimap = targetGraph.getNodes().stream().filter(input -> IjModuleFactory.SUPPORTED_MODULE_DESCRIPTION_CLASSES.contains(input.getDescription().getClass())).collect(MoreCollectors.toImmutableListMultimap(targetNode -> {
Path path;
Path basePath = targetNode.getBuildTarget().getBasePath();
if (targetNode.getConstructorArg() instanceof AndroidResourceDescription.Arg) {
path = basePath;
} else {
path = simplifyPath(basePath, minimumPathDepth, blockedPathTree);
}
return path;
}, targetNode -> targetNode));
ImmutableMap.Builder<BuildTarget, IjModule> moduleMapBuilder = new ImmutableMap.Builder<>();
for (Path baseTargetPath : baseTargetPathMultimap.keySet()) {
ImmutableSet<TargetNode<?, ?>> targets = ImmutableSet.copyOf(baseTargetPathMultimap.get(baseTargetPath));
IjModule module = moduleFactory.createModule(baseTargetPath, targets);
for (TargetNode<?, ?> target : targets) {
moduleMapBuilder.put(target.getBuildTarget(), module);
}
}
return moduleMapBuilder.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project buck by facebook.
the class IjProjectTemplateDataPreparer method createExcludes.
public ImmutableSet<IjFolder> createExcludes(final IjModule module) throws IOException {
final ImmutableSet.Builder<IjFolder> excludesBuilder = ImmutableSet.builder();
final Path moduleBasePath = module.getModuleBasePath();
projectFilesystem.walkRelativeFileTree(moduleBasePath, new FileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
// When we create excludes for that module.
if (filesystemTraversalBoundaryPaths.contains(dir) && !moduleBasePath.equals(dir)) {
return FileVisitResult.SKIP_SUBTREE;
}
if (isRootAndroidResourceDirectory(module, dir)) {
return FileVisitResult.SKIP_SUBTREE;
}
if (!referencedFolderPaths.contains(dir)) {
excludesBuilder.add(new ExcludeFolder(dir));
return FileVisitResult.SKIP_SUBTREE;
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
return FileVisitResult.CONTINUE;
}
});
return excludesBuilder.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project buck by facebook.
the class PythonTestDescription method createBuildRule.
@Override
public <A extends Arg> PythonTest createBuildRule(TargetGraph targetGraph, final BuildRuleParams params, final BuildRuleResolver resolver, final A args) throws HumanReadableException, NoSuchBuildTargetException {
PythonPlatform pythonPlatform = pythonPlatforms.getValue(params.getBuildTarget()).orElse(pythonPlatforms.getValue(args.platform.<Flavor>map(InternalFlavor::of).orElse(pythonPlatforms.getFlavors().iterator().next())));
CxxPlatform cxxPlatform = cxxPlatforms.getValue(params.getBuildTarget()).orElse(defaultCxxPlatform);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
Path baseModule = PythonUtil.getBasePath(params.getBuildTarget(), args.baseModule);
Optional<ImmutableMap<BuildTarget, Version>> selectedVersions = targetGraph.get(params.getBuildTarget()).getSelectedVersions();
ImmutableMap<Path, SourcePath> srcs = PythonUtil.getModules(params.getBuildTarget(), resolver, ruleFinder, pathResolver, pythonPlatform, cxxPlatform, "srcs", baseModule, args.srcs, args.platformSrcs, args.versionedSrcs, selectedVersions);
ImmutableMap<Path, SourcePath> resources = PythonUtil.getModules(params.getBuildTarget(), resolver, ruleFinder, pathResolver, pythonPlatform, cxxPlatform, "resources", baseModule, args.resources, args.platformResources, args.versionedResources, selectedVersions);
// Convert the passed in module paths into test module names.
ImmutableSet.Builder<String> testModulesBuilder = ImmutableSet.builder();
for (Path name : srcs.keySet()) {
testModulesBuilder.add(PythonUtil.toModuleName(params.getBuildTarget(), name.toString()));
}
ImmutableSet<String> testModules = testModulesBuilder.build();
// Construct a build rule to generate the test modules list source file and
// add it to the build.
BuildRule testModulesBuildRule = createTestModulesSourceBuildRule(params, getTestModulesListPath(params.getBuildTarget(), params.getProjectFilesystem()), testModules);
resolver.addToIndex(testModulesBuildRule);
String mainModule;
if (args.mainModule.isPresent()) {
mainModule = args.mainModule.get();
} else {
mainModule = PythonUtil.toModuleName(params.getBuildTarget(), getTestMainName().toString());
}
// Build up the list of everything going into the python test.
PythonPackageComponents testComponents = PythonPackageComponents.of(ImmutableMap.<Path, SourcePath>builder().put(getTestModulesListName(), testModulesBuildRule.getSourcePathToOutput()).put(getTestMainName(), pythonBuckConfig.getPathToTestMain(params.getProjectFilesystem())).putAll(srcs).build(), resources, ImmutableMap.of(), ImmutableSet.of(), args.zipSafe);
PythonPackageComponents allComponents = PythonUtil.getAllComponents(params, resolver, ruleFinder, testComponents, pythonPlatform, cxxBuckConfig, cxxPlatform, args.linkerFlags.stream().map(MacroArg.toMacroArgFunction(PythonUtil.MACRO_HANDLER, params.getBuildTarget(), params.getCellRoots(), resolver)::apply).collect(MoreCollectors.toImmutableList()), pythonBuckConfig.getNativeLinkStrategy(), args.preloadDeps);
// Build the PEX using a python binary rule with the minimum dependencies.
PythonBinary binary = binaryDescription.createPackageRule(params.withBuildTarget(getBinaryBuildTarget(params.getBuildTarget())), resolver, ruleFinder, pythonPlatform, cxxPlatform, mainModule, args.extension, allComponents, args.buildArgs, args.packageStyle.orElse(pythonBuckConfig.getPackageStyle()), PythonUtil.getPreloadNames(resolver, cxxPlatform, args.preloadDeps));
resolver.addToIndex(binary);
ImmutableList.Builder<Pair<Float, ImmutableSet<Path>>> neededCoverageBuilder = ImmutableList.builder();
for (NeededCoverageSpec coverageSpec : args.neededCoverage) {
BuildRule buildRule = resolver.getRule(coverageSpec.getBuildTarget());
if (params.getDeps().contains(buildRule) && buildRule instanceof PythonLibrary) {
PythonLibrary pythonLibrary = (PythonLibrary) buildRule;
ImmutableSortedSet<Path> paths;
if (coverageSpec.getPathName().isPresent()) {
Path path = coverageSpec.getBuildTarget().getBasePath().resolve(coverageSpec.getPathName().get());
if (!pythonLibrary.getPythonPackageComponents(pythonPlatform, cxxPlatform).getModules().keySet().contains(path)) {
throw new HumanReadableException("%s: path %s specified in needed_coverage not found in target %s", params.getBuildTarget(), path, buildRule.getBuildTarget());
}
paths = ImmutableSortedSet.of(path);
} else {
paths = ImmutableSortedSet.copyOf(pythonLibrary.getPythonPackageComponents(pythonPlatform, cxxPlatform).getModules().keySet());
}
neededCoverageBuilder.add(new Pair<Float, ImmutableSet<Path>>(coverageSpec.getNeededCoverageRatio(), paths));
} else {
throw new HumanReadableException("%s: needed_coverage requires a python library dependency. Found %s instead", params.getBuildTarget(), buildRule);
}
}
Supplier<ImmutableMap<String, String>> testEnv = () -> ImmutableMap.copyOf(Maps.transformValues(args.env, MACRO_HANDLER.getExpander(params.getBuildTarget(), params.getCellRoots(), resolver)));
// Generate and return the python test rule, which depends on the python binary rule above.
return PythonTest.from(params, ruleFinder, testEnv, binary, args.labels, neededCoverageBuilder.build(), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.contacts);
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project buck by facebook.
the class QueryTargetAccessor method filterAttributeContents.
/**
* Filters the objects in the given attribute that satisfy the given predicate.
*/
public static <T> ImmutableSet<Object> filterAttributeContents(TargetNode<T, ?> node, String attribute, final Predicate<Object> predicate) {
try {
final ImmutableSet.Builder<Object> builder = ImmutableSet.builder();
Class<?> constructorArgClass = node.getConstructorArg().getClass();
Field field = constructorArgClass.getField(attribute);
ParamInfo info = new ParamInfo(typeCoercerFactory, constructorArgClass, field);
info.traverse(value -> {
if (predicate.apply(value)) {
builder.add(value);
}
}, node.getConstructorArg());
return builder.build();
} catch (NoSuchFieldException e) {
// Ignore if the field does not exist in this rule.
return ImmutableSet.of();
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project buck by facebook.
the class CellProvider method createForLocalBuild.
/**
* Create a cell provider at a given root.
*/
public static CellProvider createForLocalBuild(ProjectFilesystem rootFilesystem, Watchman watchman, BuckConfig rootConfig, CellConfig rootCellConfigOverrides, KnownBuildRuleTypesFactory knownBuildRuleTypesFactory) throws IOException {
DefaultCellPathResolver rootCellCellPathResolver = new DefaultCellPathResolver(rootFilesystem.getRootPath(), rootConfig.getConfig());
ImmutableMap<RelativeCellName, Path> transitiveCellPathMapping = rootCellCellPathResolver.getTransitivePathMapping();
ImmutableMap<Path, RawConfig> pathToConfigOverrides;
try {
pathToConfigOverrides = rootCellConfigOverrides.getOverridesByPath(transitiveCellPathMapping);
} catch (CellConfig.MalformedOverridesException e) {
throw new HumanReadableException(e.getMessage());
}
ImmutableSet<Path> allRoots = ImmutableSet.copyOf(transitiveCellPathMapping.values());
return new CellProvider(cellProvider -> new CacheLoader<Path, Cell>() {
@Override
public Cell load(Path cellPath) throws IOException, InterruptedException {
Path normalizedCellPath = cellPath.toRealPath().normalize();
Preconditions.checkState(allRoots.contains(normalizedCellPath), "Cell %s outside of transitive closure of root cell (%s).", normalizedCellPath, allRoots);
RawConfig configOverrides = Optional.ofNullable(pathToConfigOverrides.get(normalizedCellPath)).orElse(RawConfig.of(ImmutableMap.of()));
Config config = Configs.createDefaultConfig(normalizedCellPath, configOverrides);
DefaultCellPathResolver cellPathResolver = new DefaultCellPathResolver(normalizedCellPath, config);
cellPathResolver.getCellPaths().forEach((name, path) -> {
Path pathInRootResolver = rootCellCellPathResolver.getCellPaths().get(name);
if (pathInRootResolver == null) {
throw new HumanReadableException("In the config of %s: %s.%s must exist in the root cell's cell mappings.", cellPath.toString(), DefaultCellPathResolver.REPOSITORIES_SECTION, name);
} else if (!pathInRootResolver.equals(path)) {
throw new HumanReadableException("In the config of %s: %s.%s must point to the same directory as the root " + "cell's cell mapping: (root) %s != (current) %s", cellPath.toString(), DefaultCellPathResolver.REPOSITORIES_SECTION, name, pathInRootResolver, path);
}
});
ProjectFilesystem cellFilesystem = new ProjectFilesystem(normalizedCellPath, config);
BuckConfig buckConfig = new BuckConfig(config, cellFilesystem, rootConfig.getArchitecture(), rootConfig.getPlatform(), rootConfig.getEnvironment(), cellPathResolver);
return new Cell(cellPathResolver.getKnownRoots(), cellFilesystem, watchman, buckConfig, knownBuildRuleTypesFactory, cellProvider);
}
}, cellProvider -> {
try {
return new Cell(rootCellCellPathResolver.getKnownRoots(), rootFilesystem, watchman, rootConfig, knownBuildRuleTypesFactory, cellProvider);
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while loading root cell", e);
} catch (IOException e) {
throw new HumanReadableException("Failed to load root cell", e);
}
});
}
Aggregations