use of com.facebook.buck.rules.Cell in project buck by facebook.
the class WorkspaceAndProjectGenerator method generateProject.
private void generateProject(final Map<Path, ProjectGenerator> projectGenerators, ListeningExecutorService listeningExecutorService, WorkspaceGenerator workspaceGenerator, ImmutableSet<BuildTarget> targetsInRequiredProjects, ImmutableMultimap.Builder<BuildTarget, PBXTarget> buildTargetToPbxTargetMapBuilder, ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder, final Optional<BuildTarget> targetToBuildWithBuck) throws IOException, InterruptedException {
ImmutableMultimap.Builder<Cell, BuildTarget> projectCellToBuildTargetsBuilder = ImmutableMultimap.builder();
for (TargetNode<?, ?> targetNode : projectGraph.getNodes()) {
BuildTarget buildTarget = targetNode.getBuildTarget();
projectCellToBuildTargetsBuilder.put(rootCell.getCell(buildTarget), buildTarget);
}
ImmutableMultimap<Cell, BuildTarget> projectCellToBuildTargets = projectCellToBuildTargetsBuilder.build();
List<ListenableFuture<GenerationResult>> projectGeneratorFutures = new ArrayList<>();
for (final Cell projectCell : projectCellToBuildTargets.keySet()) {
ImmutableMultimap.Builder<Path, BuildTarget> projectDirectoryToBuildTargetsBuilder = ImmutableMultimap.builder();
final ImmutableSet<BuildTarget> cellRules = ImmutableSet.copyOf(projectCellToBuildTargets.get(projectCell));
for (BuildTarget buildTarget : cellRules) {
projectDirectoryToBuildTargetsBuilder.put(buildTarget.getBasePath(), buildTarget);
}
ImmutableMultimap<Path, BuildTarget> projectDirectoryToBuildTargets = projectDirectoryToBuildTargetsBuilder.build();
final Path relativeTargetCell = rootCell.getRoot().relativize(projectCell.getRoot());
for (final Path projectDirectory : projectDirectoryToBuildTargets.keySet()) {
final ImmutableSet<BuildTarget> rules = filterRulesForProjectDirectory(projectGraph, ImmutableSet.copyOf(projectDirectoryToBuildTargets.get(projectDirectory)));
if (Sets.intersection(targetsInRequiredProjects, rules).isEmpty()) {
continue;
}
final boolean isMainProject = workspaceArguments.srcTarget.isPresent() && rules.contains(workspaceArguments.srcTarget.get());
projectGeneratorFutures.add(listeningExecutorService.submit(() -> {
GenerationResult result = generateProjectForDirectory(projectGenerators, targetToBuildWithBuck, projectCell, projectDirectory, rules, isMainProject, targetsInRequiredProjects);
// convert the projectPath to relative to the target cell here
result = GenerationResult.of(relativeTargetCell.resolve(result.getProjectPath()), result.isProjectGenerated(), result.getRequiredBuildTargets(), result.getBuildTargetToGeneratedTargetMap());
return result;
}));
}
}
List<GenerationResult> generationResults;
try {
generationResults = Futures.allAsList(projectGeneratorFutures).get();
} catch (ExecutionException e) {
Throwables.throwIfInstanceOf(e.getCause(), IOException.class);
Throwables.throwIfUnchecked(e.getCause());
throw new IllegalStateException("Unexpected exception: ", e);
}
for (GenerationResult result : generationResults) {
if (!result.isProjectGenerated()) {
continue;
}
workspaceGenerator.addFilePath(result.getProjectPath());
processGenerationResult(buildTargetToPbxTargetMapBuilder, targetToProjectPathMapBuilder, result);
}
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class ResolveAliasHelper method validateBuildTargetForFullyQualifiedTarget.
/**
* Verify that the given target is a valid full-qualified (non-alias) target.
*/
@Nullable
static String validateBuildTargetForFullyQualifiedTarget(CommandRunnerParams params, ListeningExecutorService executor, boolean enableProfiling, String target, Parser parser) {
BuildTarget buildTarget = getBuildTargetForFullyQualifiedTarget(params.getBuckConfig(), target);
Cell owningCell = params.getCell().getCell(buildTarget);
Path buildFile;
try {
buildFile = owningCell.getAbsolutePathToBuildFile(buildTarget);
} catch (Cell.MissingBuildFileException e) {
throw new HumanReadableException(e);
}
// Get all valid targets in our target directory by reading the build file.
ImmutableSet<TargetNode<?, ?>> targetNodes;
try {
targetNodes = parser.getAllTargetNodes(params.getBuckEventBus(), owningCell, enableProfiling, executor, buildFile);
} catch (BuildFileParseException e) {
throw new HumanReadableException(e);
}
// Check that the given target is a valid target.
for (TargetNode<?, ?> candidate : targetNodes) {
if (candidate.getBuildTarget().equals(buildTarget)) {
return buildTarget.getFullyQualifiedName();
}
}
return null;
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class AppleBuildRulesTest method testIosResourceIsNotXcodeTargetDescription.
@Test
public void testIosResourceIsNotXcodeTargetDescription() throws Exception {
Cell rootCell = (new TestCellBuilder()).build();
BuildTarget resourceTarget = BuildTarget.builder(rootCell.getRoot(), "//foo", "res").build();
TargetNode<?, ?> resourceNode = AppleResourceBuilder.createBuilder(resourceTarget).setFiles(ImmutableSet.of()).setDirs(ImmutableSet.of()).build();
assertFalse(AppleBuildRules.isXcodeTargetDescription(resourceNode.getDescription()));
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class CleanCommandTest method createCommandRunnerParams.
private CommandRunnerParams createCommandRunnerParams() throws InterruptedException, IOException {
projectFilesystem = new FakeProjectFilesystem();
Cell cell = new TestCellBuilder().setFilesystem(projectFilesystem).build();
Supplier<AndroidPlatformTarget> androidPlatformTargetSupplier = AndroidPlatformTarget.EXPLODING_ANDROID_PLATFORM_TARGET_SUPPLIER;
return CommandRunnerParams.builder().setConsole(new TestConsole()).setStdIn(new ByteArrayInputStream("".getBytes("UTF-8"))).setCell(cell).setAndroidPlatformTargetSupplier(androidPlatformTargetSupplier).setArtifactCacheFactory(new SingletonArtifactCacheFactory(new NoopArtifactCache())).setBuckEventBus(BuckEventBusFactory.newInstance()).setParser(createMock(Parser.class)).setPlatform(Platform.detect()).setEnvironment(ImmutableMap.copyOf(System.getenv())).setJavaPackageFinder(new FakeJavaPackageFinder()).setObjectMapper(ObjectMappers.newDefaultInstance()).setClock(new DefaultClock()).setProcessManager(Optional.empty()).setWebServer(Optional.empty()).setBuckConfig(FakeBuckConfig.builder().build()).setFileHashCache(new StackedFileHashCache(ImmutableList.of())).setExecutors(ImmutableMap.of()).setBuildEnvironmentDescription(CommandRunnerParamsForTesting.BUILD_ENVIRONMENT_DESCRIPTION).setVersionedTargetGraphCache(new VersionedTargetGraphCache()).setActionGraphCache(new ActionGraphCache(new BroadcastEventListener())).setKnownBuildRuleTypesFactory(new KnownBuildRuleTypesFactory(new FakeProcessExecutor(), new FakeAndroidDirectoryResolver())).build();
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class AuditInputCommandTest method setUp.
@Before
public void setUp() throws IOException, InterruptedException {
console = new TestConsole();
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
projectFilesystem.touch(Paths.get("src/com/facebook/AndroidLibraryTwo.java"));
projectFilesystem.touch(Paths.get("src/com/facebook/TestAndroidLibrary.java"));
projectFilesystem.touch(Paths.get("src/com/facebook/TestJavaLibrary.java"));
Cell cell = new TestCellBuilder().setFilesystem(projectFilesystem).build();
ArtifactCache artifactCache = new NoopArtifactCache();
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
auditInputCommand = new AuditInputCommand();
params = CommandRunnerParamsForTesting.createCommandRunnerParamsForTesting(console, cell, new FakeAndroidDirectoryResolver(), artifactCache, eventBus, FakeBuckConfig.builder().build(), Platform.detect(), ImmutableMap.copyOf(System.getenv()), new FakeJavaPackageFinder(), objectMapper, Optional.empty());
}
Aggregations