Migrate some rules over to being Buildables.

Summary: Continue migrating some rules over to the New World.

Test Plan:
buck test --all
Add integration test to reproduce bug where genfiles are listed as srcs.

Summary:
If the genfile is changed but the other sources are not, the jar is not rebuilt,
and so the resulting jar contains the old genfiles.

Test Plan: Run GenfileAsSrcIntegrationTest
Decrease ZIP_SIZE_SOFT_LIMIT by 1mb.
Add platform-specific command parameters to genrule.

Summary:
Add 2 parameters `win` and `sh` to `genrule` and make `cmd` optional,
in which `win` is Windows-specific and `sh` is non-windows specific command.
`cmd` is platform independent and has a lower priority if the platform-specific command is given.

The priority sequence is (on Windows):

  "cmd.exe /c [cmd_exe]"
  "cmd.exe /c [cmd]"

On non-windows os:

  "/bin/bash -c [bash]"
  "/bin/bash -c [cmd]"

This would provide backward compatibility.

Test Plan: Unit tests.
Fix ParserIntegrationTest on Windows.

Summary:
Add Windows-specific command to `BUILD_DEFS`.
Since `echo` in `cmd.exe` always prints `\r\n`,
we have to manually convert the line endings in unit test.

Test Plan: Unit tests.
Introduce BuildableContext.

Summary:
A BuildableContext is a context object that is created for an individual
BuildRule. This differs from a BuildContext, which is a single object
that is injected/shared in all BuildRules that are part of the same build.

Test Plan: Sandcastle builds.
Fix a bug in `ProjectWorkspace.setUp()`.

Summary:
In Windows symlink hack, if a file is empty,
`File linkToFile = new File(templatePath.toFile(), linkTo)` will
point to the folder `templatePath`. Fixed this bug by checking size.

Test Plan: Unit tests.
Port DaemonIntegrationTest to Windows.

Summary:
`DaemonIntegrationTest.testExclusiveExecution()` invokes `sleep 1s` with `genrule`.
Add Windows-specific command.

Test Plan: Unit tests.
Add support for resource directories for robolectric2's WithDefaultsTestRunner.

Summary:
In order to be able to use resources in unit tests we need to pass
a list of resource directories a specific test depends on to
WithDefaultsTestRunner. This diff adds directory list to vm arguments
before running robolectric based unit tests.
Reimplement CompileSrcZipIntegrationTest on Windows.

Summary:
This test is platform-dependent before (requiring `zip` command).
Reimplemented it with a Java zip tool instead of shelling out to `zip`.

Test Plan: Unit tests.
Fix unit test GenruleTest on Windows.

Summary: Dealt with problems of string pattern matching related to directory separators.

Test Plan: Unit tests.
Zip up all of the outputs for a build rule and store them as a single artifact.

Summary:
Previously, we used a complex scheme for storing metadata for a build rule
in the artifact cache. This diff introduces a vast simplification (note how much
code is removed from `DefaultJavaLibraryRule` as a result of this diff) where all outputs
and metadata for a build rule are stored in a zip file, and the zip file is stored in
the artifact cache. (Therefore, all metadata must be written to a file before it can
be included in the zip.) The structure of the zip file is such that it matches the layout
of the files in the user's project directory. This means that after an artifact is
downloaded, it can be unzipped in the root of the user's project directory to match
the state of `buck-out` as if the rule had been built locally.

There are two major abstractions introduced in this diff: `OnDiskBuildInfo` and
`BuildInfoRecorder`. Both of these are designed to help manage build rule
outputs and metadata (where metadata would be something like the ABI for a `java_library()` rule).

When deciding whether a rule needs to be built locally or if the current output file
in `buck-out` is valid, the current `RuleKey` must be compared with the
`RuleKey` on disk. The `OnDiskBuildInfo` is the interface through which the
`RuleKey` on disk is queried. This is true for all metadata about the output from
the previous execution of the build rule.

In a complementary fashion, `BuildInfoRecorder` is used to keep a record of all
metadata and output files generated by the build rule. Assuming the rule builds successfully,
the `BuildInfoRecorder` will write all of this data to disk, and will then zip it up
as a file to be stored in the artifact cache.

This diff introduces a new object, `BuildableContext`, which is passed along with
`BuildContext` to `Buildable`'s `getBuildSteps()` method. `BuildableContext` contains
data that is specific to the build rule being built, as opposed to `BuildContext`,
which contains shared data universal to all build rules.

This new scheme eliminates the need for the `ArchivingRule` that was introduced
earlier. This diff effectively reverts that diff, and updates `PrebuiltNativeLibrary`
and `NdkLibrary` so they extend `AbstractBuildable` rather than
`DoNotUseAbstractBuildable`. This will help us on our crusade to eliminate
`DoNotUseAbstractBuildable`, after which we can convert
`AbstractCachingBuildRule` from an abstract class to a non-extendible class
whose purpose in life is to execute `Buildable`s.

I also eliminated the `com.facebook.buck.cpp` package for now, as the only rule
in there (`PrebuiltNativeLibrary`) had Android-specific behavior because the layout
of its "libs" directory was required to have a structure that reflected that which
is required by Android. This code is now in the `com.facebook.buck.android`
package where it belongs.

Previously, `GenAidlRule` was not cacheable because it did not know where it
would generate its output files. This is exactly the type of issue that
`BuildInfoRecorder` is designed to solve, so `GenAidlRule` has been updated to
use `BuildInfoRecorder` so that it can be cached. While I was at it, I also
renamed `GenAidlRule` to `GenAidl`, as it now also extends `AbstractBuildable`
instead of `DoNotUseAbstractBuildable`.
Track build file dependencies.

Summary:
Only invalidate affected cached build rules when:
1) the build file containing the rules is changed or removed
2) a file the build file transitively includes is changed or removed or
3) a file that could be in a glob in the build file is added or removed
This should greatly improve the performance of the buckd build file cache,
which currently invalidates the entire cache when anything changes.

Test Plan: ant && ant test
Move most zip functionality into a zip package.

Summary:
This is the first step in implementing ZipStep and UnzipStep using pure Java rather than
relying on shell commands. This simply rearranges the code by moving many of the zip
related classes (though not all of them: some are utils and some are Android specific)
into their own package.

Test Plan:
buck test --all
Manual inpsection to verify that the new zip tests have run.
Fix GenfileAsSrcIntergrationTest on Windows

Summary: Add Windows command for genrule at GenfileAsSrcIntergrationTest.

Test Plan: Unit test
Fix AndroidBinaryRule to include cpuFilters and dexSplitMode in its RuleKey.

Summary:
To avoid circular dependencies, this required the introduction of
`//src/com/facebook/buck/rules:build_rule` and
`//src/com/facebook/buck/android:split_dex`.
As a result, many `BUCK` files were touched.

Test Plan: Sandcastle builds.
Fix the computation of the hash for a dirty Git repository.

Summary:
Previously, the call to `git ls-tree` to compute the hash of a dirty
Git repository specified a list of paths to include in the hash.
This list was:

  bin build.xml config lib third-party

The `src` directory and `DEFS` and `.buckconfig` files were conspicuously
missing from this list, as they all affect the behavior of Buck,
as the files in the list do.

However, it is simpler and safer to consider all version controlled files
when computing the hash, which is what `git ls-tree` without any paths
appears to do.

Test Plan:
I took the appropriate chunk of `bin/buck_common` and ran `git ls-tree`
without any paths. The contents of the resulting file were:

```
100644 blob 269c00a240c000ba34d1ed65c121f497cedcab6d	.arcconfig
100644 blob d22dc6e7f9d353c6e8a2c128dc35cfbe36e42ae3	.buckconfig
100644 blob 192a018b263c876bee0bc6ed5412fde721ce5f0c	.classpath
100644 blob 463747e3d3f7fe70afba1711a11f9453e3cbb113	.gitignore
040000 tree 960bc780d7fdbe18d2f5871cc9d23f73a16ee9e6	.idea
100644 blob b86ac4ac38bff4e1fe13eb6f1bd23108d7a2da50	.project
100644 blob 742e765d4d21710a7f517aee061dc98f00215f6b	DEFS
100644 blob d645695673349e3947e8e5ae42332d0ac3164cd7	LICENSE
100644 blob 42ed037e0c84bdf2cc65b2802e75af198f4de225	NOTES.txt
100644 blob 962f05867c923e6c0caa0872c3fba84f6178efc9	README.md
100755 blob e88a1affe24d4b4ce7179287c32150bbb091d1db	arc_unit.sh
040000 tree c42fc50ae9028f5ddf52759a0489b7f7c377f25f	arcanist
100644 blob a4a7a21d544a57dece2d315129565438a4f1c309	assert_code_coverage.py
100755 blob 4734d04c83703843929230d3dd6fb1de010b6995	automation.sh
040000 tree cca72d3917b3abe6f4d9dc338eceeee14d3b218c	bin
100644 blob d1b85a4348dce1a4cb2ecd5ad59ccad88106579c	buck.iml
100644 blob 81f7f4fcd81884a5aefa12b2e432b125021a64a4	build.xml
040000 tree 5d333f56235a5d20f6cdccff205b6556ef8fc8ca	config
040000 tree a1bcb00b5e48b4d230e8488d73349221d9ff8235	docs
040000 tree a5f9be5be8daf0dc542149dad8465c96a078f4e2	lib
040000 tree 8c86bb01a6f8515f76c9cdfb22516ab029fd2ae7	opensource
040000 tree 963ba362422381b820146f6a5b44bf660c4ee0c0	pmd
040000 tree 16d2973d11bd69abfe0c6621b5ae865c6037da20	scripts
040000 tree fe7d5fb59b075d0aa4f8867a4dcd5a0ea6fb804c	src
040000 tree 96c9fa2f6b0a1f4d5f684b5c54f8a635ee9426de	test
040000 tree 07d98f0dbb37b0c15346affe5f3f25f1cfa616f7	testdata
040000 tree 93be27eed3fb2667aa2116830615151dd8d74e1b	testrunner
040000 tree 964cd008c6a9daf6f7072b5b47cc69823b32d998	third-party
```

Note that `buck-out` and `build` are omitted from this list even
though they exist in the local Buck repository. This demonstrates that
generated files are excluded from the repository hash, as desired.
Remove old buck-bin/ and emma-2.0.5312/ directories, if present.
Make sure SymlinkFileStep deletes the existing file before overwriting it.

Summary:
I encountered this issue because I was debugging something in a downloaded
tar of a co-worker's fbandroid repo. It contained the following file:

```
~/code/andrews/fb4a2$ ls -al buck-out/gen/releasebuild-properties
lrwxrwxrwx 1 mbolin mbolin 45 Sep  3 16:10 buck-out/gen/releasebuild-properties -> /Users/andrews/fb4a/./releasebuild.properties
~/code/andrews/fb4a2$
```

As you can see, `buck-out/gen/releasebuild-properties` was a symlink, but
to a file on `andrews`'s machine, which was not on my machine. When
`SymlinkFileStep` was used to overwrite `releasebuild-properties`, it threw a
`FileAlreadyExistsException` even though we did the following to delete the
file before linking it in `SymlinkFileStep`:

  if (targetPath.toFile().exists() && !targetPath.toFile().delete()) {
    throw new HumanReadableException("Failed to delete symbolic link for %s",
        targetPath.toAbsolutePath());
  }
  context.getProjectFilesystem().createSymLink(sourcePath, targetPath);

It turns out that if `targetPath` references a symlink that points to a
non-existent file, then the `exists()` call will return `false`, which
means the `delete()` method will never get executed. When the file is not
deleted, the call to `createSymLink` will throw a `FileAlreadyExistsException`.

I'm not sure whether we could encounter this issue in ordinary usage, but it
seems like a good idea to defend against it, anyway.

Test Plan:
Created `SymlinkFileStepTest#testReplaceMalformedSymlink()`,
verified that `SymlinkFileStep.execute()` threw an exception when I ran the test,
and then fixed `SymlinkFileStep.execute()` so the test passed.
Fix some build cache interaction issues in AndroidResourceRule.

Summary:
(1) `AndroidResourceRule` was writing its output to `buck-out/bin`
instead of `buck-out/gen`. This was causing the following check
in `AbstractCachingBuildRule` to fail:

```
if (pathToOutputFile != null && pathToOutputFile.startsWith(BuckConstant.GEN_DIR)) {
  String prefix = BuckConstant.GEN_DIR + '/' + getBuildTarget().getBasePathWithSlash();
  buildInfoRecorder.recordArtifact(pathToOutputFile.substring(prefix.length()));
}
```

After fixing this for `AndroidResourceRule`, I manually inspected the
`getPathToOutputFile()` method in all build rules, and verified that
if a non-null value was returned, it started with `buck-out/gen`.

(2) `AndroidResourceRule` had two fields that were not being included in its RuleKey.

Test Plan: Sandcastle builds.