diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/aapt2/cmd/Link_test.cpp | 18 | ||||
-rw-r--r-- | tools/aapt2/format/binary/BinaryResourceParser.cpp | 9 | ||||
-rw-r--r-- | tools/aapt2/java/ClassDefinition.h | 12 | ||||
-rw-r--r-- | tools/fonts/Android.bp | 51 | ||||
-rwxr-xr-x | tools/fonts/fontchain_linter.py | 45 | ||||
-rw-r--r-- | tools/hiddenapi/OWNERS | 7 | ||||
-rwxr-xr-x | tools/hiddenapi/checksorted_sha.sh | 10 | ||||
-rwxr-xr-x | tools/hiddenapi/exclude.sh | 38 | ||||
-rwxr-xr-x | tools/hiddenapi/sort_api.sh | 26 |
9 files changed, 158 insertions, 58 deletions
diff --git a/tools/aapt2/cmd/Link_test.cpp b/tools/aapt2/cmd/Link_test.cpp index dfdac6b9d93e..d1e6d3922f3f 100644 --- a/tools/aapt2/cmd/Link_test.cpp +++ b/tools/aapt2/cmd/Link_test.cpp @@ -466,11 +466,19 @@ TEST_F(LinkTest, StagedAndroidApi) { const std::string android_r_java = android_java + "/android/R.java"; std::string android_r_contents; ASSERT_TRUE(android::base::ReadFileToString(android_r_java, &android_r_contents)); - EXPECT_THAT(android_r_contents, HasSubstr(" public static final int finalized_res=0x01010001;")); - EXPECT_THAT(android_r_contents, HasSubstr(" public static int staged_s_res=0x01010050;")); - EXPECT_THAT(android_r_contents, HasSubstr(" public static int staged_s2_res=0x01ff0049;")); - EXPECT_THAT(android_r_contents, HasSubstr(" public static int staged_t_res=0x01fe0063;")); - EXPECT_THAT(android_r_contents, HasSubstr(" public static int staged_t_string=0x01fd0072;")); + EXPECT_THAT(android_r_contents, HasSubstr("public static final int finalized_res=0x01010001;")); + EXPECT_THAT( + android_r_contents, + HasSubstr("public static final int staged_s_res; static { staged_s_res=0x01010050; }")); + EXPECT_THAT( + android_r_contents, + HasSubstr("public static final int staged_s2_res; static { staged_s2_res=0x01ff0049; }")); + EXPECT_THAT( + android_r_contents, + HasSubstr("public static final int staged_t_res; static { staged_t_res=0x01fe0063; }")); + EXPECT_THAT( + android_r_contents, + HasSubstr("public static final int staged_t_string; static { staged_t_string=0x01fd0072; }")); // Build an app that uses the framework attribute in a declare-styleable const std::string client_res = GetTestPath("app-res"); diff --git a/tools/aapt2/format/binary/BinaryResourceParser.cpp b/tools/aapt2/format/binary/BinaryResourceParser.cpp index bfb8d5854d6d..f1b350fe90f7 100644 --- a/tools/aapt2/format/binary/BinaryResourceParser.cpp +++ b/tools/aapt2/format/binary/BinaryResourceParser.cpp @@ -393,8 +393,15 @@ bool BinaryResourceParser::ParseType(const ResourceTablePackage* package, .SetAllowMangled(true); if (entry->flags & ResTable_entry::FLAG_PUBLIC) { - res_builder.SetVisibility(Visibility{Visibility::Level::kPublic}); + Visibility visibility{Visibility::Level::kPublic}; + auto spec_flags = entry_type_spec_flags_.find(res_id); + if (spec_flags != entry_type_spec_flags_.end() && + spec_flags->second & ResTable_typeSpec::SPEC_STAGED_API) { + visibility.staged_api = true; + } + + res_builder.SetVisibility(visibility); // Erase the ID from the map once processed, so that we don't mark the same symbol more than // once. entry_type_spec_flags_.erase(res_id); diff --git a/tools/aapt2/java/ClassDefinition.h b/tools/aapt2/java/ClassDefinition.h index d3648c8aae52..2acdadb3c034 100644 --- a/tools/aapt2/java/ClassDefinition.h +++ b/tools/aapt2/java/ClassDefinition.h @@ -78,10 +78,18 @@ class PrimitiveMember : public ClassMember { ClassMember::Print(final, printer, strip_api_annotations); printer->Print("public static "); - if (final && !staged_api_) { + if (final) { printer->Print("final "); } - printer->Print("int ").Print(name_).Print("=").Print(to_string(val_)).Print(";"); + printer->Print("int ").Print(name_); + if (staged_api_) { + // Prevent references to staged apis from being inline by setting their value out-of-line. + printer->Print("; static { ").Print(name_); + } + printer->Print("=").Print(to_string(val_)).Print(";"); + if (staged_api_) { + printer->Print(" }"); + } } private: diff --git a/tools/fonts/Android.bp b/tools/fonts/Android.bp new file mode 100644 index 000000000000..8ea114f1efc2 --- /dev/null +++ b/tools/fonts/Android.bp @@ -0,0 +1,51 @@ +// Copyright (C) 2021 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +python_defaults { + name: "fonts_python_defaults", + version: { + py2: { + enabled: false, + embedded_launcher: false, + }, + py3: { + enabled: true, + embedded_launcher: true, + }, + }, +} + +python_binary_host { + name: "fontchain_linter", + defaults: ["fonts_python_defaults"], + main: "fontchain_linter.py", + srcs: [ + "fontchain_linter.py", + ], + libs: [ + "fontTools", + ], +} + +python_binary_host { + name: "update_font_metadata", + defaults: ["fonts_python_defaults"], + main: "update_font_metadata.py", + srcs: [ + "update_font_metadata.py", + ], + libs: [ + "fontTools", + ], +} diff --git a/tools/fonts/fontchain_linter.py b/tools/fonts/fontchain_linter.py index f0b759547a93..1d308df00ef7 100755 --- a/tools/fonts/fontchain_linter.py +++ b/tools/fonts/fontchain_linter.py @@ -4,6 +4,7 @@ import collections import copy import glob from os import path +import re import sys from xml.etree import ElementTree @@ -199,8 +200,9 @@ def check_hyphens(hyphens_dir): class FontRecord(object): - def __init__(self, name, scripts, variant, weight, style, fallback_for, font): + def __init__(self, name, psName, scripts, variant, weight, style, fallback_for, font): self.name = name + self.psName = psName self.scripts = scripts self.variant = variant self.weight = weight @@ -236,6 +238,7 @@ def parse_fonts_xml(fonts_xml_path): assert variant in {None, 'elegant', 'compact'}, ( 'Unexpected value for variant: %s' % variant) + trim_re = re.compile(r"^[ \n\r\t]*(.+)[ \n\r\t]*$") for family in families: name = family.get('name') variant = family.get('variant') @@ -251,6 +254,10 @@ def parse_fonts_xml(fonts_xml_path): assert child.tag == 'font', ( 'Unknown tag <%s>' % child.tag) font_file = child.text.rstrip() + + m = trim_re.match(font_file) + font_file = m.group(1) + weight = int(child.get('weight')) assert weight % 100 == 0, ( 'Font weight "%d" is not a multiple of 100.' % weight) @@ -270,11 +277,12 @@ def parse_fonts_xml(fonts_xml_path): if index: index = int(index) - if not path.exists(path.join(_fonts_dir, font_file)): + if not path.exists(path.join(_fonts_dir, m.group(1))): continue # Missing font is a valid case. Just ignore the missing font files. record = FontRecord( name, + child.get('postScriptName'), frozenset(scripts), variant, weight, @@ -664,6 +672,37 @@ def check_cjk_punctuation(): break assert_font_supports_none_of_chars(record.font, cjk_punctuation, name) +def getPostScriptName(font): + font_file, index = font + font_path = path.join(_fonts_dir, font_file) + if index is not None: + # Use the first font file in the collection for resolving post script name. + ttf = ttLib.TTFont(font_path, fontNumber=0) + else: + ttf = ttLib.TTFont(font_path) + + nameTable = ttf['name'] + for name in nameTable.names: + if (name.nameID == 6 and name.platformID == 3 and name.platEncID == 1 + and name.langID == 0x0409): + return str(name) + +def check_canonical_name(): + for record in _all_fonts: + file_name, index = record.font + + psName = getPostScriptName(record.font) + if record.psName: + # If fonts element has postScriptName attribute, it should match with the PostScript + # name in the name table. + assert psName == record.psName, ('postScriptName attribute %s should match with %s' % ( + record.psName, psName)) + else: + # If fonts element doesn't have postScriptName attribute, the file name should match + # with the PostScript name in the name table. + assert psName == file_name[:-4], ('file name %s should match with %s' % ( + file_name, psName)) + def main(): global _fonts_dir @@ -682,6 +721,8 @@ def main(): check_cjk_punctuation() + check_canonical_name() + check_emoji = sys.argv[2] if check_emoji == 'true': ucd_path = sys.argv[3] diff --git a/tools/hiddenapi/OWNERS b/tools/hiddenapi/OWNERS new file mode 100644 index 000000000000..afbeef5a0b41 --- /dev/null +++ b/tools/hiddenapi/OWNERS @@ -0,0 +1,7 @@ +# compat-team@ for changes to hiddenapi files +andreionea@google.com +mathewi@google.com +satayev@google.com + +# soong-team@ as the files these tools protect are tightly coupled with Soong +file:platform/build/soong:/OWNERS diff --git a/tools/hiddenapi/checksorted_sha.sh b/tools/hiddenapi/checksorted_sha.sh deleted file mode 100755 index ceb705f4e42a..000000000000 --- a/tools/hiddenapi/checksorted_sha.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e -LOCAL_DIR="$( dirname ${BASH_SOURCE} )" -git show --name-only --pretty=format: $1 | grep "config/hiddenapi-.*txt" | while read file; do - diff <(git show $1:$file) <(git show $1:$file | $LOCAL_DIR/sort_api.sh ) || { - echo -e "\e[1m\e[31m$file $1 is not sorted or contains duplicates. To sort it correctly:\e[0m" - echo -e "\e[33m${LOCAL_DIR}/sort_api.sh $2/frameworks/base/$file\e[0m" - exit 1 - } -done diff --git a/tools/hiddenapi/exclude.sh b/tools/hiddenapi/exclude.sh index 73eacc0641e5..8b18f9b1920e 100755 --- a/tools/hiddenapi/exclude.sh +++ b/tools/hiddenapi/exclude.sh @@ -7,12 +7,9 @@ LOCAL_DIR="$( dirname ${BASH_SOURCE} )" # the team email to use in the event of this detecting an entry in a <team> package. Also # add <team> to the TEAMS list. LIBCORE_PACKAGES="\ - android.icu \ android.system \ android.test \ com.android.bouncycastle \ - com.android.conscrypt \ - com.android.i18n.phonenumbers \ com.android.okhttp \ com.sun \ dalvik \ @@ -24,37 +21,54 @@ LIBCORE_PACKAGES="\ org.json \ org.w3c.dom \ org.xml.sax \ + org.xmlpull.v1 \ sun \ " LIBCORE_EMAIL=libcore-team@android.com +I18N_PACKAGES="\ + android.icu \ + " + +I18N_EMAIL=$LIBCORE_EMAIL + +CONSCRYPT_PACKAGES="\ + com.android.org.conscrypt \ + " + +CONSCRYPT_EMAIL=$LIBCORE_EMAIL + # List of teams. -TEAMS=LIBCORE +TEAMS="LIBCORE I18N CONSCRYPT" + +SHA=$1 # Generate the list of packages and convert to a regular expression. PACKAGES=$(for t in $TEAMS; do echo $(eval echo \${${t}_PACKAGES}); done) RE=$(echo ${PACKAGES} | sed "s/ /|/g") -git show --name-only --pretty=format: $1 | grep "config/hiddenapi-.*txt" | while read file; do - ENTRIES=$(grep -E "^L(${RE})/" || true <(git show $1:$file)) +EXIT_CODE=0 +for file in $(git show --name-only --pretty=format: $SHA | grep "boot/hiddenapi/hiddenapi-.*txt"); do + ENTRIES=$(grep -E "^\+L(${RE})/" <(git diff ${SHA}~1 ${SHA} $file) | sed "s|^\+||" || echo) if [[ -n "${ENTRIES}" ]]; then - echo -e "\e[1m\e[31m$file $1 contains the following entries\e[0m" + echo -e "\e[1m\e[31m$file $SHA contains the following entries\e[0m" echo -e "\e[1m\e[31mfor packages that are handled using UnsupportedAppUsage. Please remove\e[0m" echo -e "\e[1m\e[31mthese entries and add annotations instead.\e[0m" # Partition the entries by team and provide contact details to aid in fixing the issue. for t in ${TEAMS} do PACKAGES=$(eval echo \${${t}_PACKAGES}) - RE=$(echo ${PACKAGES} | sed "s/ /|/g") - TEAM_ENTRIES=$(grep -E "^L(${RE})/" <(echo "${ENTRIES}")) + TEAM_RE=$(echo ${PACKAGES} | sed "s/ /|/g") + TEAM_ENTRIES=$(grep -E "^L(${TEAM_RE})/" <(echo "${ENTRIES}") || echo) if [[ -n "${TEAM_ENTRIES}" ]]; then EMAIL=$(eval echo \${${t}_EMAIL}) - echo -e "\e[33mContact ${EMAIL} or compat- for help with the following:\e[0m" - for i in ${ENTRIES} + echo -e "\e[33mContact ${EMAIL} for help with the following:\e[0m" + for i in ${TEAM_ENTRIES} do echo -e "\e[33m ${i}\e[0m" done fi done - exit 1 + EXIT_CODE=1 fi done +exit $EXIT_CODE diff --git a/tools/hiddenapi/sort_api.sh b/tools/hiddenapi/sort_api.sh deleted file mode 100755 index 710da40585ac..000000000000 --- a/tools/hiddenapi/sort_api.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -set -e -if [ -z "$1" ]; then - source_list=/dev/stdin - dest_list=/dev/stdout -else - source_list="$1" - dest_list="$1" -fi -# Load the file -readarray A < "$source_list" -# Sort -IFS=$'\n' -# Stash away comments -C=( $(grep -E '^#' <<< "${A[*]}" || :) ) -A=( $(grep -v -E '^#' <<< "${A[*]}" || :) ) -# Sort entries -A=( $(LC_COLLATE=C sort -f <<< "${A[*]}") ) -A=( $(uniq <<< "${A[*]}") ) -# Concatenate comments and entries -A=( ${C[*]} ${A[*]} ) -unset IFS -# Dump array back into the file -if [ ${#A[@]} -ne 0 ]; then - printf '%s\n' "${A[@]}" > "$dest_list" -fi |