Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 1 | // Copyright 2019 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package sdk |
| 16 | |
| 17 | import ( |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 18 | "fmt" |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 19 | "path/filepath" |
Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 20 | "strings" |
| 21 | "testing" |
| 22 | |
| 23 | "android/soong/android" |
| 24 | "android/soong/apex" |
| 25 | "android/soong/cc" |
Paul Duffin | d6ceb86 | 2021-03-04 23:02:31 +0000 | [diff] [blame] | 26 | "android/soong/genrule" |
Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 27 | "android/soong/java" |
| 28 | ) |
| 29 | |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 30 | var prepareForSdkTest = android.GroupFixturePreparers( |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 31 | apex.PrepareForTestWithApexBuildComponents, |
| 32 | cc.PrepareForTestWithCcDefaultModules, |
| 33 | genrule.PrepareForTestWithGenRuleBuildComponents, |
| 34 | java.PrepareForTestWithJavaBuildComponents, |
| 35 | PrepareForTestWithSdkBuildComponents, |
Martin Stjernholm | 7feceb2 | 2020-07-11 04:33:29 +0100 | [diff] [blame] | 36 | |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 37 | android.FixtureAddTextFile("sdk/tests/Android.bp", ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 38 | apex_key { |
| 39 | name: "myapex.key", |
| 40 | public_key: "myapex.avbpubkey", |
| 41 | private_key: "myapex.pem", |
| 42 | } |
| 43 | |
| 44 | android_app_certificate { |
| 45 | name: "myapex.cert", |
| 46 | certificate: "myapex", |
| 47 | } |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 48 | `), |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 49 | |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 50 | android.FixtureMergeMockFs(map[string][]byte{ |
Martin Stjernholm | cc77601 | 2020-07-07 03:22:21 +0100 | [diff] [blame] | 51 | "build/make/target/product/security": nil, |
| 52 | "apex_manifest.json": nil, |
| 53 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 54 | "system/sepolicy/apex/myapex2-file_contexts": nil, |
| 55 | "system/sepolicy/apex/mysdkapex-file_contexts": nil, |
| 56 | "myapex.avbpubkey": nil, |
| 57 | "myapex.pem": nil, |
| 58 | "myapex.x509.pem": nil, |
| 59 | "myapex.pk8": nil, |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 60 | }), |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 61 | |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 62 | cc.PrepareForTestOnWindows, |
| 63 | android.FixtureModifyConfig(func(config android.Config) { |
| 64 | // Add windows as a default disable OS to test behavior when some OS variants |
| 65 | // are disabled. |
| 66 | config.Targets[android.Windows] = []android.Target{ |
| 67 | {android.Windows, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", "", true}, |
Martin Stjernholm | 7feceb2 | 2020-07-11 04:33:29 +0100 | [diff] [blame] | 68 | } |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 69 | }), |
| 70 | ) |
Martin Stjernholm | 7feceb2 | 2020-07-11 04:33:29 +0100 | [diff] [blame] | 71 | |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 72 | var PrepareForTestWithSdkBuildComponents = android.GroupFixturePreparers( |
| 73 | android.FixtureRegisterWithContext(registerModuleExportsBuildComponents), |
| 74 | android.FixtureRegisterWithContext(registerSdkBuildComponents), |
| 75 | ) |
Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 76 | |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 77 | func testSdkWithFs(t *testing.T, bp string, fs android.MockFS) *android.TestResult { |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 78 | t.Helper() |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 79 | return prepareForSdkTest.RunTest(t, fs.AddToFixture(), android.FixtureWithRootAndroidBp(bp)) |
Martin Stjernholm | 7feceb2 | 2020-07-11 04:33:29 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 82 | func testSdkError(t *testing.T, pattern, bp string) { |
| 83 | t.Helper() |
Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 84 | prepareForSdkTest. |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 85 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). |
| 86 | RunTestWithBp(t, bp) |
Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | func ensureListContains(t *testing.T, result []string, expected string) { |
| 90 | t.Helper() |
| 91 | if !android.InList(expected, result) { |
| 92 | t.Errorf("%q is not found in %v", expected, result) |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | func pathsToStrings(paths android.Paths) []string { |
| 97 | var ret []string |
| 98 | for _, p := range paths { |
| 99 | ret = append(ret, p.String()) |
| 100 | } |
| 101 | return ret |
| 102 | } |
| 103 | |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 104 | // Analyse the sdk build rules to extract information about what it is doing. |
Paul Duffin | fe9a9e3 | 2021-03-11 17:41:01 +0000 | [diff] [blame] | 105 | // |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 106 | // e.g. find the src/dest pairs from each cp command, the various zip files |
| 107 | // generated, etc. |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 108 | func getSdkSnapshotBuildInfo(t *testing.T, result *android.TestResult, sdk *sdk) *snapshotBuildInfo { |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 109 | info := &snapshotBuildInfo{ |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 110 | t: t, |
Paul Duffin | 981b94b | 2021-03-11 12:32:12 +0000 | [diff] [blame] | 111 | r: result, |
Paul Duffin | d075907 | 2021-02-17 11:23:00 +0000 | [diff] [blame] | 112 | androidBpContents: sdk.GetAndroidBpContentsForTests(), |
| 113 | androidUnversionedBpContents: sdk.GetUnversionedAndroidBpContentsForTests(), |
| 114 | androidVersionedBpContents: sdk.GetVersionedAndroidBpContentsForTests(), |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | buildParams := sdk.BuildParamsForTests() |
| 118 | copyRules := &strings.Builder{} |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 119 | otherCopyRules := &strings.Builder{} |
Paul Duffin | e1ddcc9 | 2020-03-03 16:01:26 +0000 | [diff] [blame] | 120 | snapshotDirPrefix := sdk.builderForTests.snapshotDir.String() + "/" |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 121 | for _, bp := range buildParams { |
| 122 | switch bp.Rule.String() { |
| 123 | case android.Cp.String(): |
Paul Duffin | e1ddcc9 | 2020-03-03 16:01:26 +0000 | [diff] [blame] | 124 | output := bp.Output |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 125 | // Get destination relative to the snapshot root |
| 126 | dest := output.Rel() |
| 127 | src := android.NormalizePathForTesting(bp.Input) |
| 128 | // We differentiate between copy rules for the snapshot, and copy rules for the install file. |
Paul Duffin | e1ddcc9 | 2020-03-03 16:01:26 +0000 | [diff] [blame] | 129 | if strings.HasPrefix(output.String(), snapshotDirPrefix) { |
| 130 | // Get source relative to build directory. |
Paul Duffin | e1ddcc9 | 2020-03-03 16:01:26 +0000 | [diff] [blame] | 131 | _, _ = fmt.Fprintf(copyRules, "%s -> %s\n", src, dest) |
| 132 | info.snapshotContents = append(info.snapshotContents, dest) |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 133 | } else { |
| 134 | _, _ = fmt.Fprintf(otherCopyRules, "%s -> %s\n", src, dest) |
Paul Duffin | e1ddcc9 | 2020-03-03 16:01:26 +0000 | [diff] [blame] | 135 | } |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 136 | |
| 137 | case repackageZip.String(): |
| 138 | // Add the destdir to the snapshot contents as that is effectively where |
| 139 | // the content of the repackaged zip is copied. |
| 140 | dest := bp.Args["destdir"] |
| 141 | info.snapshotContents = append(info.snapshotContents, dest) |
| 142 | |
| 143 | case zipFiles.String(): |
| 144 | // This could be an intermediate zip file and not the actual output zip. |
| 145 | // In that case this will be overridden when the rule to merge the zips |
| 146 | // is processed. |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 147 | info.outputZip = android.NormalizePathForTesting(bp.Output) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 148 | |
| 149 | case mergeZips.String(): |
| 150 | // Copy the current outputZip to the intermediateZip. |
| 151 | info.intermediateZip = info.outputZip |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 152 | mergeInput := android.NormalizePathForTesting(bp.Input) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 153 | if info.intermediateZip != mergeInput { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 154 | t.Errorf("Expected intermediate zip %s to be an input to merge zips but found %s instead", |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 155 | info.intermediateZip, mergeInput) |
| 156 | } |
| 157 | |
| 158 | // Override output zip (which was actually the intermediate zip file) with the actual |
| 159 | // output zip. |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 160 | info.outputZip = android.NormalizePathForTesting(bp.Output) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 161 | |
| 162 | // Save the zips to be merged into the intermediate zip. |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 163 | info.mergeZips = android.NormalizePathsForTesting(bp.Inputs) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
| 167 | info.copyRules = copyRules.String() |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 168 | info.otherCopyRules = otherCopyRules.String() |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 169 | |
| 170 | return info |
| 171 | } |
| 172 | |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 173 | // Check the snapshot build rules. |
| 174 | // |
| 175 | // Takes a list of functions which check different facets of the snapshot build rules. |
| 176 | // Allows each test to customize what is checked without duplicating lots of code |
| 177 | // or proliferating check methods of different flavors. |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 178 | func CheckSnapshot(t *testing.T, result *android.TestResult, name string, dir string, checkers ...snapshotBuildInfoChecker) { |
| 179 | t.Helper() |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 180 | |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 181 | // The sdk CommonOS variant is always responsible for generating the snapshot. |
| 182 | variant := android.CommonOS.Name |
| 183 | |
Paul Duffin | 981b94b | 2021-03-11 12:32:12 +0000 | [diff] [blame] | 184 | sdk := result.Module(name, variant).(*sdk) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 185 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 186 | snapshotBuildInfo := getSdkSnapshotBuildInfo(t, result, sdk) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 187 | |
| 188 | // Check state of the snapshot build. |
| 189 | for _, checker := range checkers { |
| 190 | checker(snapshotBuildInfo) |
| 191 | } |
| 192 | |
| 193 | // Make sure that the generated zip file is in the correct place. |
| 194 | actual := snapshotBuildInfo.outputZip |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 195 | if dir != "" { |
| 196 | dir = filepath.Clean(dir) + "/" |
| 197 | } |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 198 | android.AssertStringEquals(t, "Snapshot zip file in wrong place", |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 199 | fmt.Sprintf(".intermediates/%s%s/%s/%s-current.zip", dir, name, variant, name), actual) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 200 | |
| 201 | // Populate a mock filesystem with the files that would have been copied by |
| 202 | // the rules. |
Paul Duffin | c93c98e | 2021-03-20 01:32:50 +0000 | [diff] [blame^] | 203 | fs := android.MockFS{} |
| 204 | snapshotSubDir := "snapshot" |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 205 | for _, dest := range snapshotBuildInfo.snapshotContents { |
Paul Duffin | c93c98e | 2021-03-20 01:32:50 +0000 | [diff] [blame^] | 206 | fs[filepath.Join(snapshotSubDir, dest)] = nil |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 207 | } |
Paul Duffin | c93c98e | 2021-03-20 01:32:50 +0000 | [diff] [blame^] | 208 | fs[filepath.Join(snapshotSubDir, "Android.bp")] = []byte(snapshotBuildInfo.androidBpContents) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 209 | |
Paul Duffin | c93c98e | 2021-03-20 01:32:50 +0000 | [diff] [blame^] | 210 | preparer := result.Preparer() |
| 211 | |
| 212 | // Process the generated bp file to make sure it is valid. Use the same preparer as was used to |
| 213 | // produce this result. |
| 214 | t.Run("snapshot without source", func(t *testing.T) { |
| 215 | android.GroupFixturePreparers( |
| 216 | preparer, |
| 217 | // TODO(b/183184375): Set Config.TestAllowNonExistentPaths = false to verify that all the |
| 218 | // files the snapshot needs are actually copied into the snapshot. |
| 219 | |
| 220 | // Add the files (including bp) created for this snapshot to the test fixture. |
| 221 | fs.AddToFixture(), |
| 222 | |
| 223 | // Remove the source Android.bp file to make sure it works without. |
| 224 | // TODO(b/183184375): Add a test with the source. |
| 225 | android.FixtureModifyMockFS(func(fs android.MockFS) { |
| 226 | delete(fs, "Android.bp") |
| 227 | }), |
| 228 | ).RunTest(t) |
| 229 | }) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | type snapshotBuildInfoChecker func(info *snapshotBuildInfo) |
| 233 | |
| 234 | // Check that the snapshot's generated Android.bp is correct. |
| 235 | // |
| 236 | // Both the expected and actual string are both trimmed before comparing. |
| 237 | func checkAndroidBpContents(expected string) snapshotBuildInfoChecker { |
| 238 | return func(info *snapshotBuildInfo) { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 239 | info.t.Helper() |
| 240 | android.AssertTrimmedStringEquals(info.t, "Android.bp contents do not match", expected, info.androidBpContents) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
Paul Duffin | d075907 | 2021-02-17 11:23:00 +0000 | [diff] [blame] | 244 | // Check that the snapshot's unversioned generated Android.bp is correct. |
| 245 | // |
| 246 | // This func should be used to check the general snapshot generation code. |
| 247 | // |
| 248 | // Both the expected and actual string are both trimmed before comparing. |
| 249 | func checkUnversionedAndroidBpContents(expected string) snapshotBuildInfoChecker { |
| 250 | return func(info *snapshotBuildInfo) { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 251 | info.t.Helper() |
| 252 | android.AssertTrimmedStringEquals(info.t, "unversioned Android.bp contents do not match", expected, info.androidUnversionedBpContents) |
Paul Duffin | d075907 | 2021-02-17 11:23:00 +0000 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
| 256 | // Check that the snapshot's versioned generated Android.bp is correct. |
| 257 | // |
| 258 | // This func should only be used to check the version specific snapshot generation code, |
| 259 | // i.e. the encoding of version into module names and the generation of the _snapshot module. The |
| 260 | // general snapshot generation code should be checked using the checkUnversionedAndroidBpContents() |
| 261 | // func. |
| 262 | // |
| 263 | // Both the expected and actual string are both trimmed before comparing. |
| 264 | func checkVersionedAndroidBpContents(expected string) snapshotBuildInfoChecker { |
| 265 | return func(info *snapshotBuildInfo) { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 266 | info.t.Helper() |
| 267 | android.AssertTrimmedStringEquals(info.t, "versioned Android.bp contents do not match", expected, info.androidVersionedBpContents) |
Paul Duffin | d075907 | 2021-02-17 11:23:00 +0000 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 271 | // Check that the snapshot's copy rules are correct. |
| 272 | // |
| 273 | // The copy rules are formatted as <src> -> <dest>, one per line and then compared |
| 274 | // to the supplied expected string. Both the expected and actual string are trimmed |
| 275 | // before comparing. |
| 276 | func checkAllCopyRules(expected string) snapshotBuildInfoChecker { |
| 277 | return func(info *snapshotBuildInfo) { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 278 | info.t.Helper() |
| 279 | android.AssertTrimmedStringEquals(info.t, "Incorrect copy rules", expected, info.copyRules) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 283 | func checkAllOtherCopyRules(expected string) snapshotBuildInfoChecker { |
| 284 | return func(info *snapshotBuildInfo) { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 285 | info.t.Helper() |
| 286 | android.AssertTrimmedStringEquals(info.t, "Incorrect copy rules", expected, info.otherCopyRules) |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 290 | // Check that the specified paths match the list of zips to merge with the intermediate zip. |
| 291 | func checkMergeZips(expected ...string) snapshotBuildInfoChecker { |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 292 | return func(info *snapshotBuildInfo) { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 293 | info.t.Helper() |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 294 | if info.intermediateZip == "" { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 295 | info.t.Errorf("No intermediate zip file was created") |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 296 | } |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 297 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 298 | android.AssertDeepEquals(info.t, "mismatching merge zip files", expected, info.mergeZips) |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
| 302 | // Encapsulates information about the snapshot build structure in order to insulate tests from |
| 303 | // knowing too much about internal structures. |
| 304 | // |
| 305 | // All source/input paths are relative either the build directory. All dest/output paths are |
| 306 | // relative to the snapshot root directory. |
| 307 | type snapshotBuildInfo struct { |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 308 | t *testing.T |
| 309 | |
| 310 | // The result from RunTest() |
Paul Duffin | 4a2a29c | 2021-03-09 22:27:13 +0000 | [diff] [blame] | 311 | r *android.TestResult |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 312 | |
| 313 | // The contents of the generated Android.bp file |
| 314 | androidBpContents string |
| 315 | |
Paul Duffin | d075907 | 2021-02-17 11:23:00 +0000 | [diff] [blame] | 316 | // The contents of the unversioned Android.bp file |
| 317 | androidUnversionedBpContents string |
| 318 | |
| 319 | // The contents of the versioned Android.bp file |
| 320 | androidVersionedBpContents string |
| 321 | |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 322 | // The paths, relative to the snapshot root, of all files and directories copied into the |
| 323 | // snapshot. |
| 324 | snapshotContents []string |
| 325 | |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 326 | // A formatted representation of the src/dest pairs for a snapshot, one pair per line, |
| 327 | // of the format src -> dest |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 328 | copyRules string |
| 329 | |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 330 | // A formatted representation of the src/dest pairs for files not in a snapshot, one pair |
| 331 | // per line, of the format src -> dest |
| 332 | otherCopyRules string |
| 333 | |
Paul Duffin | c3c5d5e | 2019-11-29 20:45:22 +0000 | [diff] [blame] | 334 | // The path to the intermediate zip, which is a zip created from the source files copied |
| 335 | // into the snapshot directory and which will be merged with other zips to form the final output. |
| 336 | // Is am empty string if there is no intermediate zip because there are no zips to merge in. |
| 337 | intermediateZip string |
| 338 | |
| 339 | // The paths to the zips to merge into the output zip, does not include the intermediate |
| 340 | // zip. |
| 341 | mergeZips []string |
| 342 | |
| 343 | // The final output zip. |
| 344 | outputZip string |
| 345 | } |