Commit dbedbda7 authored by husky@chromium.org's avatar husky@chromium.org

Ignore block comments in JNI generator.

The JNI generator was being confused by the word 'native' appearing
in a block comment in ChromeBrowserProvider.java. This patch ensures
that all comments are stripped out correctly.

BUG=138941
TEST=jni_generator_tests.py


Review URL: https://chromiumcodereview.appspot.com/10830035

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148967 0039d316-1c4b-4281-b951-d872f2087c98
parent 854e131a
......@@ -78,6 +78,19 @@ class SampleForTests {
@CalledByNativeUnchecked
void methodThatThrowsException() throws Exception {}
// The generator is not confused by inline comments:
// @CalledByNative void thisShouldNotAppearInTheOutput();
// @CalledByNativeUnchecked public static void neitherShouldThis(int foo);
/**
* The generator is not confused by block comments:
* @CalledByNative void thisShouldNotAppearInTheOutputEither();
* @CalledByNativeUnchecked public static void andDefinitelyNotThis(int foo);
*/
// String constants that look like comments don't confuse the generator:
private String arrgh = "*/*";
//------------------------------------------------------------------------------------------------
// Java fields which are accessed from C++ code only must be annotated with @AccessedByNative to
// prevent them being eliminated when unreferenced code is stripped.
......
......@@ -451,11 +451,22 @@ class JNIFromJavaSource(object):
self.content = inl_header_file_generator.GetContent()
def _RemoveComments(self, contents):
ret = []
for c in [c.strip() for c in contents.split('\n')]:
if not c.startswith('//'):
ret += [c]
return '\n'.join(ret)
# We need to support both inline and block comments, and we need to handle
# strings that contain '//' or '/*'. Rather than trying to do all that with
# regexps, we just pipe the contents through the C preprocessor. We tell cpp
# the file has already been preprocessed, so it just removes comments and
# doesn't try to parse #include, #pragma etc.
#
# TODO(husky): This is a bit hacky. It would be cleaner to use a real Java
# parser. Maybe we could ditch JNIFromJavaSource and just always use
# JNIFromJavaP; or maybe we could rewrite this script in Java and use APT.
# http://code.google.com/p/chromium/issues/detail?id=138941
p = subprocess.Popen(args=['cpp', '-fpreprocessed'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, _ = p.communicate(contents)
return stdout
def GetContent(self):
return self.content
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment