Update buckd consoles. Summary: Parsers and FileHashCaches are reused by multiple commands, so need to have their consoles updated on each command so that they can log to the current console. Test Plan: 0) buck test --all 1) buckd 2) buck build -v 8 buck &> /dev/null 3) touch tmp 4) buck build -v 8 buck 2>&1 | head 5) check that 4 prints "Parser watched event ENTRY_MODIFY ... tmp"
diff --git a/src/com/facebook/buck/cli/Main.java b/src/com/facebook/buck/cli/Main.java index 3744688..1ce2d46 100644 --- a/src/com/facebook/buck/cli/Main.java +++ b/src/com/facebook/buck/cli/Main.java
@@ -110,6 +110,7 @@ private final class Daemon implements Closeable { private final Parser parser; + private final DefaultFileHashCache hashCache; private final EventBus fileEventBus; private final ProjectFilesystemWatcher filesystemWatcher; private final BuckConfig config; @@ -121,7 +122,7 @@ Console console) throws IOException { this.config = Preconditions.checkNotNull(config); this.console = Preconditions.checkNotNull(console); - DefaultFileHashCache hashCache = new DefaultFileHashCache(projectFilesystem, console); + this.hashCache = new DefaultFileHashCache(projectFilesystem, console); this.parser = new Parser(projectFilesystem, new KnownBuildRuleTypes(), console, @@ -187,13 +188,15 @@ }); } - private void watchFileSystem() throws IOException { + private void watchFileSystem(Console console) throws IOException { // Synchronize on parser object so that all outstanding watch events are processed // as a single, atomic Parser cache update and are not interleaved with Parser cache // invalidations triggered by requests to parse build files or interrupted by client // disconnections. synchronized (parser) { + parser.setConsole(console); + hashCache.setConsole(console); filesystemWatcher.postEvents(); } } @@ -336,7 +339,7 @@ if (context.isPresent()) { Daemon daemon = getDaemon(projectFilesystem, config, console); daemon.watchClient(context.get()); - daemon.watchFileSystem(); + daemon.watchFileSystem(console); daemon.initWebServer(); parser = daemon.getParser(); } else {
diff --git a/src/com/facebook/buck/parser/Parser.java b/src/com/facebook/buck/parser/Parser.java index c68c2b9..97c8f0b 100644 --- a/src/com/facebook/buck/parser/Parser.java +++ b/src/com/facebook/buck/parser/Parser.java
@@ -109,7 +109,7 @@ private final KnownBuildRuleTypes buildRuleTypes; private final ProjectBuildFileParserFactory buildFileParserFactory; private final RuleKeyBuilderFactory ruleKeyBuilderFactory; - private final Console console; + private Console console; /** * Key of the meta-rule that lists the build files executed while reading rules. @@ -125,6 +125,14 @@ private final ListMultimap<Path, Path> buildFileDependents; /** + * Parsers may be reused on different consoles, so need to allow the console to be set. + * @param console The new console that the Parser should use. + */ + public synchronized void setConsole(Console console) { + this.console = console; + } + + /** * A cached BuildFileTree which can be invalidated and lazily constructs new BuildFileTrees. * TODO(user): refactor this as a generic CachingSupplier<T> when it's needed elsewhere. */
diff --git a/src/com/facebook/buck/util/DefaultFileHashCache.java b/src/com/facebook/buck/util/DefaultFileHashCache.java index 9032b84..f2d6509 100644 --- a/src/com/facebook/buck/util/DefaultFileHashCache.java +++ b/src/com/facebook/buck/util/DefaultFileHashCache.java
@@ -38,7 +38,7 @@ public class DefaultFileHashCache implements FileHashCache { private final ProjectFilesystem projectFilesystem; - private final Console console; + private Console console; @VisibleForTesting final LoadingCache<Path, HashCode> loadingCache; @@ -83,9 +83,9 @@ * build rules if required. */ @Subscribe - public void onFileSystemChange(WatchEvent<?> event) throws IOException { + public synchronized void onFileSystemChange(WatchEvent<?> event) throws IOException { if (console.getVerbosity() == Verbosity.ALL) { - console.getStdErr().printf("ConcurrentMapFileHashCache watched event %s %s\n", event.kind(), + console.getStdErr().printf("DefaultFileHashCache watched event %s %s\n", event.kind(), projectFilesystem.createContextString(event)); } @@ -98,4 +98,12 @@ loadingCache.invalidateAll(); } } + + /** + * DefaultFileHashCaches may be reused on different consoles, so allow the console to be set. + * @param console The new console that the Parser should use. + */ + public synchronized void setConsole(Console console) { + this.console = console; + } }