use of com.facebook.buck.model.BuildId in project buck by facebook.
the class ProjectWorkspace method runBuckCommandWithEnvironmentOverridesAndContext.
public ProcessResult runBuckCommandWithEnvironmentOverridesAndContext(Path repoRoot, Optional<NGContext> context, ImmutableMap<String, String> environmentOverrides, CapturingPrintStream stderr, String... args) throws IOException {
assertTrue("setUp() must be run before this method is invoked", isSetUp);
CapturingPrintStream stdout = new CapturingPrintStream();
InputStream stdin = new ByteArrayInputStream("".getBytes());
// Construct a limited view of the parent environment for the child.
// TODO(#5754812): we should eventually get tests working without requiring these be set.
ImmutableList<String> inheritedEnvVars = ImmutableList.of("ANDROID_HOME", "ANDROID_NDK", "ANDROID_NDK_REPOSITORY", "ANDROID_SDK", // scripts provided by the groovy distribution in order to remove these two.
"GROOVY_HOME", "JAVA_HOME", "NDK_HOME", "PATH", "PATHEXT", // Needed by ndk-build on Windows
"OS", "ProgramW6432", "ProgramFiles(x86)", // The haskell integration tests call into GHC, which needs HOME to be set.
"HOME", // TODO(#6586154): set TMP variable for ShellSteps
"TMP");
Map<String, String> envBuilder = new HashMap<>();
for (String variable : inheritedEnvVars) {
String value = System.getenv(variable);
if (value != null) {
envBuilder.put(variable, value);
}
}
envBuilder.putAll(environmentOverrides);
ImmutableMap<String, String> sanizitedEnv = ImmutableMap.copyOf(envBuilder);
Main main = new Main(stdout, stderr, stdin);
int exitCode;
try {
exitCode = main.runMainWithExitCode(new BuildId(), repoRoot, context, sanizitedEnv, CommandMode.TEST, WatchmanWatcher.FreshInstanceAction.NONE, System.nanoTime(), args);
} catch (InterruptedException e) {
e.printStackTrace(stderr);
exitCode = Main.FAIL_EXIT_CODE;
Thread.currentThread().interrupt();
}
return new ProcessResult(exitCode, stdout.getContentsAsString(Charsets.UTF_8), stderr.getContentsAsString(Charsets.UTF_8));
}
use of com.facebook.buck.model.BuildId in project buck by facebook.
the class WatchmanWatcherIntegrationTest method createWatchmanWatcher.
// Create a watcher for the given ignore paths, clearing the initial overflow event before
// returning it.
private WatchmanWatcher createWatchmanWatcher(PathOrGlobMatcher... ignorePaths) throws IOException, InterruptedException {
WatchmanWatcher watcher = new WatchmanWatcher(ImmutableMap.of(tmp.getRoot(), ProjectWatch.of(tmp.getRoot().toString(), Optional.empty())), eventBus, ImmutableSet.copyOf(ignorePaths), watchman, ImmutableMap.of(tmp.getRoot(), new WatchmanCursor(new StringBuilder("n:buckd").append(UUID.randomUUID()).toString())));
// Clear out the initial overflow event.
watcher.postEvents(new BuckEventBus(new FakeClock(0), new BuildId()), WatchmanWatcher.FreshInstanceAction.NONE);
watchmanEventCollector.clear();
return watcher;
}
use of com.facebook.buck.model.BuildId in project buck by facebook.
the class Build method executeBuild.
/**
* If {@code isKeepGoing} is false, then this returns a future that succeeds only if all of
* {@code rulesToBuild} build successfully. Otherwise, this returns a future that should always
* succeed, even if individual rules fail to build. In that case, a failed build rule is indicated
* by a {@code null} value in the corresponding position in the iteration order of
* {@code rulesToBuild}.
* @param targetish The targets to build. All targets in this iterable must be unique.
*/
@SuppressWarnings("PMD.EmptyCatchBlock")
public BuildExecutionResult executeBuild(Iterable<? extends BuildTarget> targetish, boolean isKeepGoing) throws IOException, ExecutionException, InterruptedException {
BuildId buildId = executionContext.getBuildId();
BuildEngineBuildContext buildContext = BuildEngineBuildContext.builder().setBuildContext(BuildContext.builder().setActionGraph(actionGraph).setSourcePathResolver(new SourcePathResolver(new SourcePathRuleFinder(ruleResolver))).setJavaPackageFinder(javaPackageFinder).setEventBus(executionContext.getBuckEventBus()).setAndroidPlatformTargetSupplier(executionContext.getAndroidPlatformTargetSupplier()).build()).setClock(clock).setArtifactCache(artifactCache).setBuildId(buildId).setObjectMapper(objectMapper).putAllEnvironment(executionContext.getEnvironment()).setKeepGoing(isKeepGoing).build();
// It is important to use this logic to determine the set of rules to build rather than
// build.getActionGraph().getNodesWithNoIncomingEdges() because, due to graph enhancement,
// there could be disconnected subgraphs in the DependencyGraph that we do not want to build.
ImmutableSet<BuildTarget> targetsToBuild = StreamSupport.stream(targetish.spliterator(), false).collect(MoreCollectors.toImmutableSet());
// It is important to use this logic to determine the set of rules to build rather than
// build.getActionGraph().getNodesWithNoIncomingEdges() because, due to graph enhancement,
// there could be disconnected subgraphs in the DependencyGraph that we do not want to build.
ImmutableList<BuildRule> rulesToBuild = ImmutableList.copyOf(targetsToBuild.stream().map(buildTarget -> {
try {
return getRuleResolver().requireRule(buildTarget);
} catch (NoSuchBuildTargetException e) {
throw new HumanReadableException("No build rule found for target %s", buildTarget);
}
}).collect(MoreCollectors.toImmutableSet()));
// Calculate and post the number of rules that need to built.
int numRules = buildEngine.getNumRulesToBuild(rulesToBuild);
getExecutionContext().getBuckEventBus().post(BuildEvent.ruleCountCalculated(targetsToBuild, numRules));
// Setup symlinks required when configuring the output path.
createConfiguredBuckOutSymlinks();
List<ListenableFuture<BuildResult>> futures = rulesToBuild.stream().map(rule -> buildEngine.build(buildContext, executionContext, rule)).collect(MoreCollectors.toImmutableList());
// Get the Future representing the build and then block until everything is built.
ListenableFuture<List<BuildResult>> buildFuture = Futures.allAsList(futures);
List<BuildResult> results;
try {
results = buildFuture.get();
if (!isKeepGoing) {
for (BuildResult result : results) {
Throwable thrown = result.getFailure();
if (thrown != null) {
throw new ExecutionException(thrown);
}
}
}
} catch (ExecutionException | InterruptedException | RuntimeException e) {
Throwable t = Throwables.getRootCause(e);
if (e instanceof InterruptedException || t instanceof InterruptedException || t instanceof ClosedByInterruptException) {
try {
buildFuture.cancel(true);
} catch (CancellationException ignored) {
// Rethrow original InterruptedException instead.
}
Thread.currentThread().interrupt();
}
throw e;
}
// Insertion order matters
LinkedHashMap<BuildRule, Optional<BuildResult>> resultBuilder = new LinkedHashMap<>();
Preconditions.checkState(rulesToBuild.size() == results.size());
for (int i = 0, len = rulesToBuild.size(); i < len; i++) {
BuildRule rule = rulesToBuild.get(i);
resultBuilder.put(rule, Optional.ofNullable(results.get(i)));
}
return BuildExecutionResult.builder().setFailures(FluentIterable.from(results).filter(input -> input.getSuccess() == null)).setResults(resultBuilder).build();
}
use of com.facebook.buck.model.BuildId in project buck by facebook.
the class CounterRegistryImplTest method closingRegistryBeforeTimerFiresFlushesCounters.
@Test
public void closingRegistryBeforeTimerFiresFlushesCounters() throws IOException {
BuckEventBus fakeEventBus = new BuckEventBus(new FakeClock(0), false, new BuildId("12345"), 1000);
SnapshotEventListener listener = new SnapshotEventListener();
fakeEventBus.register(listener);
FakeExecutor fakeExecutor = new FakeExecutor();
try (CounterRegistryImpl registry = new CounterRegistryImpl(fakeExecutor, fakeEventBus)) {
IntegerCounter counter = registry.newIntegerCounter(CATEGORY, NAME, TAGS);
counter.inc(42);
assertThat("No events should be flushed before timer fires", listener.snapshotEvents, empty());
}
// We explicitly do not call fakeExecutor.drain() here, because we want to simulate what
// happens when the registry is closed before the executor fires.
assertThat("One snapshot event should be flushed when registry closed before timer fires", listener.snapshotEvents, hasSize(1));
assertThat("Expected snapshot should be flushed when registry closed before timer fires", listener.snapshotEvents.get(0).getSnapshots(), hasItem(CounterSnapshot.builder().setCategory(CATEGORY).setTags(TAGS).putValues(NAME, 42).build()));
}
use of com.facebook.buck.model.BuildId in project buck by facebook.
the class RuleKeyLoggerListenerTest method setUp.
@Before
public void setUp() throws IOException {
tempDirectory = new TemporaryFolder();
tempDirectory.create();
projectFilesystem = new ProjectFilesystem(tempDirectory.getRoot().toPath());
outputExecutor = MostExecutors.newSingleThreadExecutor(new CommandThreadFactory(getClass().getName()));
info = InvocationInfo.of(new BuildId(), false, false, "topspin", tempDirectory.getRoot().toPath());
durationTracker = new BuildRuleDurationTracker();
}
Aggregations