Add in logging of rule information.
Introduce buck.py server mode (parse perf pt2)

Summary:
Added a --server flag for buck.py which allows it to accept BUCK files to parse
on stdin so that multiple invocations of the script are not necessary to parse
a series of BUCK files.  In this mode, buck.py's output is also better structured
so that each individual BUCK file can be correlated with the list of rules
produced.

This doesn't actually improve parse time because Jython wasn't paying a
significant penalty per invocation of buck.py as its currently being used.  If
a python interpreter were to be used, however, the parse time step should
be 5x faster with this.

Test Plan: Smoke test building buck
Introduce keystore() rule.

Summary:
In a follow-up diff, `android_binary()`'s `keystore_properties` argument
will be removed in favor of a `keystore` argument whose value is a
`keystore()` rule.
Create events to track artifact cache fetches and stores.
Add hostname to logger.
Log additional information about the local configuration.
Measure time spent connecting to the distributed cache.
Introduce a new build rule, keystore(), that is required for an android_binary().

Summary:
The existing keystore_properties argument to android_binary() is a bad abstraction.

First, it requires the keystore.properties file to be in the same BUCK package as
the android_binary() rule that uses it. This makes it inconvenient to reuse the
same keystore in a single repository.

If the keystore referenced by the properties file changes, it will not trigger a
rebuild, as it is implemented today.

By creating a keystore() build rule that must specify the file where the key is
stored as well as the file that defines the other key properties, changes to
either file will trigger a rebuild for an android_binary that depends on the
keystore(). Further, the same keystore() can be accessed cleanly from any
android_binary() in the repository.

Note that although we could eliminate the properties file altogether and require
all data to be specified in the build rule definition, that would not
play well with continuous integration systems that want to overwrite a debug key
with a secret production key before building, as that would require such systems
to parse, edit, and regenerate the build file with the keystore() rule. Under
this design, the CI system only has to overwrite the keystore and keystore.properties
files.
Avoid a NumberFormatException when recreating non-idempotent RuleKeys.

Summary:
Currently if there is a non-idempotent rule written to disk (for example, a dependency of
a java_library) then builds will fail with a NumberFormatException. Avoid the NFE and allow
the build to continue.

Test Plan: buck test --all
Fork to invoke the interpreter and switch to using python by default (parse perf pt3)

Summary:
Once again invoke python/jython as a separate process.  Python is selected
as the new default for performance reasons and because this manner of
invoking Jython created a subtle regression in buck's own unit tests
(because they create many instances of the parser for simple jobs and
Jython's startup cost is so enormous).  Note that with buckd, many parse
invocations may yield slightly worse performance but in practice because
python starts up so much faster it should not be an issue in practice
(python buck.py --server starts up in about 0.1s whereas Jython takes about 3s).

Also had to upgrade jython to 2.5.4-rc1 due to upstream issues #1962
and #1972 to keep it working properly in this environment.

Test Plan:
Used buck build and buck targets to verify that both ./bin/jython and
python interpreters work.

Parse errors produce suboptimal results but are detected.
Make `buck-clean` delete buck-out/bin and buck-out/gen.

Test Plan: Sandcastle builds.
Extract BuckEvent interface.

Test Plan: Unit tests
Improve BUCK file parse error behaviour.

Summary:
Modify ProjectBuildFileParser to throw a checked exception instead of
the more generic and overloaded IOException.  Previously, all errors
from buck.py interaction were treated as an IOException and thrown
all the way to the main method.

Test Plan:
Created a syntax error in a BUCK file, observed that the output of
buck build originally was undesirable (double stack traces, the latter
of which was an I/O exception with little relevance to the actual
issue).  buck targets output is still not great (it prints a BUILD
FAILED message complaining about a missing target even though its not
the target which contained the BUCK file syntax error).  buck.py's
output is passed through to stderr and does show the parse error
plainly in either case.
Lazily construct buildFiles.

Summary:
Maybe this should be abstracted into a Cache class that takes a Supplier
and caches the last returned value until you invalidate it.

Only one call to constructBuildFileTree, and it's fast-ish.

The time also moved from watchFileSystem to parseBuildFilesForTargets,
which means that it will show up in the Chrome trace, which is good.

Test Plan: Needs tests.
Add BuildFileParseException to Parser test throw clauses.

Summary:
Some of the Parser tests were broken as they didn't declare
that they threw BuildFileParseException, this diff fixes them.

Test Plan: ant && ant test
Fetch from all remotes when trying to get the required revision.

Summary:
If the required revision is not in the local repository, Buck tries to
get it by running `git fetch`.  However this only works if the revision
is on the default remote, i.e. the one originally cloned from.  If the
required revision is on another remote, i.e. a forked version, it will
not be fetched.  Adding the `--all` option to `git fetch` fixes this.

Test Plan:
1. Clone buck from github.
2. Add another remote with `git remote add`.
3. In the test project set .buckversion to point to a revision that is
   only on the other remote.
4. Build the test project with `buck build`.

Change-Id: Iffd0fdff006b9bde8345d2f3623829372c1e1a83
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
Signed-off-by: Simon Stewart <simons@fb.com>

PR created from: https://github.com/facebook/buck/pull/32
Connect to Cassandra in a background thread and block all cache fetches on completion.
This effectively parellelizes connecting to Casandra with parsing and saves ~3s on startup time
Track time spent in each step.
Avoid reading the entire file into memory when hashing its contents.

Summary:
Prefer `ByteStreams.hash()` so that the file contents (in bytes) can
be hashed while being read from an InputStream rather than creating
a (potentially large) byte[] array and then hashing the array.

Test Plan: Sandcastle builds.
Enforce serialization of command execution.

Summary:
Currently buckd allows multiple commands to be executed concurrently, which can lead to buckd
being left in an invalid state. This change enforces that only one command can be run at a time
to avoid those problems.