Replace argparse with optparse in a few more places

Summary: As per title.

Test Plan: ant py-test, ant test, arc unit
Fix for asset catalogs on OS X

Summary: Handle the case where the --device argument to compile_asset_catalogs.py is not set.

Test Plan: None.
Load the AbiWriter from the current classloader.

Summary:
We're still seeing memory leaks from the java compilation. Most of the culprits point to
the AbiWriter not being properly garbabge collected. We know that the AbiWriter only uses
classes from the JRE, so it's fine for us to load it from the current classloader without
worrying it might accidentally pollute the classpath of classes being compiled.

With this fix in place, compilation of a large java codebase keeps PermGen usage to
around 30-40MB, and usage appears to return to normal levels at the end of a build.

Test Plan:
buck test --all --code-coverage
Check that coverage looks good
Build a large codebase and watch PermGen usage in jvisualvm
Bump guava to version 17 again.

Summary: Update the version of guava to the latest released version.

Test Plan:
* buck test --all
* build several projects
Create groups for projects in workspaces based on their path in the repo.

Summary:
After generating some workspaces I've noticed placing all projects except
for the one containing the main target doesn't work when projects don't have the
name of the library they're building, or are more recognizable by their path than
just their name (see the fbwebrtc dependencies). This lays out projects in the
workspace based on their path in the repo. It also removes the special treatment
for the workspace's main target.

Test Plan:
CI, generate a workspace for a target with many dependencies throughout
the repo.
Add Infer annotations. Annotate AndroidBinaryDescription.java.

Summary: Add jar file with Infer annotations to third-party.

Test Plan: buck test --all
Remove logic to extract existing GIDs from Xcode projects

Summary:
We no longer need this logic; GIDs will either be
(stably) generated, or specified in xcode_native rules.

This also improves perf, since we no longer need to read in and parse
existing Xcode projects when generating them.

Test Plan:
ant test -Dtest.class=ProjectGeneratorTest, buck project
in repo with generated Xcode projects
Redirect ant output to buck-out/log

Summary:
Does what it says on the tin. I also tidied up the error
messages on ant failure.

Test Plan:
Ran 'ant clean'. Introduced build error into a .java file, ran 'buck'
in another repo with .nobuckcheck. Confirmed error:

  Buck does not appear to have been built -- building Buck!

  BUILD FAILED
  /Users/foo/devtools/buck/build.xml:174: Compile failed; see the compiler error output for details.

  Total time: 9 seconds
  ::: 'ant' failed in the buck repo at /Users/foo/devtools/buck.
  ::: Check the logs at /Users/foo/src/fbobjc/buck-out/log/ant.log.
  ::: Try running: git -C "/Users/foo/devtools/buck" clean -xfd

Reverted build error in .java file, ran 'buck' again, confirmed
no ant output appeared.
Remove console output from Xcode project generation

Summary: This is overly verbose and is no longer needed.

Test Plan:
buck project in repo with xcode_project_config rules,
confirmed no output to console.
Fix running buck commands from any non root directory under a project.

Summary:
The bash scripts would `cd ..` until it found .buckconfig, which I missed when
I converted the scripts to Python. This actually does the right thing by not
changing directories and annoying the user.

Test Plan:
```
$ cd ~/fbcode/titan/iris
$ buck build iris
```
Do not compute git commit timestamp if BUCK_REPOSITORY_DIRTY env variable is set.

Summary:
We should probably use a different env variable to control this behavior, but I
don't want to hunt down all the repositories that set this variable and update
them.

Test Plan:
```
$ export BUCK_REPOSITORY_DIRTY=0
$ buckd
$ ps -ef | grep git_commit_timestamp=-1
```
Fix buck targets --referenced_file command.

Summary:
Before {D1498089}, the `startswith()` check was done on an absolute path. This
does the same thing on `Path`.

Test Plan:
Updated unit test which fails without this change.

```
$ cd ~/devtools/buck
$ buck targets --referenced_file third-party/java/dx-from-kitkat/NOTICE
```
no longer returns any targets.
Simplify buck.py and calling code by reducing the options

Summary:
Start to simplify buck.py and the parser code. Over time, this stuff has grown
organically. Time to start taking smarts out of buck.py and moving it
elsewhere in the system.

Test Plan:
buck test --all
Build several large, complex applications with buck
Try out a few "buck audit" options
Don't write workspaces and schemes if they haven't changed.

Summary:
This changes workspace and scheme writing to behave like project
writing and not do anything if the contents haven't changed.

Test Plan:
Run workspace generation, check timestamps of generated workspace
data and scheme, wait, run workspace generation again.
Add infer annotations to IJ project.

Summary: Apparently, they were missed out.

Test Plan: Build Buck in IntelliJ
Add SizeUnit.formatBytes()

Summary:
I'm adding a class which logs the memory consumption of
Buck.

To do that, I'd like a way to convert a byte value to its KB / MB /
etc. equivalent summary. This diff adds a new method,
SizeUnit.formatBytes(), which implements that.

Test Plan: Unit tests included.
Fix a bug in `buck run` where output was not being printed to the console.

Test Plan:
Updated `RunCommandIntegrationTest` to verify that new `buck run` behavior is working as intended.
Sandcastle builds.
[iOS] Per-target experimental "header map" mode to replace the PBXHeadersBuildPhase with header maps

Summary:
[iOS] Per-target experimental "header map" mode to replace the PBXHeadersBuildPhase with header maps

This implements the optional flag 'use_buck_header_maps' introduced in a previous diff.

By generating header maps at `buck project` time, we avoid copying the public headers around in subsequent compilations of a given build target.
Incidentally, we also prevent xcodebuild from generating its own header maps at compile time.
Altogether, this should speed up compilation by avoiding lots of disk accesses.

By design the new mode implements a stricter coding policy for headers.

# Public headers cannot include each other using user `""` includes. They must use the library `<>` includes.
# By default, headers are now target-visible, as opposed to project-visible.
# Xcode so-called "private" headers (essentially public ones with a `""` syntax) are unsupported.

Public headers can still be imported using the ""-syntax inside the same project.
Note that if a `""`-import occurs in a public header, this will break as soon as the public header is used outside the current target.

Test Plan: unit tests included
Fix check for same class in ArtifactCacheConnectEvent.

Summary:
I think ArtifactCacheConnectionEvent is supposed to check for
itself to tell whether an event is a pair or not.

Test Plan: CI
Replace osx_resource and ios_resource with apple_resource.

Summary: These two rules are handled almost identically (and exactly identically for Xcode projects), create them identically. For Buck builds, these should be handled by the target OS flavor (which doesn't exist yet).

Test Plan: Unit tests confirm behavior is the same. Try generating test projects using apple_resource, they work as expected.