summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Izabela Orlowska <imorlowska@google.com> 2018-07-24 11:33:46 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2018-07-24 11:33:46 +0000
commit148cd8c0bced9bcd72beb2e93a086fde9dcfef9e (patch)
tree13f6707bf6dedc2a00b9549fa10a704bc300c051
parent78cc39573f4f4ecc617c2fee0e98a9ba5cb33fc4 (diff)
parent58e2fbf16970d9e0c1e93f60b881765e87bfc7a6 (diff)
Merge "Revert "AAPT2: Automatic Static Library Namespacing.""
-rw-r--r--tools/aapt2/cmd/Compile.cpp4
-rw-r--r--tools/aapt2/cmd/Convert.cpp4
-rw-r--r--tools/aapt2/cmd/Diff.cpp4
-rw-r--r--tools/aapt2/cmd/Dump.cpp4
-rw-r--r--tools/aapt2/cmd/Link.cpp18
-rw-r--r--tools/aapt2/cmd/Link.h5
-rw-r--r--tools/aapt2/cmd/Optimize.cpp4
-rw-r--r--tools/aapt2/integration-tests/AutoNamespaceTest/Android.mk18
-rw-r--r--tools/aapt2/integration-tests/AutoNamespaceTest/LibOne/Android.mk29
-rw-r--r--tools/aapt2/integration-tests/AutoNamespaceTest/LibOne/AndroidManifest.xml17
-rw-r--r--tools/aapt2/integration-tests/AutoNamespaceTest/LibOne/res/values/values.xml27
-rw-r--r--tools/aapt2/integration-tests/AutoNamespaceTest/LibOne/src/com/example/android/aapt2/autonamespace/staticlib/one/StaticLibOne.java18
-rw-r--r--tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/Android.mk29
-rw-r--r--tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/AndroidManifest.xml17
-rw-r--r--tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/res/layout/layout_two.xml18
-rw-r--r--tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/res/values/values.xml19
-rw-r--r--tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/src/com/example/android/aapt2/autonamespace/staticlib/two/StaticLibTwo.java25
-rw-r--r--tools/aapt2/link/ReferenceLinker.cpp26
-rw-r--r--tools/aapt2/link/ReferenceLinker.h10
-rw-r--r--tools/aapt2/link/ReferenceLinker_test.cpp71
-rw-r--r--tools/aapt2/link/XmlReferenceLinker.cpp4
-rw-r--r--tools/aapt2/link/XmlReferenceLinker_test.cpp43
-rw-r--r--tools/aapt2/optimize/MultiApkGenerator.cpp4
-rw-r--r--tools/aapt2/process/IResourceTableConsumer.h1
-rw-r--r--tools/aapt2/process/SymbolTable.cpp29
-rw-r--r--tools/aapt2/process/SymbolTable.h16
-rw-r--r--tools/aapt2/process/SymbolTable_test.cpp35
-rw-r--r--tools/aapt2/test/Context.h19
28 files changed, 22 insertions, 496 deletions
diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp
index 8c1fa9ac0226..36b5578d1deb 100644
--- a/tools/aapt2/cmd/Compile.cpp
+++ b/tools/aapt2/cmd/Compile.cpp
@@ -690,10 +690,6 @@ class CompileContext : public IAaptContext {
return 0;
}
- bool IsAutoNamespace() override {
- return false;
- }
-
private:
DISALLOW_COPY_AND_ASSIGN(CompileContext);
diff --git a/tools/aapt2/cmd/Convert.cpp b/tools/aapt2/cmd/Convert.cpp
index 4b82eefa7d6f..d57eaa1ba145 100644
--- a/tools/aapt2/cmd/Convert.cpp
+++ b/tools/aapt2/cmd/Convert.cpp
@@ -311,10 +311,6 @@ class Context : public IAaptContext {
return 0u;
}
- bool IsAutoNamespace() override {
- return false;
- }
-
bool verbose_ = false;
std::string package_;
diff --git a/tools/aapt2/cmd/Diff.cpp b/tools/aapt2/cmd/Diff.cpp
index 7875a2bb7a86..262f4fc4e394 100644
--- a/tools/aapt2/cmd/Diff.cpp
+++ b/tools/aapt2/cmd/Diff.cpp
@@ -65,10 +65,6 @@ class DiffContext : public IAaptContext {
return 0;
}
- bool IsAutoNamespace() override {
- return false;
- }
-
private:
std::string empty_;
StdErrDiagnostics diagnostics_;
diff --git a/tools/aapt2/cmd/Dump.cpp b/tools/aapt2/cmd/Dump.cpp
index 717e757a1bba..8b1f67204c22 100644
--- a/tools/aapt2/cmd/Dump.cpp
+++ b/tools/aapt2/cmd/Dump.cpp
@@ -292,10 +292,6 @@ class DumpContext : public IAaptContext {
return 0;
}
- bool IsAutoNamespace() override {
- return false;
- }
-
private:
StdErrDiagnostics diagnostics_;
bool verbose_ = false;
diff --git a/tools/aapt2/cmd/Link.cpp b/tools/aapt2/cmd/Link.cpp
index 1d508d91f0fa..c94b8473ea87 100644
--- a/tools/aapt2/cmd/Link.cpp
+++ b/tools/aapt2/cmd/Link.cpp
@@ -137,14 +137,6 @@ class LinkContext : public IAaptContext {
min_sdk_version_ = minSdk;
}
- bool IsAutoNamespace() override {
- return auto_namespace_;
- }
-
- void SetAutoNamespace(bool val) {
- auto_namespace_ = val;
- }
-
private:
DISALLOW_COPY_AND_ASSIGN(LinkContext);
@@ -156,7 +148,6 @@ class LinkContext : public IAaptContext {
SymbolTable symbols_;
bool verbose_ = false;
int min_sdk_version_ = 0;
- bool auto_namespace_ = false;
};
// A custom delegate that generates compatible pre-O IDs for use with feature splits.
@@ -2042,15 +2033,6 @@ int LinkCommand::Action(const std::vector<std::string>& args) {
options_.output_format = OutputFormat::kProto;
}
- if (options_.auto_namespace_static_lib) {
- if (!static_lib_) {
- context.GetDiagnostics()->Error(
- DiagMessage() << "--auto-namespace-static-lib can only be used with --static-lib");
- return 1;
- }
- context.SetAutoNamespace(true);
- }
-
if (package_id_) {
if (context.GetPackageType() != PackageType::kApp) {
context.GetDiagnostics()->Error(
diff --git a/tools/aapt2/cmd/Link.h b/tools/aapt2/cmd/Link.h
index 434475ee1be5..fb8796ff0a5d 100644
--- a/tools/aapt2/cmd/Link.h
+++ b/tools/aapt2/cmd/Link.h
@@ -64,7 +64,6 @@ struct LinkOptions {
// Static lib options.
bool no_static_lib_packages = false;
- bool auto_namespace_static_lib = false;
// AndroidManifest.xml massaging options.
ManifestFixerOptions manifest_fixer_options;
@@ -188,10 +187,6 @@ class LinkCommand : public Command {
AddOptionalSwitch("--no-static-lib-packages",
"Merge all library resources under the app's package.",
&options_.no_static_lib_packages);
- AddOptionalSwitch("--auto-namespace-static-lib",
- "Automatically namespace resource references when building a static\n"
- "library.",
- &options_.auto_namespace_static_lib);
AddOptionalSwitch("--non-final-ids",
"Generates R.java without the final modifier. This is implied when\n"
"--static-lib is specified.",
diff --git a/tools/aapt2/cmd/Optimize.cpp b/tools/aapt2/cmd/Optimize.cpp
index b4cba8c2801c..47288ec092de 100644
--- a/tools/aapt2/cmd/Optimize.cpp
+++ b/tools/aapt2/cmd/Optimize.cpp
@@ -104,10 +104,6 @@ class OptimizeContext : public IAaptContext {
return sdk_version_;
}
- bool IsAutoNamespace() override {
- return false;
- }
-
private:
DISALLOW_COPY_AND_ASSIGN(OptimizeContext);
diff --git a/tools/aapt2/integration-tests/AutoNamespaceTest/Android.mk b/tools/aapt2/integration-tests/AutoNamespaceTest/Android.mk
deleted file mode 100644
index 5d7a6f7bedab..000000000000
--- a/tools/aapt2/integration-tests/AutoNamespaceTest/Android.mk
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# Copyright (C) 2018 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.
-#
-
-LOCAL_PATH := $(call my-dir)
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tools/aapt2/integration-tests/AutoNamespaceTest/LibOne/Android.mk b/tools/aapt2/integration-tests/AutoNamespaceTest/LibOne/Android.mk
deleted file mode 100644
index 91716b9870ea..000000000000
--- a/tools/aapt2/integration-tests/AutoNamespaceTest/LibOne/Android.mk
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-# Copyright (C) 2018 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.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-LOCAL_USE_AAPT2 := true
-LOCAL_MODULE := AaptTestAutoNamespace_LibOne
-LOCAL_MODULE_TAGS := tests
-LOCAL_SRC_FILES := $(call all-java-files-under,src)
-LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
-LOCAL_AAPT_NAMESPACES := true
-LOCAL_AAPT_FLAGS := --auto-namespace-static-lib
-# We need this to compile the Java sources of AaptTestStaticLib_LibTwo using javac.
-LOCAL_JAR_EXCLUDE_FILES := none
-include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/tools/aapt2/integration-tests/AutoNamespaceTest/LibOne/AndroidManifest.xml b/tools/aapt2/integration-tests/AutoNamespaceTest/LibOne/AndroidManifest.xml
deleted file mode 100644
index f585840cdb12..000000000000
--- a/tools/aapt2/integration-tests/AutoNamespaceTest/LibOne/AndroidManifest.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2018 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.
--->
-
-<manifest package="com.example.android.aapt2.autonamespace.staticlib.one" />
diff --git a/tools/aapt2/integration-tests/AutoNamespaceTest/LibOne/res/values/values.xml b/tools/aapt2/integration-tests/AutoNamespaceTest/LibOne/res/values/values.xml
deleted file mode 100644
index 3e57b0f20739..000000000000
--- a/tools/aapt2/integration-tests/AutoNamespaceTest/LibOne/res/values/values.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2018 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.
--->
-
-<resources>
- <!-- An attribute from StaticLibOne -->
- <attr name="StaticLibOne_attr" format="string" />
-
- <string name="Foo">Foo</string>
-
- <declare-styleable name="Widget">
- <attr name="StaticLibOne_attr" />
- <attr name="android:text" />
- </declare-styleable>
-</resources>
diff --git a/tools/aapt2/integration-tests/AutoNamespaceTest/LibOne/src/com/example/android/aapt2/autonamespace/staticlib/one/StaticLibOne.java b/tools/aapt2/integration-tests/AutoNamespaceTest/LibOne/src/com/example/android/aapt2/autonamespace/staticlib/one/StaticLibOne.java
deleted file mode 100644
index 886d48c7597c..000000000000
--- a/tools/aapt2/integration-tests/AutoNamespaceTest/LibOne/src/com/example/android/aapt2/autonamespace/staticlib/one/StaticLibOne.java
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright (C) 2018 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.
- */
-package com.example.android.aapt2.autonamespace.staticlib.one;
-
-public class StaticLibOne { public static int FooId = R.string.Foo; }
diff --git a/tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/Android.mk b/tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/Android.mk
deleted file mode 100644
index c85496d38fda..000000000000
--- a/tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/Android.mk
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-# Copyright (C) 2018 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.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-LOCAL_USE_AAPT2 := true
-LOCAL_MODULE := AaptTestAutoNamespace_LibTwo
-LOCAL_MODULE_TAGS := tests
-LOCAL_SRC_FILES := $(call all-java-files-under,src)
-LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
-LOCAL_SHARED_ANDROID_LIBRARIES := AaptTestAutoNamespace_LibOne
-LOCAL_AAPT_NAMESPACES := true
-LOCAL_AAPT_FLAGS := --auto-namespace-static-lib
-include $(BUILD_STATIC_JAVA_LIBRARY)
-
diff --git a/tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/AndroidManifest.xml b/tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/AndroidManifest.xml
deleted file mode 100644
index 8d3c506c5ac3..000000000000
--- a/tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/AndroidManifest.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2018 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.
--->
-
-<manifest package="com.example.android.aapt2.autonamespace.staticlib.two" />
diff --git a/tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/res/layout/layout_two.xml b/tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/res/layout/layout_two.xml
deleted file mode 100644
index fb202201a03a..000000000000
--- a/tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/res/layout/layout_two.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2018 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.
--->
-
-<View xmlns:custom="http://schemas.android.com/apk/res-auto"
- custom:StaticLibOne_attr="@string/FooBar" />
diff --git a/tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/res/values/values.xml b/tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/res/values/values.xml
deleted file mode 100644
index c532387ee961..000000000000
--- a/tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/res/values/values.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2018 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.
--->
-
-<resources>
- <string name="FooBar">@string/Foo</string>
-</resources>
diff --git a/tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/src/com/example/android/aapt2/autonamespace/staticlib/two/StaticLibTwo.java b/tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/src/com/example/android/aapt2/autonamespace/staticlib/two/StaticLibTwo.java
deleted file mode 100644
index 323f53ae907b..000000000000
--- a/tools/aapt2/integration-tests/AutoNamespaceTest/LibTwo/src/com/example/android/aapt2/autonamespace/staticlib/two/StaticLibTwo.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2018 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.
- */
-package com.example.android.aapt2.autonamespace.staticlib.two;
-
-public class StaticLibTwo {
- // IDs from StaticLibOne
- public static int FooId = com.example.android.aapt2.autonamespace.staticlib.one.R.string.Foo;
-
- // IDs from StaticLibTwo
- public static int FooBarId = R.string.FooBar;
- public static int LayoutId = R.layout.layout_two;
-}
diff --git a/tools/aapt2/link/ReferenceLinker.cpp b/tools/aapt2/link/ReferenceLinker.cpp
index 28e71cc24f79..3a5d5858254d 100644
--- a/tools/aapt2/link/ReferenceLinker.cpp
+++ b/tools/aapt2/link/ReferenceLinker.cpp
@@ -80,7 +80,7 @@ class ReferenceLinkerVisitor : public DescendingValueVisitor {
// Find the attribute in the symbol table and check if it is visible from this callsite.
const SymbolTable::Symbol* symbol = ReferenceLinker::ResolveAttributeCheckVisibility(
- transformed_reference, callsite_, symbols_, context_->IsAutoNamespace(), &err_str);
+ transformed_reference, callsite_, symbols_, &err_str);
if (symbol) {
// Assign our style key the correct ID. The ID may not exist.
entry.key.id = symbol->id;
@@ -202,18 +202,12 @@ bool IsSymbolVisible(const SymbolTable::Symbol& symbol, const Reference& ref,
const SymbolTable::Symbol* ReferenceLinker::ResolveSymbol(const Reference& reference,
const CallSite& callsite,
- SymbolTable* symbols,
- bool auto_namespace) {
+ SymbolTable* symbols) {
if (reference.name) {
const ResourceName& name = reference.name.value();
if (name.package.empty()) {
// Use the callsite's package name if no package name was defined.
- const SymbolTable::Symbol* local_symbol =
- symbols->FindByName(ResourceName(callsite.package, name.type, name.entry));
- if (!auto_namespace || local_symbol) {
- return local_symbol;
- }
- return symbols->FindByNameInAnyPackage(name);
+ return symbols->FindByName(ResourceName(callsite.package, name.type, name.entry));
}
return symbols->FindByName(name);
} else if (reference.id) {
@@ -226,9 +220,8 @@ const SymbolTable::Symbol* ReferenceLinker::ResolveSymbol(const Reference& refer
const SymbolTable::Symbol* ReferenceLinker::ResolveSymbolCheckVisibility(const Reference& reference,
const CallSite& callsite,
SymbolTable* symbols,
- bool auto_namespace,
std::string* out_error) {
- const SymbolTable::Symbol* symbol = ResolveSymbol(reference, callsite, symbols, auto_namespace);
+ const SymbolTable::Symbol* symbol = ResolveSymbol(reference, callsite, symbols);
if (!symbol) {
if (out_error) *out_error = "not found";
return nullptr;
@@ -242,10 +235,10 @@ const SymbolTable::Symbol* ReferenceLinker::ResolveSymbolCheckVisibility(const R
}
const SymbolTable::Symbol* ReferenceLinker::ResolveAttributeCheckVisibility(
- const Reference& reference, const CallSite& callsite, SymbolTable* symbols, bool auto_namespace,
+ const Reference& reference, const CallSite& callsite, SymbolTable* symbols,
std::string* out_error) {
const SymbolTable::Symbol* symbol =
- ResolveSymbolCheckVisibility(reference, callsite, symbols, auto_namespace, out_error);
+ ResolveSymbolCheckVisibility(reference, callsite, symbols, out_error);
if (!symbol) {
return nullptr;
}
@@ -260,10 +253,9 @@ const SymbolTable::Symbol* ReferenceLinker::ResolveAttributeCheckVisibility(
Maybe<xml::AaptAttribute> ReferenceLinker::CompileXmlAttribute(const Reference& reference,
const CallSite& callsite,
SymbolTable* symbols,
- bool auto_namespace,
std::string* out_error) {
const SymbolTable::Symbol* symbol =
- ResolveAttributeCheckVisibility(reference, callsite, symbols, auto_namespace, out_error);
+ ResolveAttributeCheckVisibility(reference, callsite, symbols, out_error);
if (!symbol) {
return {};
}
@@ -341,8 +333,8 @@ bool ReferenceLinker::LinkReference(const CallSite& callsite, Reference* referen
xml::ResolvePackage(decls, &transformed_reference);
std::string err_str;
- const SymbolTable::Symbol* s = ResolveSymbolCheckVisibility(
- transformed_reference, callsite, symbols, context->IsAutoNamespace(), &err_str);
+ const SymbolTable::Symbol* s =
+ ResolveSymbolCheckVisibility(transformed_reference, callsite, symbols, &err_str);
if (s) {
// The ID may not exist. This is fine because of the possibility of building
// against libraries without assigned IDs.
diff --git a/tools/aapt2/link/ReferenceLinker.h b/tools/aapt2/link/ReferenceLinker.h
index 7887915a7bb1..b0b49457e5dd 100644
--- a/tools/aapt2/link/ReferenceLinker.h
+++ b/tools/aapt2/link/ReferenceLinker.h
@@ -36,12 +36,10 @@ class ReferenceLinker : public IResourceTableConsumer {
ReferenceLinker() = default;
// Performs name mangling and looks up the resource in the symbol table. Uses the callsite's
- // package if the reference has no package name defined (implicit), or if auto_namespace is
- // set try looking in all avaliable packages for a symbol of that name.
+ // package if the reference has no package name defined (implicit).
// Returns nullptr if the symbol was not found.
static const SymbolTable::Symbol* ResolveSymbol(const Reference& reference,
- const CallSite& callsite, SymbolTable* symbols,
- bool auto_namespace);
+ const CallSite& callsite, SymbolTable* symbols);
// Performs name mangling and looks up the resource in the symbol table. If the symbol is not
// visible by the reference at the callsite, nullptr is returned.
@@ -49,7 +47,6 @@ class ReferenceLinker : public IResourceTableConsumer {
static const SymbolTable::Symbol* ResolveSymbolCheckVisibility(const Reference& reference,
const CallSite& callsite,
SymbolTable* symbols,
- bool auto_namespace,
std::string* out_error);
// Same as ResolveSymbolCheckVisibility(), but also makes sure the symbol is an attribute.
@@ -57,14 +54,13 @@ class ReferenceLinker : public IResourceTableConsumer {
static const SymbolTable::Symbol* ResolveAttributeCheckVisibility(const Reference& reference,
const CallSite& callsite,
SymbolTable* symbols,
- bool auto_namespace,
std::string* out_error);
// Resolves the attribute reference and returns an xml::AaptAttribute if successful.
// If resolution fails, outError holds the error message.
static Maybe<xml::AaptAttribute> CompileXmlAttribute(const Reference& reference,
const CallSite& callsite,
- SymbolTable* symbols, bool auto_namespace,
+ SymbolTable* symbols,
std::string* out_error);
// Writes the resource name to the DiagMessage, using the
diff --git a/tools/aapt2/link/ReferenceLinker_test.cpp b/tools/aapt2/link/ReferenceLinker_test.cpp
index 0b7b1ce03a52..be38b967c986 100644
--- a/tools/aapt2/link/ReferenceLinker_test.cpp
+++ b/tools/aapt2/link/ReferenceLinker_test.cpp
@@ -267,7 +267,7 @@ TEST(ReferenceLinkerTest, AppsWithSamePackageButDifferentIdAreVisibleNonPublic)
std::string error;
const CallSite call_site{"com.app.test"};
const SymbolTable::Symbol* symbol = ReferenceLinker::ResolveSymbolCheckVisibility(
- *test::BuildReference("com.app.test:string/foo"), call_site, &table, false, &error);
+ *test::BuildReference("com.app.test:string/foo"), call_site, &table, &error);
ASSERT_THAT(symbol, NotNull());
EXPECT_TRUE(error.empty());
}
@@ -285,13 +285,13 @@ TEST(ReferenceLinkerTest, AppsWithDifferentPackageCanNotUseEachOthersAttribute)
std::string error;
const CallSite call_site{"com.app.ext"};
- EXPECT_FALSE(ReferenceLinker::CompileXmlAttribute(*test::BuildReference("com.app.test:attr/foo"),
- call_site, &table, false, &error));
+ EXPECT_FALSE(ReferenceLinker::CompileXmlAttribute(
+ *test::BuildReference("com.app.test:attr/foo"), call_site, &table, &error));
EXPECT_FALSE(error.empty());
error = "";
ASSERT_TRUE(ReferenceLinker::CompileXmlAttribute(
- *test::BuildReference("com.app.test:attr/public_foo"), call_site, &table, false, &error));
+ *test::BuildReference("com.app.test:attr/public_foo"), call_site, &table, &error));
EXPECT_TRUE(error.empty());
}
@@ -303,74 +303,19 @@ TEST(ReferenceLinkerTest, ReferenceWithNoPackageUsesCallSitePackage) {
.AddSymbol("com.app.lib:string/foo", ResourceId(0x7f010001))
.Build());
- const SymbolTable::Symbol* s = ReferenceLinker::ResolveSymbol(
- *test::BuildReference("string/foo"), CallSite{"com.app.test"}, &table, false);
+ const SymbolTable::Symbol* s = ReferenceLinker::ResolveSymbol(*test::BuildReference("string/foo"),
+ CallSite{"com.app.test"}, &table);
ASSERT_THAT(s, NotNull());
EXPECT_THAT(s->id, Eq(make_value<ResourceId>(0x7f010000)));
s = ReferenceLinker::ResolveSymbol(*test::BuildReference("string/foo"), CallSite{"com.app.lib"},
- &table, false);
+ &table);
ASSERT_THAT(s, NotNull());
EXPECT_THAT(s->id, Eq(make_value<ResourceId>(0x7f010001)));
EXPECT_THAT(ReferenceLinker::ResolveSymbol(*test::BuildReference("string/foo"),
- CallSite{"com.app.bad"}, &table, false),
+ CallSite{"com.app.bad"}, &table),
IsNull());
}
-TEST(ReferenceLinkerTest, AutomaticNamespace) {
- NameMangler mangler(NameManglerPolicy{"com.example.thislib"});
- SymbolTable table(&mangler);
- table.AppendSource(
- test::StaticSymbolSourceBuilder()
- .AddSymbol("com.example.thislib:string/thislib_string", ResourceId(0x7f010006))
- .AddSymbol("com.example.thislib:string/explicit_override_string", ResourceId(0x7f010007))
- .Build());
- // Lib2 is higher priority than lib1
- table.AppendSource(
- test::StaticSymbolSourceBuilder()
- .AddSymbol("com.example.lib2:string/lib2_string", ResourceId(0x7f010003))
- .AddSymbol("com.example.lib2:string/explicit_override_string", ResourceId(0x7f010004))
- .AddSymbol("com.example.lib2:string/implicit_override_string", ResourceId(0x7f010005))
- .Build());
- table.AppendSource(
- test::StaticSymbolSourceBuilder()
- .AddSymbol("com.example.lib1:string/explicit_override_string", ResourceId(0x7f010001))
- .AddSymbol("com.example.lib1:string/implicit_override_string", ResourceId(0x7f010002))
- .Build());
-
- // Sanity test: Local references are still fine.
- const SymbolTable::Symbol* s =
- ReferenceLinker::ResolveSymbol(*test::BuildReference("string/thislib_string"),
- CallSite{"com.example.thislib"}, &table, true);
- ASSERT_THAT(s, NotNull());
- EXPECT_THAT(s->id, Eq(make_value<ResourceId>(0x7f010006)));
-
- // Local references are fine, even if clash with remote ones.
- s = ReferenceLinker::ResolveSymbol(*test::BuildReference("string/explicit_override_string"),
- CallSite{"com.example.thislib"}, &table, true);
- ASSERT_THAT(s, NotNull());
- EXPECT_THAT(s->id, Eq(make_value<ResourceId>(0x7f010007)));
-
- // An unqualified reference to lib2 is rewritten
- s = ReferenceLinker::ResolveSymbol(*test::BuildReference("string/lib2_string"),
- CallSite{"com.example.thislib"}, &table, true);
- ASSERT_THAT(s, NotNull());
- EXPECT_THAT(s->id, Eq(make_value<ResourceId>(0x7f010003)));
-
- // Qualified references are left alone.
- s = ReferenceLinker::ResolveSymbol(
- *test::BuildReference("com.example.lib2:string/explicit_override_string"),
- CallSite{"com.example.thislib"}, &table, true);
- ASSERT_THAT(s, NotNull());
- EXPECT_THAT(s->id, Eq(make_value<ResourceId>(0x7f010004)));
-
- // Implicit overrides respect priority ordering.
- s = ReferenceLinker::ResolveSymbol(*test::BuildReference("string/implicit_override_string"),
- CallSite{"com.example.thislib"}, &table, true);
- ASSERT_THAT(s, NotNull());
- EXPECT_THAT(s->id, Eq(make_value<ResourceId>(0x7f010005)));
-
- //
-}
} // namespace aapt
diff --git a/tools/aapt2/link/XmlReferenceLinker.cpp b/tools/aapt2/link/XmlReferenceLinker.cpp
index 420a1271479d..160ff925f6cc 100644
--- a/tools/aapt2/link/XmlReferenceLinker.cpp
+++ b/tools/aapt2/link/XmlReferenceLinker.cpp
@@ -97,8 +97,8 @@ class XmlVisitor : public xml::PackageAwareVisitor {
attr_ref.private_reference = maybe_package.value().private_namespace;
std::string err_str;
- attr.compiled_attribute = ReferenceLinker::CompileXmlAttribute(
- attr_ref, callsite_, symbols_, context_->IsAutoNamespace(), &err_str);
+ attr.compiled_attribute =
+ ReferenceLinker::CompileXmlAttribute(attr_ref, callsite_, symbols_, &err_str);
if (!attr.compiled_attribute) {
DiagMessage error_msg(source);
diff --git a/tools/aapt2/link/XmlReferenceLinker_test.cpp b/tools/aapt2/link/XmlReferenceLinker_test.cpp
index d321f8f76d87..ef99355e5b5f 100644
--- a/tools/aapt2/link/XmlReferenceLinker_test.cpp
+++ b/tools/aapt2/link/XmlReferenceLinker_test.cpp
@@ -18,7 +18,6 @@
#include "test/Test.h"
-using ::testing::Eq;
using ::testing::IsNull;
using ::testing::NotNull;
@@ -71,29 +70,12 @@ class XmlReferenceLinkerTest : public ::testing::Test {
.Build())
.AddPublicSymbol("com.app.test:attr/attr", ResourceId(0x7f010002),
test::AttributeBuilder().Build())
- .AddPublicSymbol("com.app.lib:string/lib_string", ResourceId(0x7f020003))
.Build())
.Build();
-
- auto_namespace_context_ =
- test::ContextBuilder()
- .SetCompilationPackage("com.app.test")
- .SetNameManglerPolicy(NameManglerPolicy{"com.app.test", {"com.android.support"}})
- .SetAutoNamespace(true)
- .AddSymbolSource(
- test::StaticSymbolSourceBuilder()
- .AddPublicSymbol("android:attr/text", ResourceId(0x01010003),
- test::AttributeBuilder()
- .SetTypeMask(android::ResTable_map::TYPE_STRING)
- .Build())
- .AddPublicSymbol("com.app.lib:string/lib_string", ResourceId(0x7f020003))
- .Build())
- .Build();
}
protected:
std::unique_ptr<IAaptContext> context_;
- std::unique_ptr<IAaptContext> auto_namespace_context_;
};
TEST_F(XmlReferenceLinkerTest, LinkBasicAttributes) {
@@ -213,31 +195,6 @@ TEST_F(XmlReferenceLinkerTest, LinkAutoResReference) {
EXPECT_EQ(make_value(ResourceId(0x7f020001)), ref->id);
}
-TEST_F(XmlReferenceLinkerTest, LinkAutoNamespaceResReference) {
- std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDomForPackageName(context_.get(), R"(
- <View
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:text="@string/lib_string" />)");
-
- XmlReferenceLinker linker;
- // Should not link with auto-namespace support disabled.
- ASSERT_FALSE(linker.Consume(context_.get(), doc.get()));
- // Should link with auto-namespace enabled.
- ASSERT_TRUE(linker.Consume(auto_namespace_context_.get(), doc.get()));
-
- xml::Element* view_el = doc->root.get();
- ASSERT_THAT(view_el, NotNull());
-
- xml::Attribute* xml_attr = view_el->FindAttribute(xml::kSchemaAndroid, "text");
- ASSERT_THAT(xml_attr, NotNull());
- ASSERT_TRUE(xml_attr->compiled_attribute);
- EXPECT_EQ(make_value(ResourceId(0x01010003)), xml_attr->compiled_attribute.value().id);
- Reference* ref = ValueCast<Reference>(xml_attr->compiled_value.get());
- ASSERT_THAT(ref, NotNull());
- ASSERT_TRUE(ref->name);
- EXPECT_EQ(make_value(ResourceId(0x7f020003)), ref->id);
-}
-
TEST_F(XmlReferenceLinkerTest, LinkViewWithShadowedPackageAlias) {
std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDomForPackageName(context_.get(), R"(
<View xmlns:app="http://schemas.android.com/apk/res/android" app:attr="@app:id/id">
diff --git a/tools/aapt2/optimize/MultiApkGenerator.cpp b/tools/aapt2/optimize/MultiApkGenerator.cpp
index a931343281bc..e92c121272eb 100644
--- a/tools/aapt2/optimize/MultiApkGenerator.cpp
+++ b/tools/aapt2/optimize/MultiApkGenerator.cpp
@@ -99,10 +99,6 @@ class ContextWrapper : public IAaptContext {
util::make_unique<SourcePathDiagnostics>(Source{source}, context_->GetDiagnostics());
}
- bool IsAutoNamespace() override {
- return context_->IsAutoNamespace();
- }
-
private:
IAaptContext* context_;
std::unique_ptr<SourcePathDiagnostics> source_diag_;
diff --git a/tools/aapt2/process/IResourceTableConsumer.h b/tools/aapt2/process/IResourceTableConsumer.h
index a3a7719bfe16..30dad8025900 100644
--- a/tools/aapt2/process/IResourceTableConsumer.h
+++ b/tools/aapt2/process/IResourceTableConsumer.h
@@ -50,7 +50,6 @@ struct IAaptContext {
virtual NameMangler* GetNameMangler() = 0;
virtual bool IsVerbose() = 0;
virtual int GetMinSdkVersion() = 0;
- virtual bool IsAutoNamespace() = 0;
};
struct IResourceTableConsumer {
diff --git a/tools/aapt2/process/SymbolTable.cpp b/tools/aapt2/process/SymbolTable.cpp
index ef2e448b68b8..fc4c9b537e73 100644
--- a/tools/aapt2/process/SymbolTable.cpp
+++ b/tools/aapt2/process/SymbolTable.cpp
@@ -114,16 +114,6 @@ const SymbolTable::Symbol* SymbolTable::FindByName(const ResourceName& name) {
return shared_symbol.get();
}
-const SymbolTable::Symbol* SymbolTable::FindByNameInAnyPackage(const ResourceName& name) {
- for (auto& source : sources_) {
- std::string package = source->GetPackageForSymbol(name);
- if (!package.empty()) {
- return FindByName(ResourceName(package, name.type, name.entry));
- }
- }
- return {};
-}
-
const SymbolTable::Symbol* SymbolTable::FindById(const ResourceId& id) {
if (const std::shared_ptr<Symbol>& s = id_cache_.get(id)) {
return s.get();
@@ -221,25 +211,6 @@ std::unique_ptr<SymbolTable::Symbol> ResourceTableSymbolSource::FindByName(
return symbol;
}
-std::string ResourceTableSymbolSource::GetPackageForSymbol(const ResourceName& name) {
- for (auto& package : table_->packages) {
- ResourceTableType* type = package->FindType(name.type);
- if (type == nullptr) {
- continue;
- }
- ResourceEntry* entry = type->FindEntry(name.entry);
- if (entry == nullptr) {
- continue;
- }
- return package->name;
- }
- if (name.type == ResourceType::kAttr) {
- // Recurse and try looking up a private attribute.
- return GetPackageForSymbol(ResourceName(name.package, ResourceType::kAttrPrivate, name.entry));
- }
- return {};
-}
-
bool AssetManagerSymbolSource::AddAssetPath(const StringPiece& path) {
int32_t cookie = 0;
return assets_.addAssetPath(android::String8(path.data(), path.size()), &cookie);
diff --git a/tools/aapt2/process/SymbolTable.h b/tools/aapt2/process/SymbolTable.h
index c798cbb8d8a2..51a2e373596a 100644
--- a/tools/aapt2/process/SymbolTable.h
+++ b/tools/aapt2/process/SymbolTable.h
@@ -89,13 +89,6 @@ class SymbolTable {
// results are stored in a cache which may evict entries on subsequent calls.
const Symbol* FindByName(const ResourceName& name);
- // Finds the symbol from any package, for use as part of automatic conversion to namespaces.
- // This returns the symbol from the highest priority package,
- // which mimics the behavior of the resource merger and overlays.
- // NOTE: Never hold on to the result between calls to FindByXXX. The
- // results are stored in a cache which may evict entries on subsequent calls.
- const Symbol* FindByNameInAnyPackage(const ResourceName& name);
-
// NOTE: Never hold on to the result between calls to FindByXXX. The
// results are stored in a cache which may evict entries on subsequent calls.
const Symbol* FindById(const ResourceId& id);
@@ -160,11 +153,6 @@ class ISymbolSource {
virtual std::unique_ptr<SymbolTable::Symbol> FindByName(
const ResourceName& name) = 0;
- // Finds the name of a symbol from any package,
- // for use as part of automatic conversion to namespaces.
- // This returns the symbol from the highest priority package,
- // which mimics the behavior of the resource merger and overlays.
- virtual std::string GetPackageForSymbol(const ResourceName& name) = 0;
virtual std::unique_ptr<SymbolTable::Symbol> FindById(ResourceId id) = 0;
// Default implementation tries the name if it exists, else the ID.
@@ -189,7 +177,6 @@ class ResourceTableSymbolSource : public ISymbolSource {
std::unique_ptr<SymbolTable::Symbol> FindByName(
const ResourceName& name) override;
- std::string GetPackageForSymbol(const ResourceName& name) override;
std::unique_ptr<SymbolTable::Symbol> FindById(ResourceId id) override {
return {};
}
@@ -210,9 +197,6 @@ class AssetManagerSymbolSource : public ISymbolSource {
std::unique_ptr<SymbolTable::Symbol> FindByName(
const ResourceName& name) override;
- std::string GetPackageForSymbol(const ResourceName& name) override {
- return {};
- }
std::unique_ptr<SymbolTable::Symbol> FindById(ResourceId id) override;
std::unique_ptr<SymbolTable::Symbol> FindByReference(
const Reference& ref) override;
diff --git a/tools/aapt2/process/SymbolTable_test.cpp b/tools/aapt2/process/SymbolTable_test.cpp
index df40b26a64f4..1f59d7034300 100644
--- a/tools/aapt2/process/SymbolTable_test.cpp
+++ b/tools/aapt2/process/SymbolTable_test.cpp
@@ -120,39 +120,4 @@ TEST(SymbolTableTest, FindByNameWhenSymbolIsMangledInResTable) {
EXPECT_THAT(symbol_table.FindByName(test::ParseNameOrDie("com.android.other:id/foo")), IsNull());
}
-TEST(SymbolTableTest, FindByNameInAnyPackage) {
- // This represents lib3 --depends-on--> lib2 --depends-on--> lib1
-
- NameMangler mangler(NameManglerPolicy{"com.example.lib3"});
- SymbolTable symbol_table(&mangler);
- // Lib2 has higher precedence than lib1, as it is closer to the current library (lib3)
- // in the dependency graph.
-
- symbol_table.AppendSource(test::StaticSymbolSourceBuilder()
- .AddPublicSymbol("com.example.lib1:string/foo", ResourceId())
- .AddSymbol("com.example.lib1:attr/foo", ResourceId(),
- test::AttributeBuilder()
- .SetTypeMask(android::ResTable_map::TYPE_FLAGS)
- .AddItem("one", 0x01)
- .AddItem("two", 0x02)
- .Build())
- .Build());
- symbol_table.PrependSource(test::StaticSymbolSourceBuilder()
- .AddPublicSymbol("com.example.lib2:string/foo", ResourceId())
- .Build());
-
- // Sanity test
- EXPECT_THAT(symbol_table.FindByName(test::ParseNameOrDie("string/foo")), IsNull());
-
- // Test public symbol resolution
- const SymbolTable::Symbol* const found_string =
- symbol_table.FindByNameInAnyPackage(test::ParseNameOrDie("string/foo"));
- ASSERT_THAT(found_string, NotNull());
-
- // Test attr resolution
- const SymbolTable::Symbol* const found_attr =
- symbol_table.FindByNameInAnyPackage(test::ParseNameOrDie("attr/foo"));
- ASSERT_THAT(found_attr, NotNull());
-}
-
} // namespace aapt
diff --git a/tools/aapt2/test/Context.h b/tools/aapt2/test/Context.h
index a07d79f01dfe..0564db063b9a 100644
--- a/tools/aapt2/test/Context.h
+++ b/tools/aapt2/test/Context.h
@@ -81,10 +81,6 @@ class Context : public IAaptContext {
return min_sdk_version_;
}
- bool IsAutoNamespace() override {
- return auto_namespace_;
- }
-
private:
DISALLOW_COPY_AND_ASSIGN(Context);
@@ -97,7 +93,6 @@ class Context : public IAaptContext {
NameMangler name_mangler_;
SymbolTable symbols_;
int min_sdk_version_;
- bool auto_namespace_;
};
class ContextBuilder {
@@ -132,11 +127,6 @@ class ContextBuilder {
return *this;
}
- ContextBuilder& SetAutoNamespace(bool auto_namespace) {
- context_->auto_namespace_ = auto_namespace;
- return *this;
- }
-
std::unique_ptr<Context> Build() { return std::move(context_); }
private:
@@ -182,15 +172,6 @@ class StaticSymbolSourceBuilder {
return nullptr;
}
- std::string GetPackageForSymbol(const ResourceName& name) override {
- for (auto const& imap : name_map_) {
- if (imap.first.type == name.type && imap.first.entry == name.entry) {
- return imap.first.package;
- }
- }
- return "";
- }
-
std::unique_ptr<SymbolTable::Symbol> FindById(ResourceId id) override {
auto iter = id_map_.find(id);
if (iter != id_map_.end()) {