2019-11-30 10:24:33 +01:00
|
|
|
// Copyright 2019 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 sdk
|
|
|
|
|
|
|
|
import (
|
2019-11-29 21:45:22 +01:00
|
|
|
"fmt"
|
2019-11-30 10:24:33 +01:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2019-11-29 21:45:22 +01:00
|
|
|
"path/filepath"
|
2019-11-30 10:24:33 +01:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/apex"
|
|
|
|
"android/soong/cc"
|
2021-03-05 00:02:31 +01:00
|
|
|
"android/soong/genrule"
|
2019-11-30 10:24:33 +01:00
|
|
|
"android/soong/java"
|
|
|
|
)
|
|
|
|
|
2020-07-11 05:33:29 +02:00
|
|
|
func testSdkContext(bp string, fs map[string][]byte, extraOsTypes []android.OsType) (*android.TestContext, android.Config) {
|
|
|
|
extraOsTypes = append(extraOsTypes, android.Android, android.Windows)
|
|
|
|
|
2019-12-14 05:41:13 +01:00
|
|
|
bp = bp + `
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "myapex.avbpubkey",
|
|
|
|
private_key: "myapex.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_app_certificate {
|
|
|
|
name: "myapex.cert",
|
|
|
|
certificate: "myapex",
|
|
|
|
}
|
2020-07-11 05:33:29 +02:00
|
|
|
` + cc.GatherRequiredDepsForTest(extraOsTypes...)
|
2019-12-14 05:41:13 +01:00
|
|
|
|
|
|
|
mockFS := map[string][]byte{
|
2020-07-07 04:22:21 +02:00
|
|
|
"build/make/target/product/security": nil,
|
|
|
|
"apex_manifest.json": nil,
|
|
|
|
"system/sepolicy/apex/myapex-file_contexts": nil,
|
|
|
|
"system/sepolicy/apex/myapex2-file_contexts": nil,
|
|
|
|
"system/sepolicy/apex/mysdkapex-file_contexts": nil,
|
|
|
|
"myapex.avbpubkey": nil,
|
|
|
|
"myapex.pem": nil,
|
|
|
|
"myapex.x509.pem": nil,
|
|
|
|
"myapex.pk8": nil,
|
2019-12-14 05:41:13 +01:00
|
|
|
}
|
|
|
|
|
2020-02-15 20:00:10 +01:00
|
|
|
cc.GatherRequiredFilesForTest(mockFS)
|
|
|
|
|
2019-12-14 05:41:13 +01:00
|
|
|
for k, v := range fs {
|
|
|
|
mockFS[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
config := android.TestArchConfig(buildDir, nil, bp, mockFS)
|
|
|
|
|
2020-02-27 14:12:46 +01:00
|
|
|
// Add windows as a default disable OS to test behavior when some OS variants
|
|
|
|
// are disabled.
|
|
|
|
config.Targets[android.Windows] = []android.Target{
|
2020-09-14 12:43:17 +02:00
|
|
|
{android.Windows, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", "", true},
|
2020-02-27 14:12:46 +01:00
|
|
|
}
|
|
|
|
|
2020-07-11 05:33:29 +02:00
|
|
|
for _, extraOsType := range extraOsTypes {
|
|
|
|
switch extraOsType {
|
|
|
|
case android.LinuxBionic:
|
|
|
|
config.Targets[android.LinuxBionic] = []android.Target{
|
2020-09-14 12:43:17 +02:00
|
|
|
{android.LinuxBionic, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", "", false},
|
2020-07-11 05:33:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-30 01:09:13 +01:00
|
|
|
ctx := android.NewTestArchContext(config)
|
2019-11-30 10:24:33 +01:00
|
|
|
|
2020-03-04 21:15:08 +01:00
|
|
|
// Enable androidmk support.
|
|
|
|
// * Register the singleton
|
|
|
|
// * Configure that we are inside make
|
|
|
|
// * Add CommonOS to ensure that androidmk processing works.
|
|
|
|
android.RegisterAndroidMkBuildComponents(ctx)
|
2020-11-23 06:22:30 +01:00
|
|
|
android.SetKatiEnabledForTests(config)
|
2020-03-04 21:15:08 +01:00
|
|
|
config.Targets[android.CommonOS] = []android.Target{
|
2020-09-14 12:43:17 +02:00
|
|
|
{android.CommonOS, android.Arch{ArchType: android.Common}, android.NativeBridgeDisabled, "", "", true},
|
2020-03-04 21:15:08 +01:00
|
|
|
}
|
|
|
|
|
2019-11-30 10:24:33 +01:00
|
|
|
// from android package
|
2020-01-14 13:15:29 +01:00
|
|
|
android.RegisterPackageBuildComponents(ctx)
|
2020-09-11 12:55:00 +02:00
|
|
|
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
2019-12-05 15:31:48 +01:00
|
|
|
ctx.PreArchMutators(android.RegisterVisibilityRuleChecker)
|
2019-11-30 10:24:33 +01:00
|
|
|
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
|
2020-06-26 21:17:02 +02:00
|
|
|
ctx.PreArchMutators(android.RegisterComponentsMutator)
|
2020-07-30 17:04:17 +02:00
|
|
|
|
|
|
|
android.RegisterPrebuiltMutators(ctx)
|
|
|
|
|
|
|
|
// Register these after the prebuilt mutators have been registered to match what
|
|
|
|
// happens at runtime.
|
2019-12-05 15:31:48 +01:00
|
|
|
ctx.PreArchMutators(android.RegisterVisibilityRuleGatherer)
|
|
|
|
ctx.PostDepsMutators(android.RegisterVisibilityRuleEnforcer)
|
|
|
|
|
2019-11-30 10:24:33 +01:00
|
|
|
// from java package
|
2021-01-20 18:13:52 +01:00
|
|
|
java.RegisterRequiredBuildComponentsForTest(ctx)
|
2019-11-30 10:24:33 +01:00
|
|
|
|
2021-03-05 00:02:31 +01:00
|
|
|
// from genrule package
|
|
|
|
genrule.RegisterGenruleBuildComponents(ctx)
|
|
|
|
|
2019-11-30 10:24:33 +01:00
|
|
|
// from cc package
|
2019-12-19 17:01:36 +01:00
|
|
|
cc.RegisterRequiredBuildComponentsForTest(ctx)
|
2019-11-30 10:24:33 +01:00
|
|
|
|
|
|
|
// from apex package
|
|
|
|
ctx.RegisterModuleType("apex", apex.BundleFactory)
|
|
|
|
ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
|
|
|
|
ctx.PostDepsMutators(apex.RegisterPostDepsMutators)
|
|
|
|
|
|
|
|
// from this package
|
2021-03-09 23:59:28 +01:00
|
|
|
registerModuleExportsBuildComponents(ctx)
|
|
|
|
registerSdkBuildComponents(ctx)
|
2019-11-30 10:24:33 +01:00
|
|
|
|
2020-10-30 01:09:13 +01:00
|
|
|
ctx.Register()
|
2019-11-30 10:24:33 +01:00
|
|
|
|
|
|
|
return ctx, config
|
|
|
|
}
|
|
|
|
|
2020-07-11 05:33:29 +02:00
|
|
|
func runTests(t *testing.T, ctx *android.TestContext, config android.Config) *testSdkResult {
|
2019-11-29 21:45:22 +01:00
|
|
|
t.Helper()
|
2019-12-05 15:31:48 +01:00
|
|
|
_, errs := ctx.ParseBlueprintsFiles(".")
|
2019-11-30 10:24:33 +01:00
|
|
|
android.FailIfErrored(t, errs)
|
|
|
|
_, errs = ctx.PrepareBuildActions(config)
|
|
|
|
android.FailIfErrored(t, errs)
|
2019-11-29 21:45:22 +01:00
|
|
|
return &testSdkResult{
|
2021-03-11 13:18:24 +01:00
|
|
|
TestHelper: android.TestHelper{T: t},
|
|
|
|
TestContext: ctx,
|
2019-11-29 21:45:22 +01:00
|
|
|
}
|
2019-11-30 10:24:33 +01:00
|
|
|
}
|
|
|
|
|
2020-07-11 05:33:29 +02:00
|
|
|
func testSdkWithFs(t *testing.T, bp string, fs map[string][]byte) *testSdkResult {
|
|
|
|
t.Helper()
|
|
|
|
ctx, config := testSdkContext(bp, fs, nil)
|
|
|
|
return runTests(t, ctx, config)
|
|
|
|
}
|
|
|
|
|
2019-11-30 10:24:33 +01:00
|
|
|
func testSdkError(t *testing.T, pattern, bp string) {
|
|
|
|
t.Helper()
|
2020-07-11 05:33:29 +02:00
|
|
|
ctx, config := testSdkContext(bp, nil, nil)
|
2019-11-30 10:24:33 +01:00
|
|
|
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
|
|
|
if len(errs) > 0 {
|
|
|
|
android.FailIfNoMatchingErrors(t, pattern, errs)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
_, errs = ctx.PrepareBuildActions(config)
|
|
|
|
if len(errs) > 0 {
|
|
|
|
android.FailIfNoMatchingErrors(t, pattern, errs)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ensureListContains(t *testing.T, result []string, expected string) {
|
|
|
|
t.Helper()
|
|
|
|
if !android.InList(expected, result) {
|
|
|
|
t.Errorf("%q is not found in %v", expected, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func pathsToStrings(paths android.Paths) []string {
|
|
|
|
var ret []string
|
|
|
|
for _, p := range paths {
|
|
|
|
ret = append(ret, p.String())
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2019-11-29 21:45:22 +01:00
|
|
|
// Encapsulates result of processing an SDK definition. Provides support for
|
|
|
|
// checking the state of the build structures.
|
|
|
|
type testSdkResult struct {
|
2021-03-10 10:15:22 +01:00
|
|
|
android.TestHelper
|
2021-03-11 13:18:24 +01:00
|
|
|
*android.TestContext
|
2019-11-29 21:45:22 +01:00
|
|
|
}
|
|
|
|
|
2021-03-11 13:32:12 +01:00
|
|
|
func (result *testSdkResult) Module(name string, variant string) android.Module {
|
|
|
|
return result.ModuleForTests(name, variant).Module()
|
|
|
|
}
|
|
|
|
|
2019-11-29 21:45:22 +01:00
|
|
|
// Analyse the sdk build rules to extract information about what it is doing.
|
|
|
|
|
|
|
|
// e.g. find the src/dest pairs from each cp command, the various zip files
|
|
|
|
// generated, etc.
|
2021-03-11 13:32:12 +01:00
|
|
|
func getSdkSnapshotBuildInfo(result *testSdkResult, sdk *sdk) *snapshotBuildInfo {
|
2019-11-29 21:45:22 +01:00
|
|
|
info := &snapshotBuildInfo{
|
2021-03-11 13:32:12 +01:00
|
|
|
r: result,
|
2021-02-17 12:23:00 +01:00
|
|
|
androidBpContents: sdk.GetAndroidBpContentsForTests(),
|
|
|
|
androidUnversionedBpContents: sdk.GetUnversionedAndroidBpContentsForTests(),
|
|
|
|
androidVersionedBpContents: sdk.GetVersionedAndroidBpContentsForTests(),
|
2019-11-30 10:24:33 +01:00
|
|
|
}
|
2019-11-29 21:45:22 +01:00
|
|
|
|
|
|
|
buildParams := sdk.BuildParamsForTests()
|
|
|
|
copyRules := &strings.Builder{}
|
2020-02-27 14:45:35 +01:00
|
|
|
otherCopyRules := &strings.Builder{}
|
2020-03-03 17:01:26 +01:00
|
|
|
snapshotDirPrefix := sdk.builderForTests.snapshotDir.String() + "/"
|
2019-11-29 21:45:22 +01:00
|
|
|
for _, bp := range buildParams {
|
|
|
|
switch bp.Rule.String() {
|
|
|
|
case android.Cp.String():
|
2020-03-03 17:01:26 +01:00
|
|
|
output := bp.Output
|
2020-02-27 14:45:35 +01:00
|
|
|
// Get destination relative to the snapshot root
|
|
|
|
dest := output.Rel()
|
|
|
|
src := android.NormalizePathForTesting(bp.Input)
|
|
|
|
// We differentiate between copy rules for the snapshot, and copy rules for the install file.
|
2020-03-03 17:01:26 +01:00
|
|
|
if strings.HasPrefix(output.String(), snapshotDirPrefix) {
|
|
|
|
// Get source relative to build directory.
|
|
|
|
_, _ = fmt.Fprintf(copyRules, "%s -> %s\n", src, dest)
|
|
|
|
info.snapshotContents = append(info.snapshotContents, dest)
|
2020-02-27 14:45:35 +01:00
|
|
|
} else {
|
|
|
|
_, _ = fmt.Fprintf(otherCopyRules, "%s -> %s\n", src, dest)
|
2020-03-03 17:01:26 +01:00
|
|
|
}
|
2019-11-29 21:45:22 +01:00
|
|
|
|
|
|
|
case repackageZip.String():
|
|
|
|
// Add the destdir to the snapshot contents as that is effectively where
|
|
|
|
// the content of the repackaged zip is copied.
|
|
|
|
dest := bp.Args["destdir"]
|
|
|
|
info.snapshotContents = append(info.snapshotContents, dest)
|
|
|
|
|
|
|
|
case zipFiles.String():
|
|
|
|
// This could be an intermediate zip file and not the actual output zip.
|
|
|
|
// In that case this will be overridden when the rule to merge the zips
|
|
|
|
// is processed.
|
2019-12-10 14:41:51 +01:00
|
|
|
info.outputZip = android.NormalizePathForTesting(bp.Output)
|
2019-11-29 21:45:22 +01:00
|
|
|
|
|
|
|
case mergeZips.String():
|
|
|
|
// Copy the current outputZip to the intermediateZip.
|
|
|
|
info.intermediateZip = info.outputZip
|
2019-12-10 14:41:51 +01:00
|
|
|
mergeInput := android.NormalizePathForTesting(bp.Input)
|
2019-11-29 21:45:22 +01:00
|
|
|
if info.intermediateZip != mergeInput {
|
2021-03-11 13:32:12 +01:00
|
|
|
result.Errorf("Expected intermediate zip %s to be an input to merge zips but found %s instead",
|
2019-11-29 21:45:22 +01:00
|
|
|
info.intermediateZip, mergeInput)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Override output zip (which was actually the intermediate zip file) with the actual
|
|
|
|
// output zip.
|
2019-12-10 14:41:51 +01:00
|
|
|
info.outputZip = android.NormalizePathForTesting(bp.Output)
|
2019-11-29 21:45:22 +01:00
|
|
|
|
|
|
|
// Save the zips to be merged into the intermediate zip.
|
2019-12-10 14:41:51 +01:00
|
|
|
info.mergeZips = android.NormalizePathsForTesting(bp.Inputs)
|
2019-11-29 21:45:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
info.copyRules = copyRules.String()
|
2020-02-27 14:45:35 +01:00
|
|
|
info.otherCopyRules = otherCopyRules.String()
|
2019-11-29 21:45:22 +01:00
|
|
|
|
|
|
|
return info
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the snapshot build rules.
|
|
|
|
//
|
|
|
|
// Takes a list of functions which check different facets of the snapshot build rules.
|
|
|
|
// Allows each test to customize what is checked without duplicating lots of code
|
|
|
|
// or proliferating check methods of different flavors.
|
2021-03-11 13:32:12 +01:00
|
|
|
func CheckSnapshot(result *testSdkResult, name string, dir string, checkers ...snapshotBuildInfoChecker) {
|
|
|
|
result.Helper()
|
2019-11-29 21:45:22 +01:00
|
|
|
|
2020-02-25 20:26:33 +01:00
|
|
|
// The sdk CommonOS variant is always responsible for generating the snapshot.
|
|
|
|
variant := android.CommonOS.Name
|
|
|
|
|
2021-03-11 13:32:12 +01:00
|
|
|
sdk := result.Module(name, variant).(*sdk)
|
2019-11-29 21:45:22 +01:00
|
|
|
|
2021-03-11 13:32:12 +01:00
|
|
|
snapshotBuildInfo := getSdkSnapshotBuildInfo(result, sdk)
|
2019-11-29 21:45:22 +01:00
|
|
|
|
|
|
|
// Check state of the snapshot build.
|
|
|
|
for _, checker := range checkers {
|
|
|
|
checker(snapshotBuildInfo)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that the generated zip file is in the correct place.
|
|
|
|
actual := snapshotBuildInfo.outputZip
|
2019-12-05 15:31:48 +01:00
|
|
|
if dir != "" {
|
|
|
|
dir = filepath.Clean(dir) + "/"
|
|
|
|
}
|
2021-03-11 13:32:12 +01:00
|
|
|
result.AssertStringEquals("Snapshot zip file in wrong place",
|
2019-12-05 15:31:48 +01:00
|
|
|
fmt.Sprintf(".intermediates/%s%s/%s/%s-current.zip", dir, name, variant, name), actual)
|
2019-11-29 21:45:22 +01:00
|
|
|
|
|
|
|
// Populate a mock filesystem with the files that would have been copied by
|
|
|
|
// the rules.
|
|
|
|
fs := make(map[string][]byte)
|
|
|
|
for _, dest := range snapshotBuildInfo.snapshotContents {
|
|
|
|
fs[dest] = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process the generated bp file to make sure it is valid.
|
2021-03-11 13:32:12 +01:00
|
|
|
testSdkWithFs(result.T, snapshotBuildInfo.androidBpContents, fs)
|
2019-11-29 21:45:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type snapshotBuildInfoChecker func(info *snapshotBuildInfo)
|
|
|
|
|
|
|
|
// Check that the snapshot's generated Android.bp is correct.
|
|
|
|
//
|
|
|
|
// Both the expected and actual string are both trimmed before comparing.
|
|
|
|
func checkAndroidBpContents(expected string) snapshotBuildInfoChecker {
|
|
|
|
return func(info *snapshotBuildInfo) {
|
2021-03-10 10:15:22 +01:00
|
|
|
info.r.Helper()
|
2019-11-29 21:45:22 +01:00
|
|
|
info.r.AssertTrimmedStringEquals("Android.bp contents do not match", expected, info.androidBpContents)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-17 12:23:00 +01:00
|
|
|
// Check that the snapshot's unversioned generated Android.bp is correct.
|
|
|
|
//
|
|
|
|
// This func should be used to check the general snapshot generation code.
|
|
|
|
//
|
|
|
|
// Both the expected and actual string are both trimmed before comparing.
|
|
|
|
func checkUnversionedAndroidBpContents(expected string) snapshotBuildInfoChecker {
|
|
|
|
return func(info *snapshotBuildInfo) {
|
2021-03-10 10:15:22 +01:00
|
|
|
info.r.Helper()
|
2021-02-17 12:23:00 +01:00
|
|
|
info.r.AssertTrimmedStringEquals("unversioned Android.bp contents do not match", expected, info.androidUnversionedBpContents)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the snapshot's versioned generated Android.bp is correct.
|
|
|
|
//
|
|
|
|
// This func should only be used to check the version specific snapshot generation code,
|
|
|
|
// i.e. the encoding of version into module names and the generation of the _snapshot module. The
|
|
|
|
// general snapshot generation code should be checked using the checkUnversionedAndroidBpContents()
|
|
|
|
// func.
|
|
|
|
//
|
|
|
|
// Both the expected and actual string are both trimmed before comparing.
|
|
|
|
func checkVersionedAndroidBpContents(expected string) snapshotBuildInfoChecker {
|
|
|
|
return func(info *snapshotBuildInfo) {
|
2021-03-10 10:15:22 +01:00
|
|
|
info.r.Helper()
|
2021-02-17 12:23:00 +01:00
|
|
|
info.r.AssertTrimmedStringEquals("versioned Android.bp contents do not match", expected, info.androidVersionedBpContents)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-29 21:45:22 +01:00
|
|
|
// Check that the snapshot's copy rules are correct.
|
|
|
|
//
|
|
|
|
// The copy rules are formatted as <src> -> <dest>, one per line and then compared
|
|
|
|
// to the supplied expected string. Both the expected and actual string are trimmed
|
|
|
|
// before comparing.
|
|
|
|
func checkAllCopyRules(expected string) snapshotBuildInfoChecker {
|
|
|
|
return func(info *snapshotBuildInfo) {
|
2021-03-10 10:15:22 +01:00
|
|
|
info.r.Helper()
|
2019-11-29 21:45:22 +01:00
|
|
|
info.r.AssertTrimmedStringEquals("Incorrect copy rules", expected, info.copyRules)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:45:35 +01:00
|
|
|
func checkAllOtherCopyRules(expected string) snapshotBuildInfoChecker {
|
|
|
|
return func(info *snapshotBuildInfo) {
|
2021-03-10 10:15:22 +01:00
|
|
|
info.r.Helper()
|
2020-02-27 14:45:35 +01:00
|
|
|
info.r.AssertTrimmedStringEquals("Incorrect copy rules", expected, info.otherCopyRules)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-09 01:10:17 +02:00
|
|
|
// Check that the specified paths match the list of zips to merge with the intermediate zip.
|
|
|
|
func checkMergeZips(expected ...string) snapshotBuildInfoChecker {
|
2019-11-29 21:45:22 +01:00
|
|
|
return func(info *snapshotBuildInfo) {
|
2021-03-10 10:15:22 +01:00
|
|
|
info.r.Helper()
|
2019-11-29 21:45:22 +01:00
|
|
|
if info.intermediateZip == "" {
|
2021-03-10 10:15:22 +01:00
|
|
|
info.r.Errorf("No intermediate zip file was created")
|
2019-11-29 21:45:22 +01:00
|
|
|
}
|
2020-04-09 01:10:17 +02:00
|
|
|
|
|
|
|
info.r.AssertDeepEquals("mismatching merge zip files", expected, info.mergeZips)
|
2019-11-29 21:45:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encapsulates information about the snapshot build structure in order to insulate tests from
|
|
|
|
// knowing too much about internal structures.
|
|
|
|
//
|
|
|
|
// All source/input paths are relative either the build directory. All dest/output paths are
|
|
|
|
// relative to the snapshot root directory.
|
|
|
|
type snapshotBuildInfo struct {
|
|
|
|
r *testSdkResult
|
|
|
|
|
|
|
|
// The contents of the generated Android.bp file
|
|
|
|
androidBpContents string
|
|
|
|
|
2021-02-17 12:23:00 +01:00
|
|
|
// The contents of the unversioned Android.bp file
|
|
|
|
androidUnversionedBpContents string
|
|
|
|
|
|
|
|
// The contents of the versioned Android.bp file
|
|
|
|
androidVersionedBpContents string
|
|
|
|
|
2019-11-29 21:45:22 +01:00
|
|
|
// The paths, relative to the snapshot root, of all files and directories copied into the
|
|
|
|
// snapshot.
|
|
|
|
snapshotContents []string
|
|
|
|
|
2020-02-27 14:45:35 +01:00
|
|
|
// A formatted representation of the src/dest pairs for a snapshot, one pair per line,
|
|
|
|
// of the format src -> dest
|
2019-11-29 21:45:22 +01:00
|
|
|
copyRules string
|
|
|
|
|
2020-02-27 14:45:35 +01:00
|
|
|
// A formatted representation of the src/dest pairs for files not in a snapshot, one pair
|
|
|
|
// per line, of the format src -> dest
|
|
|
|
otherCopyRules string
|
|
|
|
|
2019-11-29 21:45:22 +01:00
|
|
|
// The path to the intermediate zip, which is a zip created from the source files copied
|
|
|
|
// into the snapshot directory and which will be merged with other zips to form the final output.
|
|
|
|
// Is am empty string if there is no intermediate zip because there are no zips to merge in.
|
|
|
|
intermediateZip string
|
|
|
|
|
|
|
|
// The paths to the zips to merge into the output zip, does not include the intermediate
|
|
|
|
// zip.
|
|
|
|
mergeZips []string
|
|
|
|
|
|
|
|
// The final output zip.
|
|
|
|
outputZip string
|
2019-11-30 10:24:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var buildDir string
|
|
|
|
|
|
|
|
func setUp() {
|
|
|
|
var err error
|
|
|
|
buildDir, err = ioutil.TempDir("", "soong_sdk_test")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func tearDown() {
|
|
|
|
_ = os.RemoveAll(buildDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
func runTestWithBuildDir(m *testing.M) {
|
|
|
|
run := func() int {
|
|
|
|
setUp()
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
return m.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Exit(run())
|
|
|
|
}
|