use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class HeaderVerificationTest method getRuleKey.
private RuleKey getRuleKey(HeaderVerification headerVerification) {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
FileHashCache fileHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(new FakeProjectFilesystem())));
DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(0, fileHashCache, resolver, ruleFinder);
RuleKeyBuilder<RuleKey> builder = new UncachedRuleKeyBuilder(ruleFinder, resolver, fileHashCache, factory);
builder.setReflectively("headerVerification", headerVerification);
return builder.build();
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class PrebuiltCxxLibraryTest method testGetNativeLinkWithDep.
@Test
public void testGetNativeLinkWithDep() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
CxxPlatform platform = CxxLibraryBuilder.createDefaultPlatform();
GenruleBuilder genSrcBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:gen_libx")).setOut("gen_libx").setCmd("something");
BuildTarget target = BuildTargetFactory.newInstance("//:x");
PrebuiltCxxLibraryBuilder builder = new PrebuiltCxxLibraryBuilder(target).setLibName("x").setLibDir("$(location //:gen_libx)");
TargetGraph targetGraph = TargetGraphFactory.newInstance(genSrcBuilder.build(), builder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildRule genSrc = genSrcBuilder.build(resolver, filesystem, targetGraph);
filesystem.writeContentsToPath("class Test {}", pathResolver.getAbsolutePath(genSrc.getSourcePathToOutput()).resolve("libx.a"));
PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) builder.build(resolver, filesystem, targetGraph);
lib.getNativeLinkableInput(platform, Linker.LinkableDepType.STATIC);
FileHashCache originalHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(0, originalHashCache, pathResolver, ruleFinder);
RuleKey ruleKey = factory.build(lib);
assertNotNull(ruleKey);
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class ChromeTraceBuildListenerTest method testBuildJson.
@Test
public void testBuildJson() throws IOException {
ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmpDir.getRoot().toPath());
ObjectMapper mapper = ObjectMappers.newDefaultInstance();
BuildId buildId = new BuildId("ChromeTraceBuildListenerTestBuildId");
ChromeTraceBuildListener listener = new ChromeTraceBuildListener(projectFilesystem, invocationInfo, new FakeClock(TIMESTAMP_NANOS), mapper, Locale.US, TimeZone.getTimeZone("America/Los_Angeles"), /* tracesToKeep */
42, false);
BuildTarget target = BuildTargetFactory.newInstance("//fake:rule");
FakeBuildRule rule = new FakeBuildRule(target, new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSortedSet.of());
RuleKey ruleKey = new RuleKey("abc123");
String stepShortName = "fakeStep";
String stepDescription = "I'm a Fake Step!";
UUID stepUuid = UUID.randomUUID();
ImmutableSet<BuildTarget> buildTargets = ImmutableSet.of(target);
Iterable<String> buildArgs = Iterables.transform(buildTargets, Object::toString);
Clock fakeClock = new IncrementingFakeClock(TimeUnit.MILLISECONDS.toNanos(1));
BuckEventBus eventBus = BuckEventBusFactory.newInstance(fakeClock, buildId);
eventBus.register(listener);
CommandEvent.Started commandEventStarted = CommandEvent.started("party", ImmutableList.of("arg1", "arg2"), true, 23L);
eventBus.post(commandEventStarted);
eventBus.post(new PerfStatsTracking.MemoryPerfStatsEvent(/* freeMemoryBytes */
1024 * 1024L, /* totalMemoryBytes */
3 * 1024 * 1024L, /* timeSpentInGcMs */
-1, /* currentMemoryBytesUsageByPool */
ImmutableMap.of("flower", 42L * 1024 * 1024)));
ArtifactCacheConnectEvent.Started artifactCacheConnectEventStarted = ArtifactCacheConnectEvent.started();
eventBus.post(artifactCacheConnectEventStarted);
eventBus.post(ArtifactCacheConnectEvent.finished(artifactCacheConnectEventStarted));
BuildEvent.Started buildEventStarted = BuildEvent.started(buildArgs);
eventBus.post(buildEventStarted);
HttpArtifactCacheEvent.Started artifactCacheEventStarted = HttpArtifactCacheEvent.newFetchStartedEvent(ruleKey);
eventBus.post(artifactCacheEventStarted);
eventBus.post(HttpArtifactCacheEvent.newFinishedEventBuilder(artifactCacheEventStarted).setFetchDataBuilder(HttpArtifactCacheEventFetchData.builder().setFetchResult(CacheResult.hit("http"))).build());
ArtifactCompressionEvent.Started artifactCompressionStartedEvent = ArtifactCompressionEvent.started(ArtifactCompressionEvent.Operation.COMPRESS, ImmutableSet.of(ruleKey));
eventBus.post(artifactCompressionStartedEvent);
eventBus.post(ArtifactCompressionEvent.finished(artifactCompressionStartedEvent));
BuildRuleEvent.Started started = BuildRuleEvent.started(rule, durationTracker);
eventBus.post(started);
eventBus.post(StepEvent.started(stepShortName, stepDescription, stepUuid));
JavacPhaseEvent.Started runProcessorsStartedEvent = JavacPhaseEvent.started(target, JavacPhaseEvent.Phase.RUN_ANNOTATION_PROCESSORS, ImmutableMap.of());
eventBus.post(runProcessorsStartedEvent);
String annotationProcessorName = "com.facebook.FakeProcessor";
AnnotationProcessingEvent.Operation operation = AnnotationProcessingEvent.Operation.PROCESS;
int annotationRound = 1;
boolean isLastRound = false;
AnnotationProcessingEvent.Started annotationProcessingEventStarted = AnnotationProcessingEvent.started(target, annotationProcessorName, operation, annotationRound, isLastRound);
eventBus.post(annotationProcessingEventStarted);
HttpArtifactCacheEvent.Scheduled httpScheduled = HttpArtifactCacheEvent.newStoreScheduledEvent(Optional.of("TARGET_ONE"), ImmutableSet.of(ruleKey));
HttpArtifactCacheEvent.Started httpStarted = HttpArtifactCacheEvent.newStoreStartedEvent(httpScheduled);
eventBus.post(httpStarted);
HttpArtifactCacheEvent.Finished httpFinished = HttpArtifactCacheEvent.newFinishedEventBuilder(httpStarted).build();
eventBus.post(httpFinished);
final CompilerPluginDurationEvent.Started processingPartOneStarted = CompilerPluginDurationEvent.started(target, annotationProcessorName, "processingPartOne", ImmutableMap.of());
eventBus.post(processingPartOneStarted);
eventBus.post(CompilerPluginDurationEvent.finished(processingPartOneStarted, ImmutableMap.of()));
eventBus.post(AnnotationProcessingEvent.finished(annotationProcessingEventStarted));
eventBus.post(JavacPhaseEvent.finished(runProcessorsStartedEvent, ImmutableMap.of()));
eventBus.post(StepEvent.finished(StepEvent.started(stepShortName, stepDescription, stepUuid), 0));
eventBus.post(BuildRuleEvent.finished(started, BuildRuleKeys.of(ruleKey), BuildRuleStatus.SUCCESS, CacheResult.miss(), Optional.of(BuildRuleSuccessType.BUILT_LOCALLY), Optional.empty(), Optional.empty()));
try (final SimplePerfEvent.Scope scope1 = SimplePerfEvent.scope(eventBus, PerfEventId.of("planning"), ImmutableMap.<String, Object>of("nefarious", "true"))) {
try (final SimplePerfEvent.Scope scope2 = SimplePerfEvent.scope(eventBus, PerfEventId.of("scheming"))) {
scope2.appendFinishedInfo("success", "false");
}
}
eventBus.post(BuildEvent.finished(buildEventStarted, 0));
eventBus.post(CommandEvent.finished(commandEventStarted, /* exitCode */
0));
listener.outputTrace(new BuildId("BUILD_ID"));
File resultFile = new File(tmpDir.getRoot(), "buck-out/log/build.trace");
List<ChromeTraceEvent> originalResultList = mapper.readValue(resultFile, new TypeReference<List<ChromeTraceEvent>>() {
});
List<ChromeTraceEvent> resultListCopy = new ArrayList<>();
resultListCopy.addAll(originalResultList);
ImmutableMap<String, String> emptyArgs = ImmutableMap.of();
assertNextResult(resultListCopy, "process_name", ChromeTraceEvent.Phase.METADATA, ImmutableMap.of("name", "buck"));
assertNextResult(resultListCopy, "party", ChromeTraceEvent.Phase.BEGIN, ImmutableMap.of("command_args", "arg1 arg2"));
assertNextResult(resultListCopy, "memory", ChromeTraceEvent.Phase.COUNTER, ImmutableMap.of("used_memory_mb", "2", "free_memory_mb", "1", "total_memory_mb", "3", "time_spent_in_gc_sec", "0", "pool_flower_mb", "42"));
assertNextResult(resultListCopy, "artifact_connect", ChromeTraceEvent.Phase.BEGIN, emptyArgs);
assertNextResult(resultListCopy, "artifact_connect", ChromeTraceEvent.Phase.END, emptyArgs);
assertNextResult(resultListCopy, "build", ChromeTraceEvent.Phase.BEGIN, emptyArgs);
assertNextResult(resultListCopy, "http_artifact_fetch", ChromeTraceEvent.Phase.BEGIN, ImmutableMap.of("rule_key", "abc123"));
assertNextResult(resultListCopy, "http_artifact_fetch", ChromeTraceEvent.Phase.END, ImmutableMap.of("rule_key", "abc123", "success", "true", "cache_result", "HTTP_HIT"));
assertNextResult(resultListCopy, "artifact_compress", ChromeTraceEvent.Phase.BEGIN, ImmutableMap.of("rule_key", "abc123"));
assertNextResult(resultListCopy, "artifact_compress", ChromeTraceEvent.Phase.END, ImmutableMap.of("rule_key", "abc123"));
// BuildRuleEvent.Started
assertNextResult(resultListCopy, "//fake:rule", ChromeTraceEvent.Phase.BEGIN, ImmutableMap.of());
assertNextResult(resultListCopy, "fakeStep", ChromeTraceEvent.Phase.BEGIN, emptyArgs);
assertNextResult(resultListCopy, "run annotation processors", ChromeTraceEvent.Phase.BEGIN, emptyArgs);
assertNextResult(resultListCopy, "com.facebook.FakeProcessor.process", ChromeTraceEvent.Phase.BEGIN, emptyArgs);
assertNextResult(resultListCopy, "http_artifact_store", ChromeTraceEvent.Phase.BEGIN, ImmutableMap.of("rule_key", "abc123"));
assertNextResult(resultListCopy, "http_artifact_store", ChromeTraceEvent.Phase.END, ImmutableMap.of("success", "true", "rule_key", "abc123"));
assertNextResult(resultListCopy, "processingPartOne", ChromeTraceEvent.Phase.BEGIN, emptyArgs);
assertNextResult(resultListCopy, "processingPartOne", ChromeTraceEvent.Phase.END, emptyArgs);
assertNextResult(resultListCopy, "com.facebook.FakeProcessor.process", ChromeTraceEvent.Phase.END, emptyArgs);
assertNextResult(resultListCopy, "run annotation processors", ChromeTraceEvent.Phase.END, emptyArgs);
assertNextResult(resultListCopy, "fakeStep", ChromeTraceEvent.Phase.END, ImmutableMap.of("description", "I'm a Fake Step!", "exit_code", "0"));
assertNextResult(resultListCopy, "//fake:rule", ChromeTraceEvent.Phase.END, ImmutableMap.of("cache_result", "miss", "success_type", "BUILT_LOCALLY"));
assertNextResult(resultListCopy, "planning", ChromeTraceEvent.Phase.BEGIN, ImmutableMap.of("nefarious", "true"));
assertNextResult(resultListCopy, "scheming", ChromeTraceEvent.Phase.BEGIN, emptyArgs);
assertNextResult(resultListCopy, "scheming", ChromeTraceEvent.Phase.END, ImmutableMap.of("success", "false"));
assertNextResult(resultListCopy, "planning", ChromeTraceEvent.Phase.END, emptyArgs);
assertNextResult(resultListCopy, "build", ChromeTraceEvent.Phase.END, emptyArgs);
assertNextResult(resultListCopy, "party", ChromeTraceEvent.Phase.END, ImmutableMap.of("command_args", "arg1 arg2", "daemon", "true"));
assertEquals(0, resultListCopy.size());
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class EventSerializationTest method testBuildRuleEventFinished.
@Test
public void testBuildRuleEventFinished() throws IOException {
BuildRule rule = FakeBuildRule.newEmptyInstance("//fake:rule");
BuildRuleEvent.Started started = BuildRuleEvent.started(rule, durationTracker);
started.configure(timestamp - 11, nanoTime - 12, threadUserNanoTime - 13, threadId, buildId);
BuildRuleEvent.Finished event = BuildRuleEvent.finished(started, BuildRuleKeys.of(new RuleKey("aaaa")), BuildRuleStatus.SUCCESS, CacheResult.miss(), Optional.of(BuildRuleSuccessType.BUILT_LOCALLY), Optional.empty(), Optional.empty());
event.configure(timestamp, nanoTime, threadUserNanoTime, threadId, buildId);
String message = MAPPER.writeValueAsString(event);
assertJsonEquals("{%s,\"status\":\"SUCCESS\",\"cacheResult\":{\"type\":\"MISS\",\"cacheSource\":{" + "\"present\":false},\"cacheError\":{\"present\":false}," + "\"metadata\":{\"present\":false},\"artifactSizeBytes\":{\"present\":false}}," + "\"buildRule\":{\"type\":" + "\"fake_build_rule\",\"name\":\"//fake:rule\"}," + "\"type\":\"BuildRuleFinished\"," + "\"duration\":{" + "\"wallMillisDuration\":11,\"nanoDuration\":12,\"threadUserNanoDuration\":13}," + "\"ruleRunningAfterThisEvent\":false," + "\"eventKey\":{\"value\":1024186770}," + "\"ruleKeys\":{\"ruleKey\":{\"hashCode\":\"aaaa\"}," + "\"inputRuleKey\":{\"present\":false}," + "\"depFileRuleKey\":{\"present\":false}," + "\"manifestRuleKey\":{\"present\":false}}," + "\"outputHash\":{\"present\":false}},", message);
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class MachineReadableLogJsonViewTest method testBuildRuleEvent.
@Test
public void testBuildRuleEvent() throws IOException {
BuildRule rule = FakeBuildRule.newEmptyInstance("//fake:rule");
BuildRuleEvent.Started started = BuildRuleEvent.started(rule, durationTracker);
started.configure(timestamp, nanoTime, threadUserNanoTime, threadId, buildId);
BuildRuleEvent.Finished event = BuildRuleEvent.finished(started, BuildRuleKeys.builder().setRuleKey(new RuleKey("aaaa")).setInputRuleKey(Optional.of(new RuleKey("bbbb"))).build(), BuildRuleStatus.SUCCESS, CacheResult.of(CacheResultType.MISS, Optional.of("my-secret-source"), Optional.empty(), Optional.empty(), Optional.empty()), Optional.of(BuildRuleSuccessType.BUILT_LOCALLY), Optional.of(HashCode.fromString("abcd42")), Optional.empty());
event.configure(timestamp, nanoTime, threadUserNanoTime, threadId, buildId);
String message = WRITER.writeValueAsString(event);
assertJsonEquals("{%s,\"status\":\"SUCCESS\",\"cacheResult\":{\"type\":\"MISS\"," + "\"cacheSource\":\"my-secret-source\"}," + "\"buildRule\":{\"name\":\"//fake:rule\"}," + "\"ruleKeys\":{\"ruleKey\":{\"hashCode\":\"aaaa\"}," + "\"inputRuleKey\":{\"hashCode\":\"bbbb\"}}," + "\"outputHash\":\"abcd42\"},", message);
}
Aggregations