use of com.facebook.buck.rules.Cell in project buck by facebook.
the class ProjectBuildFileParserPoolTest method closeWhenRunningJobs.
@Test
public void closeWhenRunningJobs() throws Exception {
Cell cell = EasyMock.createMock(Cell.class);
ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1));
final CountDownLatch waitTillClosed = new CountDownLatch(1);
final CountDownLatch firstJobRunning = new CountDownLatch(1);
final AtomicInteger postCloseWork = new AtomicInteger(0);
ImmutableSet<ListenableFuture<?>> futures;
try (ProjectBuildFileParserPool parserPool = new ProjectBuildFileParserPool(/* maxParsers */
1, createMockParserFactory(() -> {
firstJobRunning.countDown();
waitTillClosed.await();
return ImmutableList.of();
}))) {
futures = scheduleWork(cell, parserPool, executorService, 5);
for (ListenableFuture<?> future : futures) {
Futures.addCallback(future, new FutureCallback<Object>() {
@Override
public void onSuccess(@Nullable Object result) {
postCloseWork.incrementAndGet();
}
@Override
public void onFailure(Throwable t) {
}
});
}
firstJobRunning.await(1, TimeUnit.SECONDS);
}
waitTillClosed.countDown();
List<Object> futureResults = Futures.successfulAsList(futures).get(1, TimeUnit.SECONDS);
// The threadpool is of size 1, so we had 1 job in the 'running' state. That one job completed
// normally, the rest should have been cancelled.
int expectedCompletedJobs = 1;
int completedJobs = FluentIterable.from(futureResults).filter(Objects::nonNull).size();
assertThat(completedJobs, Matchers.equalTo(expectedCompletedJobs));
executorService.shutdown();
assertThat(executorService.awaitTermination(1, TimeUnit.SECONDS), Matchers.is(true));
assertThat(postCloseWork.get(), Matchers.equalTo(expectedCompletedJobs));
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class BuildLogHelperIntegrationTest method findsLogFiles.
@Test
public void findsLogFiles() throws Exception {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "build_log_helper", temporaryFolder);
workspace.setUp();
Cell cell = workspace.asCell();
ProjectFilesystem filesystem = cell.getFilesystem();
BuildLogHelper buildLogHelper = new BuildLogHelper(filesystem, ObjectMappers.newDefaultInstance());
ImmutableList<BuildLogEntry> buildLogs = buildLogHelper.getBuildLogs();
ImmutableMap<BuildId, BuildLogEntry> idToLogMap = FluentIterable.from(buildLogs).uniqueIndex(input -> input.getBuildId().get());
Map<BuildId, String> buildIdToCommandMap = Maps.transformValues(idToLogMap, input -> input.getCommandArgs().get());
assertThat(buildIdToCommandMap, Matchers.equalTo(ImmutableMap.of(new BuildId("ac8bd626-6137-4747-84dd-5d4f215c876c"), "build, buck", new BuildId("d09893d5-b11e-4e3f-a5bf-70c60a06896e"), "autodeps")));
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class AuditInputCommand method printJsonInputs.
@VisibleForTesting
int printJsonInputs(final CommandRunnerParams params, TargetGraph graph) throws IOException {
final SortedMap<String, ImmutableSortedSet<Path>> targetToInputs = new TreeMap<>();
new AbstractBottomUpTraversal<TargetNode<?, ?>, RuntimeException>(graph) {
@Override
public void visit(TargetNode<?, ?> node) {
Optional<Cell> cellRoot = params.getCell().getCellIfKnown(node.getBuildTarget());
Cell cell = cellRoot.isPresent() ? cellRoot.get() : params.getCell();
LOG.debug("Looking at inputs for %s", node.getBuildTarget().getFullyQualifiedName());
SortedSet<Path> targetInputs = new TreeSet<>();
for (Path input : node.getInputs()) {
LOG.debug("Walking input %s", input);
try {
if (!cell.getFilesystem().exists(input)) {
throw new HumanReadableException("Target %s refers to non-existent input file: %s", node, params.getCell().getRoot().relativize(cell.getRoot().resolve(input)));
}
targetInputs.addAll(cell.getFilesystem().getFilesUnderPath(input));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
targetToInputs.put(node.getBuildTarget().getFullyQualifiedName(), ImmutableSortedSet.copyOf(targetInputs));
}
}.traverse();
params.getObjectMapper().writeValue(params.getConsole().getStdOut(), targetToInputs);
return 0;
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class DistBuildFileHashesIntegrationTest method crossCellDoesNotCauseAbsolutePathSrcs.
@Test
public void crossCellDoesNotCauseAbsolutePathSrcs() throws Exception {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "cross_cell", temporaryFolder);
workspace.setUp();
ProjectFilesystem rootFs = new ProjectFilesystem(temporaryFolder.getRoot().toAbsolutePath().resolve("root_cell"));
ProjectFilesystem secondaryFs = new ProjectFilesystem(temporaryFolder.getRoot().toAbsolutePath().resolve("secondary_cell"));
BuckConfig rootCellConfig = FakeBuckConfig.builder().setFilesystem(rootFs).setSections("[repositories]", "cross_cell_secondary = " + secondaryFs.getRootPath().toAbsolutePath()).build();
Cell rootCell = new TestCellBuilder().setBuckConfig(rootCellConfig).setFilesystem(rootFs).build();
TypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
ConstructorArgMarshaller constructorArgMarshaller = new ConstructorArgMarshaller(typeCoercerFactory);
Parser parser = new Parser(new BroadcastEventListener(), rootCellConfig.getView(ParserConfig.class), typeCoercerFactory, constructorArgMarshaller);
TargetGraph targetGraph = parser.buildTargetGraph(BuckEventBusFactory.newInstance(), rootCell, /* enableProfiling */
false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(rootFs.getRootPath(), "//:libA")));
DistBuildTargetGraphCodec targetGraphCodec = DistBuildStateTest.createDefaultCodec(rootCell, Optional.of(parser));
BuildJobState dump = DistBuildState.dump(new DistBuildCellIndexer(rootCell), createDistBuildFileHashes(targetGraph, rootCell), targetGraphCodec, targetGraph, ImmutableSet.of(BuildTargetFactory.newInstance(rootFs.getRootPath(), "//:libA")));
assertNotNull(dump);
assertEquals(2, dump.getFileHashesSize());
List<BuildJobStateFileHashes> sortedHashes = dump.getFileHashes().stream().sorted(Comparator.comparingInt(BuildJobStateFileHashes::getCellIndex)).collect(Collectors.toList());
BuildJobStateFileHashes rootCellHashes = sortedHashes.get(0);
assertEquals(1, rootCellHashes.getEntriesSize());
assertEquals("A.java", rootCellHashes.getEntries().get(0).getPath().getPath());
BuildJobStateFileHashes secondaryCellHashes = sortedHashes.get(1);
assertEquals(1, secondaryCellHashes.getEntriesSize());
assertEquals("B.java", secondaryCellHashes.getEntries().get(0).getPath().getPath());
}
use of com.facebook.buck.rules.Cell in project buck by facebook.
the class DistBuildFileHashesIntegrationTest method symlinkPathsRecordedInRootCell.
@Test
public void symlinkPathsRecordedInRootCell() throws Exception {
Assume.assumeTrue(Platform.detect() != Platform.WINDOWS);
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "symlink", temporaryFolder);
workspace.setUp();
ProjectFilesystem rootFs = new ProjectFilesystem(temporaryFolder.getRoot().toAbsolutePath().resolve("root_cell"));
Path absSymlinkFilePath = rootFs.resolve("../" + SYMLINK_FILE_NAME);
Path symLinkPath = rootFs.resolve(SYMLINK_FILE_NAME);
rootFs.createSymLink(symLinkPath, absSymlinkFilePath, false);
BuckConfig rootCellConfig = FakeBuckConfig.builder().setFilesystem(rootFs).build();
Cell rootCell = new TestCellBuilder().setBuckConfig(rootCellConfig).setFilesystem(rootFs).build();
TypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
ConstructorArgMarshaller constructorArgMarshaller = new ConstructorArgMarshaller(typeCoercerFactory);
Parser parser = new Parser(new BroadcastEventListener(), rootCellConfig.getView(ParserConfig.class), typeCoercerFactory, constructorArgMarshaller);
TargetGraph targetGraph = parser.buildTargetGraph(BuckEventBusFactory.newInstance(), rootCell, /* enableProfiling */
false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(rootFs.getRootPath(), "//:libA")));
DistBuildTargetGraphCodec targetGraphCodec = DistBuildStateTest.createDefaultCodec(rootCell, Optional.of(parser));
BuildJobState dump = DistBuildState.dump(new DistBuildCellIndexer(rootCell), createDistBuildFileHashes(targetGraph, rootCell), targetGraphCodec, targetGraph, ImmutableSet.of(BuildTargetFactory.newInstance(rootFs.getRootPath(), "//:libA")));
assertNotNull(dump);
assertEquals(1, dump.getFileHashesSize());
BuildJobStateFileHashes rootCellHashes = dump.getFileHashes().get(0);
assertEquals(2, rootCellHashes.getEntriesSize());
BuildJobStateFileHashEntry symLinkEntry = rootCellHashes.getEntries().stream().filter(x -> x.isSetRootSymLink()).findFirst().get();
String expectedPath = temporaryFolder.getRoot().resolve(SYMLINK_FILE_NAME).toAbsolutePath().toString();
assertEquals(MorePaths.pathWithUnixSeparators(expectedPath), symLinkEntry.getRootSymLinkTarget().getPath());
assertEquals(SYMLINK_FILE_NAME, symLinkEntry.getRootSymLink().getPath());
BuildJobStateFileHashEntry relPathEntry = rootCellHashes.getEntries().stream().filter(x -> !x.isPathIsAbsolute()).findFirst().get();
assertEquals("A.java", relPathEntry.getPath().getPath());
}
Aggregations