Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3788)

Unified Diff: build/protoc_java.py

Issue 11146005: Add support for generating jars from protos and add cacheinvalidation_java. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated crbug link to use http:// Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/protoc_java.gypi ('k') | third_party/cacheinvalidation/cacheinvalidation.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/protoc_java.py
diff --git a/build/protoc_java.py b/build/protoc_java.py
new file mode 100755
index 0000000000000000000000000000000000000000..1c19db852c951045cd9b6453b4abb46f8bf51644
--- /dev/null
+++ b/build/protoc_java.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Generate java source files from protobufs
+
+Usage:
+ protoc_java.py {protoc} {proto_path} {java_out} {stamp_file} {proto_files}
+
+This is a helper file for the genproto_java action in protoc_java.gypi.
+
+It performs the following steps:
+1. Deletes all old sources (ensures deleted classes are not part of new jars).
+2. Creates source directory.
+3. Generates Java files using protoc.
+4. Creates a new stamp file.
+"""
+
+import os
+import shutil
+import subprocess
+import sys
+
+def main(argv):
+ if len(argv) < 5:
+ usage()
+ return 1
+
+ protoc_path = argv[1]
Isaac (away) 2012/10/31 21:32:48 nit: lines 30-33 can be shortened to: protoc_path
nyquist 2012/10/31 23:14:20 Done.
+ proto_path = argv[2]
+ java_out = argv[3]
+ stamp_file = argv[4]
+ proto_files = argv[5:]
+
+ # Delete all old sources
+ if os.path.exists(java_out):
+ shutil.rmtree(java_out)
+
+ # Create source directory
+ os.makedirs(java_out)
+
+ # Generate Java files using protoc
+ protoc_command = [protoc_path,
Isaac (away) 2012/10/31 21:32:48 nit: you could inline this: subprocess.call( [p
nyquist 2012/10/31 23:14:20 Done.
+ '--proto_path', proto_path,
+ '--java_out', java_out]
+ protoc_command.extend(proto_files)
+ ret = subprocess.call(protoc_command)
+ if ret != 0:
+ return ret
+
+ # Create a new stamp file
+ with file(stamp_file, 'a'):
Isaac (away) 2012/10/31 21:32:48 nit, you could always return ret (delete lines 49/
nyquist 2012/10/31 23:14:20 Done.
+ os.utime(stamp_file, None)
+
+ return 0
+
+def usage():
+ print(__doc__);
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
« no previous file with comments | « build/protoc_java.gypi ('k') | third_party/cacheinvalidation/cacheinvalidation.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698