Add dryrun argument to tools/archive.py

This can be run locally to ensure that everything is build (and we wil
print the locations for archiving)

Change-Id: I5c9481b80581a9a2b3e04cb9edfda58046c48596
diff --git a/tools/archive.py b/tools/archive.py
index 65f87a1..78a8189 100755
--- a/tools/archive.py
+++ b/tools/archive.py
@@ -5,6 +5,7 @@
 
 import create_maven_release
 import gradle
+import optparse
 import os
 import shutil
 import subprocess
@@ -16,6 +17,13 @@
 
 ARCHIVE_BUCKET = 'r8-releases'
 
+def ParseOptions():
+  result = optparse.OptionParser()
+  result.add_option('--dry-run', '--dry_run',
+      help='Build only, no upload.',
+      default=False, action='store_true')
+  return result.parse_args()
+
 def GetToolVersion(jar_path):
   output = subprocess.check_output(['java', '-jar', jar_path, '--version'])
   return output.splitlines()[0].strip()
@@ -79,7 +87,8 @@
   return GetVersionDestination('http://storage.googleapis.com/', '', is_master)
 
 def Main():
-  if not utils.is_bot():
+  (options, args) = ParseOptions()
+  if not utils.is_bot() and not options.dry_run:
     raise Exception('You are not a bot, don\'t archive builds')
 
   # Generate an r8-ed build without dependencies.
@@ -150,14 +159,20 @@
           zip.write(version_file, os.path.basename(version_file))
       destination = GetUploadDestination(version, file_name, is_master)
       print('Uploading %s to %s' % (tagged_jar, destination))
-      utils.upload_file_to_cloud_storage(tagged_jar, destination)
-      print('File available at: %s' % GetUrl(version, file_name, is_master))
+      if options.dry_run:
+        print('Dry run, not actually uploading')
+      else:
+        utils.upload_file_to_cloud_storage(tagged_jar, destination)
+        print('File available at: %s' % GetUrl(version, file_name, is_master))
       if file == utils.R8_JAR:
         # Upload R8 to a maven compatible location.
         maven_dst = GetUploadDestination(utils.get_maven_path(version),
                                          'r8-%s.jar' % version, is_master)
-        utils.upload_file_to_cloud_storage(tagged_jar, maven_dst)
-        print('Maven repo root available at: %s' % GetMavenUrl(is_master))
+        if options.dry_run:
+          print('Dry run, not actually creating maven repo')
+        else:
+          utils.upload_file_to_cloud_storage(tagged_jar, maven_dst)
+          print('Maven repo root available at: %s' % GetMavenUrl(is_master))
 
 
 if __name__ == '__main__':