From db26530b734579d7813345c519a62ea91db6158b Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Mon, 1 Aug 2016 13:26:51 -0700 Subject: [PATCH 1/3] Don't warn for TODOish comments. These just make it harder to detect when the file is clean of interesting errors. Change-Id: I6f2ae6368cdbd2800ce3f0461a3d456f79e6e994 --- cc/pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cc/pylintrc b/cc/pylintrc index 5d1aa9af9..ed49dd7ea 100644 --- a/cc/pylintrc +++ b/cc/pylintrc @@ -38,7 +38,7 @@ load-plugins= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -disable=design +disable=design,fixme [REPORTS] From a85042a040e10e912a3bcd282e5cc75030b26a0b Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Thu, 28 Jul 2016 16:58:27 -0700 Subject: [PATCH 2/3] Add a new tag to NDK symbol files: future. Symbols that have been added to a library but should not be exposed in any of the current NDK API levels should be tagged with "future". These will be suppressed from the NDK libraries. Once all this is in better shape we'll have `sdk: "current"`. Symbols tagged with "future" will be available for that. Note that this tag can be applied directly to a version. Aside from being more ergonomic than tagging an entire section, this also solved the problem of gen_stub_libs.py emitting an empty global section (which is not valid syntax) in the case where every symbol is "future". Tag the version instead and it will be omitted. Test: `make ndk` with libc/libm migration patches. Change-Id: I41f6e4939c406f695ab5725f360ec6554ad8ab31 --- cc/gen_stub_libs.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cc/gen_stub_libs.py b/cc/gen_stub_libs.py index a4a042141..78544c391 100755 --- a/cc/gen_stub_libs.py +++ b/cc/gen_stub_libs.py @@ -65,6 +65,12 @@ class Stack(object): return self.stack[-1] +def get_tags(line): + """Returns a list of all tags on this line.""" + _, _, all_tags = line.strip().partition('#') + return re.split(r'\s+', all_tags) + + def version_is_private(version): """Returns True if the version name should be treated as private.""" return version.endswith('_PRIVATE') or version.endswith('_PLATFORM') @@ -78,7 +84,8 @@ def enter_version(scope, line, version_file): # Entering a new version block. By convention symbols with versions ending # with "_PRIVATE" or "_PLATFORM" are not included in the NDK. version_name = line.split('{')[0].strip() - if version_is_private(version_name): + tags = get_tags(line) + if version_is_private(version_name) or 'future' in tags: scope.push(Scope.Private) else: scope.push(Scope.Global) # By default symbols are visible. @@ -166,6 +173,11 @@ def symbol_in_version(tags, arch, version): elif tag.startswith('introduced-' + arch + '='): introduced_tag = tag arch_specific = True + elif tag == 'future': + # This symbol is not in any released API level. + # TODO(danalbert): These need to be emitted for version == current. + # That's not a construct we have yet, so just skip it for now. + return False if introduced_tag is None: # We found no "introduced" tags, so the symbol has always been @@ -194,8 +206,7 @@ def handle_global_scope(scope, line, src_file, version_file, arch, api): # Line is now in the format "; # tags" # Tags are whitespace separated. symbol_name, _, rest = line.strip().partition(';') - _, _, all_tags = rest.partition('#') - tags = re.split(r'\s+', all_tags) + tags = get_tags(line) if not symbol_in_arch(tags, arch): return From 08532b6779281c3a5f4d4166914a26b047cd3459 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Thu, 28 Jul 2016 18:09:47 -0700 Subject: [PATCH 3/3] Allow more symbol file tags at top level. A version block might need to be omitted for reasons beyond just "future". Support all the same tags we do at symbol scope. Test: `make ndk` with libc/libm migration patches. Change-Id: I21f54c67079dae10fee1e5e08bcd01f8810e7a67 --- cc/gen_stub_libs.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/cc/gen_stub_libs.py b/cc/gen_stub_libs.py index 78544c391..4b7c244e5 100755 --- a/cc/gen_stub_libs.py +++ b/cc/gen_stub_libs.py @@ -76,7 +76,23 @@ def version_is_private(version): return version.endswith('_PRIVATE') or version.endswith('_PLATFORM') -def enter_version(scope, line, version_file): +def should_omit_version(name, tags, arch, api): + """Returns True if the version section should be ommitted. + + We want to omit any sections that do not have any symbols we'll have in the + stub library. Sections that contain entirely future symbols or only symbols + for certain architectures. + """ + if version_is_private(name): + return True + if not symbol_in_arch(tags, arch): + return True + if not symbol_in_version(tags, arch, api): + return True + return False + + +def enter_version(scope, line, version_file, arch, api): """Enters a new version block scope.""" if scope.top != Scope.Top: raise RuntimeError('Encountered nested version block.') @@ -85,7 +101,7 @@ def enter_version(scope, line, version_file): # with "_PRIVATE" or "_PLATFORM" are not included in the NDK. version_name = line.split('{')[0].strip() tags = get_tags(line) - if version_is_private(version_name) or 'future' in tags: + if should_omit_version(version_name, tags, arch, api): scope.push(Scope.Private) else: scope.push(Scope.Global) # By default symbols are visible. @@ -123,10 +139,10 @@ def leave_visibility(scope): assert scope.top == Scope.Top -def handle_top_scope(scope, line, version_file): +def handle_top_scope(scope, line, version_file, arch, api): """Processes a line in the top level scope.""" if '{' in line: - enter_version(scope, line, version_file) + enter_version(scope, line, version_file, arch, api) else: raise RuntimeError('Unexpected contents at top level: ' + line) @@ -228,7 +244,7 @@ def generate(symbol_file, src_file, version_file, arch, api): if line.strip() == '' or line.strip().startswith('#'): version_file.write(line) elif scope.top == Scope.Top: - handle_top_scope(scope, line, version_file) + handle_top_scope(scope, line, version_file, arch, api) elif scope.top == Scope.Private: handle_private_scope(scope, line, version_file) elif scope.top == Scope.Local: