diff options
author | Colin Cross <ccross@android.com> | 2017-11-22 16:19:37 -0800 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2017-11-29 05:05:07 +0000 |
commit | 3bc7ffa59b8277b3a36eb9e16192583b3b9a93ea (patch) | |
tree | 1a768f402d17a3181a18177e17935dbd1d3c60b2 /java/app_test.go | |
parent | 0875c52de753b858b74a9ac285626536bee9cb57 (diff) | |
download | android_build_soong-3bc7ffa59b8277b3a36eb9e16192583b3b9a93ea.tar.gz android_build_soong-3bc7ffa59b8277b3a36eb9e16192583b3b9a93ea.tar.bz2 android_build_soong-3bc7ffa59b8277b3a36eb9e16192583b3b9a93ea.zip |
Replace aapt support with aapt2
Use aapt2 instead of aapt to compile Android app resources.
Also generate all files into srcjars instead of individual
sources.
Test: m checkbuild
Change-Id: I5a67991a0daf0017e8159b46fcff7d5564a91468
Diffstat (limited to 'java/app_test.go')
-rw-r--r-- | java/app_test.go | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/java/app_test.go b/java/app_test.go new file mode 100644 index 00000000..0b1491e7 --- /dev/null +++ b/java/app_test.go @@ -0,0 +1,90 @@ +// Copyright 2017 Google Inc. All rights reserved. +// +// 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 java + +import ( + "android/soong/android" + "reflect" + "testing" +) + +var ( + resourceFiles = []string{ + "res/layout/layout.xml", + "res/values/strings.xml", + "res/values-en-rUS/strings.xml", + } + + compiledResourceFiles = []string{ + "aapt2/res/layout_layout.xml.flat", + "aapt2/res/values_strings.arsc.flat", + "aapt2/res/values-en-rUS_strings.arsc.flat", + } +) + +func testApp(t *testing.T, bp string) *android.TestContext { + bp += ` + android_app { + name: "framework-res", + no_framework_libs: true, + } + ` + + appFs := map[string][]byte{ + "AndroidManifest.xml": nil, + "build/target/product/security/testkey": nil, + } + + for _, file := range resourceFiles { + appFs[file] = nil + } + + return testJavaWithEnvFs(t, bp, nil, appFs) +} + +func TestApp(t *testing.T) { + ctx := testApp(t, ` + android_app { + name: "foo", + srcs: ["a.java"], + } + `) + + foo := ctx.ModuleForTests("foo", "android_common") + + expectedLinkImplicits := []string{"AndroidManifest.xml"} + + frameworkRes := ctx.ModuleForTests("framework-res", "android_common") + expectedLinkImplicits = append(expectedLinkImplicits, + frameworkRes.Output("package-res.apk").Output.String()) + + // Test the mapping from input files to compiled output file names + compile := foo.Output(compiledResourceFiles[0]) + if !reflect.DeepEqual(resourceFiles, compile.Inputs.Strings()) { + t.Errorf("expected aapt2 compile inputs expected:\n %#v\n got:\n %#v", + resourceFiles, compile.Inputs.Strings()) + } + expectedLinkImplicits = append(expectedLinkImplicits, compile.Outputs.Strings()...) + + list := foo.Output("aapt2/res.list") + expectedLinkImplicits = append(expectedLinkImplicits, list.Output.String()) + + // Check that the link rule uses + res := ctx.ModuleForTests("foo", "android_common").Output("package-res.apk") + if !reflect.DeepEqual(expectedLinkImplicits, res.Implicits.Strings()) { + t.Errorf("expected aapt2 link implicits expected:\n %#v\n got:\n %#v", + expectedLinkImplicits, res.Implicits.Strings()) + } +} |