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

Unified Diff: sync/protocol/prepare_protos_for_java_tests.py

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 5 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 | « sync/protocol/preference_specifics.proto ('k') | sync/protocol/priority_preference_specifics.proto » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/protocol/prepare_protos_for_java_tests.py
diff --git a/sync/protocol/prepare_protos_for_java_tests.py b/sync/protocol/prepare_protos_for_java_tests.py
deleted file mode 100755
index 0db4b9dc11625b6ed372935a66118925a8c4e9b4..0000000000000000000000000000000000000000
--- a/sync/protocol/prepare_protos_for_java_tests.py
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2015 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.
-
-"""Converts protocol buffer definitions to ones supported by the Nano library.
-
-Note: Java files generated from the output of this script should only be used
-in tests.
-
-Chromium uses the Java Protocol Buffers Nano runtime library. This library,
-compared to the standard proto compilter in C++, is limited. Most notably, the
-retain_unknown_fields option is not supported.
-
-This script also adds Java-specific configs to enable usage in Java. This script
-is Sync-specific, so a Sync package name is used.
-"""
-
-import optparse
-import os
-import re
-import sys
-
-
-def main():
- parser = optparse.OptionParser(
- usage='Usage: %prog [options...] original_proto_files')
- parser.add_option('-o', '--output_dir', dest='output_dir',
- help='Where to put the modified proto files')
-
- options, args = parser.parse_args()
- if not options.output_dir:
- print 'output_dir not specified.'
- return 1
-
- # Map of original base file names to their contents.
- original_proto_contents = {}
- for original_proto_file in args:
- with open(original_proto_file, 'r') as original_file:
- base_name = os.path.basename(original_proto_file)
- original_proto_contents[base_name] = original_file.read()
-
- for file_name, original_contents in original_proto_contents.iteritems():
- new_contents = ConvertProtoFileContents(original_contents)
- with open(os.path.join(options.output_dir, file_name), 'w') as new_file:
- new_file.write(new_contents)
-
-
-def ConvertProtoFileContents(contents):
- """Returns a Nano-compatible version of contents.
-
- Args:
- contents: The contents of a protocol buffer definition file.
- """
- # Remove the retain_unknown_fields option.
- incompatible_option_regex = re.compile(
- r'^\s*option\s+retain_unknown_fields\s*=.*;', re.MULTILINE)
- pruned_contents = incompatible_option_regex.sub('', contents)
-
- # Add the java_multiple_files and java_package options. Options must be set
- # after the syntax declaration, so look for the declaration and place the
- # options immediately after it.
- # TODO(pvalenzuela): Set Java options via proto compiler flags instead of
- # modifying the files here.
- syntax_regex = re.compile(r'^\s*syntax\s*=.*;', re.MULTILINE)
- syntax_end = syntax_regex.search(pruned_contents).end()
- java_options = ('option java_multiple_files = true; '
- 'option java_package = "org.chromium.sync.protocol";')
-
- contents_to_join = (pruned_contents[:syntax_end], java_options,
- pruned_contents[syntax_end:])
- return ''.join(contents_to_join)
-
-
-if __name__ == '__main__':
- sys.exit(main())
« no previous file with comments | « sync/protocol/preference_specifics.proto ('k') | sync/protocol/priority_preference_specifics.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698