blob: 7a2540a2772a10caa550183983b138afee4df874 [file] [log] [blame]
Paul Duffin82d90432019-11-30 09:24:33 +00001// 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
15package sdk
16
17import (
Paul Duffinc3c5d5e2019-11-29 20:45:22 +000018 "fmt"
Paul Duffin82d90432019-11-30 09:24:33 +000019 "io/ioutil"
20 "os"
Paul Duffinc3c5d5e2019-11-29 20:45:22 +000021 "path/filepath"
Paul Duffinb07fa512020-03-10 22:17:04 +000022 "reflect"
Paul Duffin82d90432019-11-30 09:24:33 +000023 "strings"
24 "testing"
25
26 "android/soong/android"
27 "android/soong/apex"
28 "android/soong/cc"
Paul Duffind6ceb862021-03-04 23:02:31 +000029 "android/soong/genrule"
Paul Duffin82d90432019-11-30 09:24:33 +000030 "android/soong/java"
31)
32
Martin Stjernholm7feceb22020-07-11 04:33:29 +010033func testSdkContext(bp string, fs map[string][]byte, extraOsTypes []android.OsType) (*android.TestContext, android.Config) {
34 extraOsTypes = append(extraOsTypes, android.Android, android.Windows)
35
Colin Cross98be1bb2019-12-13 20:41:13 -080036 bp = bp + `
37 apex_key {
38 name: "myapex.key",
39 public_key: "myapex.avbpubkey",
40 private_key: "myapex.pem",
41 }
42
43 android_app_certificate {
44 name: "myapex.cert",
45 certificate: "myapex",
46 }
Martin Stjernholm7feceb22020-07-11 04:33:29 +010047 ` + cc.GatherRequiredDepsForTest(extraOsTypes...)
Colin Cross98be1bb2019-12-13 20:41:13 -080048
49 mockFS := map[string][]byte{
Martin Stjernholmcc776012020-07-07 03:22:21 +010050 "build/make/target/product/security": nil,
51 "apex_manifest.json": nil,
52 "system/sepolicy/apex/myapex-file_contexts": nil,
53 "system/sepolicy/apex/myapex2-file_contexts": nil,
54 "system/sepolicy/apex/mysdkapex-file_contexts": nil,
55 "myapex.avbpubkey": nil,
56 "myapex.pem": nil,
57 "myapex.x509.pem": nil,
58 "myapex.pk8": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -080059 }
60
Colin Crossf28329d2020-02-15 11:00:10 -080061 cc.GatherRequiredFilesForTest(mockFS)
62
Colin Cross98be1bb2019-12-13 20:41:13 -080063 for k, v := range fs {
64 mockFS[k] = v
65 }
66
67 config := android.TestArchConfig(buildDir, nil, bp, mockFS)
68
Paul Duffin08798aa2020-02-27 13:12:46 +000069 // Add windows as a default disable OS to test behavior when some OS variants
70 // are disabled.
71 config.Targets[android.Windows] = []android.Target{
Jiyong Park1613e552020-09-14 19:43:17 +090072 {android.Windows, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", "", true},
Paul Duffin08798aa2020-02-27 13:12:46 +000073 }
74
Martin Stjernholm7feceb22020-07-11 04:33:29 +010075 for _, extraOsType := range extraOsTypes {
76 switch extraOsType {
77 case android.LinuxBionic:
78 config.Targets[android.LinuxBionic] = []android.Target{
Jiyong Park1613e552020-09-14 19:43:17 +090079 {android.LinuxBionic, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", "", false},
Martin Stjernholm7feceb22020-07-11 04:33:29 +010080 }
81 }
82 }
83
Colin Crossae8600b2020-10-29 17:09:13 -070084 ctx := android.NewTestArchContext(config)
Paul Duffin82d90432019-11-30 09:24:33 +000085
Paul Duffin8c3fec42020-03-04 20:15:08 +000086 // Enable androidmk support.
87 // * Register the singleton
88 // * Configure that we are inside make
89 // * Add CommonOS to ensure that androidmk processing works.
90 android.RegisterAndroidMkBuildComponents(ctx)
Jingwen Chencda22c92020-11-23 00:22:30 -050091 android.SetKatiEnabledForTests(config)
Paul Duffin8c3fec42020-03-04 20:15:08 +000092 config.Targets[android.CommonOS] = []android.Target{
Jiyong Park1613e552020-09-14 19:43:17 +090093 {android.CommonOS, android.Arch{ArchType: android.Common}, android.NativeBridgeDisabled, "", "", true},
Paul Duffin8c3fec42020-03-04 20:15:08 +000094 }
95
Paul Duffin82d90432019-11-30 09:24:33 +000096 // from android package
Paul Duffinc1327422020-01-14 12:15:29 +000097 android.RegisterPackageBuildComponents(ctx)
Paul Duffina2ae7e02020-09-11 11:55:00 +010098 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Paul Duffin593b3c92019-12-05 14:31:48 +000099 ctx.PreArchMutators(android.RegisterVisibilityRuleChecker)
Paul Duffin82d90432019-11-30 09:24:33 +0000100 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin44f1d842020-06-26 20:17:02 +0100101 ctx.PreArchMutators(android.RegisterComponentsMutator)
Paul Duffin021f4e52020-07-30 16:04:17 +0100102
103 android.RegisterPrebuiltMutators(ctx)
104
105 // Register these after the prebuilt mutators have been registered to match what
106 // happens at runtime.
Paul Duffin593b3c92019-12-05 14:31:48 +0000107 ctx.PreArchMutators(android.RegisterVisibilityRuleGatherer)
108 ctx.PostDepsMutators(android.RegisterVisibilityRuleEnforcer)
109
Paul Duffin82d90432019-11-30 09:24:33 +0000110 // from java package
Paul Duffinc059c8c2021-01-20 17:13:52 +0000111 java.RegisterRequiredBuildComponentsForTest(ctx)
Paul Duffin82d90432019-11-30 09:24:33 +0000112
Paul Duffind6ceb862021-03-04 23:02:31 +0000113 // from genrule package
114 genrule.RegisterGenruleBuildComponents(ctx)
115
Paul Duffin82d90432019-11-30 09:24:33 +0000116 // from cc package
Paul Duffin77980a82019-12-19 16:01:36 +0000117 cc.RegisterRequiredBuildComponentsForTest(ctx)
Paul Duffin82d90432019-11-30 09:24:33 +0000118
119 // from apex package
120 ctx.RegisterModuleType("apex", apex.BundleFactory)
121 ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
122 ctx.PostDepsMutators(apex.RegisterPostDepsMutators)
123
124 // from this package
Paul Duffin8150da62019-12-16 17:21:27 +0000125 ctx.RegisterModuleType("sdk", SdkModuleFactory)
Paul Duffin82d90432019-11-30 09:24:33 +0000126 ctx.RegisterModuleType("sdk_snapshot", SnapshotModuleFactory)
Paul Duffin8150da62019-12-16 17:21:27 +0000127 ctx.RegisterModuleType("module_exports", ModuleExportsFactory)
128 ctx.RegisterModuleType("module_exports_snapshot", ModuleExportsSnapshotsFactory)
Paul Duffin82d90432019-11-30 09:24:33 +0000129 ctx.PreDepsMutators(RegisterPreDepsMutators)
130 ctx.PostDepsMutators(RegisterPostDepsMutators)
131
Colin Crossae8600b2020-10-29 17:09:13 -0700132 ctx.Register()
Paul Duffin82d90432019-11-30 09:24:33 +0000133
134 return ctx, config
135}
136
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100137func runTests(t *testing.T, ctx *android.TestContext, config android.Config) *testSdkResult {
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000138 t.Helper()
Paul Duffin593b3c92019-12-05 14:31:48 +0000139 _, errs := ctx.ParseBlueprintsFiles(".")
Paul Duffin82d90432019-11-30 09:24:33 +0000140 android.FailIfErrored(t, errs)
141 _, errs = ctx.PrepareBuildActions(config)
142 android.FailIfErrored(t, errs)
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000143 return &testSdkResult{
144 TestHelper: TestHelper{t: t},
145 ctx: ctx,
146 config: config,
147 }
Paul Duffin82d90432019-11-30 09:24:33 +0000148}
149
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100150func testSdkWithFs(t *testing.T, bp string, fs map[string][]byte) *testSdkResult {
151 t.Helper()
152 ctx, config := testSdkContext(bp, fs, nil)
153 return runTests(t, ctx, config)
154}
155
Paul Duffin82d90432019-11-30 09:24:33 +0000156func testSdkError(t *testing.T, pattern, bp string) {
157 t.Helper()
Martin Stjernholm7feceb22020-07-11 04:33:29 +0100158 ctx, config := testSdkContext(bp, nil, nil)
Paul Duffin82d90432019-11-30 09:24:33 +0000159 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
160 if len(errs) > 0 {
161 android.FailIfNoMatchingErrors(t, pattern, errs)
162 return
163 }
164 _, errs = ctx.PrepareBuildActions(config)
165 if len(errs) > 0 {
166 android.FailIfNoMatchingErrors(t, pattern, errs)
167 return
168 }
169
170 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
171}
172
173func ensureListContains(t *testing.T, result []string, expected string) {
174 t.Helper()
175 if !android.InList(expected, result) {
176 t.Errorf("%q is not found in %v", expected, result)
177 }
178}
179
180func pathsToStrings(paths android.Paths) []string {
181 var ret []string
182 for _, p := range paths {
183 ret = append(ret, p.String())
184 }
185 return ret
186}
187
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000188// Provides general test support.
189type TestHelper struct {
190 t *testing.T
191}
192
193func (h *TestHelper) AssertStringEquals(message string, expected string, actual string) {
194 h.t.Helper()
195 if actual != expected {
196 h.t.Errorf("%s: expected %s, actual %s", message, expected, actual)
Paul Duffin82d90432019-11-30 09:24:33 +0000197 }
198}
199
Paul Duffin4b8b7932020-05-06 12:35:38 +0100200func (h *TestHelper) AssertErrorMessageEquals(message string, expected string, actual error) {
201 h.t.Helper()
202 if actual == nil {
203 h.t.Errorf("Expected error but was nil")
204 } else if actual.Error() != expected {
205 h.t.Errorf("%s: expected %s, actual %s", message, expected, actual.Error())
206 }
207}
208
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000209func (h *TestHelper) AssertTrimmedStringEquals(message string, expected string, actual string) {
210 h.t.Helper()
Paul Duffin42dd4e62021-02-22 11:35:24 +0000211 expected = strings.TrimSpace(expected)
212 actual = strings.TrimSpace(actual)
213 if actual != expected {
214 h.t.Errorf("%s: expected:\n%s\nactual:\n%s\n", message, expected, actual)
215 }
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000216}
217
Paul Duffinb07fa512020-03-10 22:17:04 +0000218func (h *TestHelper) AssertDeepEquals(message string, expected interface{}, actual interface{}) {
219 h.t.Helper()
220 if !reflect.DeepEqual(actual, expected) {
221 h.t.Errorf("%s: expected %#v, actual %#v", message, expected, actual)
222 }
223}
224
Martin Stjernholm191c25f2020-09-10 00:40:37 +0100225func (h *TestHelper) AssertPanic(message string, funcThatShouldPanic func()) {
226 h.t.Helper()
227 panicked := false
228 func() {
229 defer func() {
230 if x := recover(); x != nil {
231 panicked = true
232 }
233 }()
234 funcThatShouldPanic()
235 }()
236 if !panicked {
237 h.t.Error(message)
238 }
239}
240
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000241// Encapsulates result of processing an SDK definition. Provides support for
242// checking the state of the build structures.
243type testSdkResult struct {
244 TestHelper
245 ctx *android.TestContext
246 config android.Config
247}
248
249// Analyse the sdk build rules to extract information about what it is doing.
250
251// e.g. find the src/dest pairs from each cp command, the various zip files
252// generated, etc.
253func (r *testSdkResult) getSdkSnapshotBuildInfo(sdk *sdk) *snapshotBuildInfo {
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000254 info := &snapshotBuildInfo{
Paul Duffind0759072021-02-17 11:23:00 +0000255 r: r,
256 androidBpContents: sdk.GetAndroidBpContentsForTests(),
257 androidUnversionedBpContents: sdk.GetUnversionedAndroidBpContentsForTests(),
258 androidVersionedBpContents: sdk.GetVersionedAndroidBpContentsForTests(),
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000259 }
260
261 buildParams := sdk.BuildParamsForTests()
262 copyRules := &strings.Builder{}
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000263 otherCopyRules := &strings.Builder{}
Paul Duffine1ddcc92020-03-03 16:01:26 +0000264 snapshotDirPrefix := sdk.builderForTests.snapshotDir.String() + "/"
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000265 for _, bp := range buildParams {
266 switch bp.Rule.String() {
267 case android.Cp.String():
Paul Duffine1ddcc92020-03-03 16:01:26 +0000268 output := bp.Output
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000269 // Get destination relative to the snapshot root
270 dest := output.Rel()
271 src := android.NormalizePathForTesting(bp.Input)
272 // We differentiate between copy rules for the snapshot, and copy rules for the install file.
Paul Duffine1ddcc92020-03-03 16:01:26 +0000273 if strings.HasPrefix(output.String(), snapshotDirPrefix) {
274 // Get source relative to build directory.
Paul Duffine1ddcc92020-03-03 16:01:26 +0000275 _, _ = fmt.Fprintf(copyRules, "%s -> %s\n", src, dest)
276 info.snapshotContents = append(info.snapshotContents, dest)
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000277 } else {
278 _, _ = fmt.Fprintf(otherCopyRules, "%s -> %s\n", src, dest)
Paul Duffine1ddcc92020-03-03 16:01:26 +0000279 }
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000280
281 case repackageZip.String():
282 // Add the destdir to the snapshot contents as that is effectively where
283 // the content of the repackaged zip is copied.
284 dest := bp.Args["destdir"]
285 info.snapshotContents = append(info.snapshotContents, dest)
286
287 case zipFiles.String():
288 // This could be an intermediate zip file and not the actual output zip.
289 // In that case this will be overridden when the rule to merge the zips
290 // is processed.
Paul Duffin9b478b02019-12-10 13:41:51 +0000291 info.outputZip = android.NormalizePathForTesting(bp.Output)
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000292
293 case mergeZips.String():
294 // Copy the current outputZip to the intermediateZip.
295 info.intermediateZip = info.outputZip
Paul Duffin9b478b02019-12-10 13:41:51 +0000296 mergeInput := android.NormalizePathForTesting(bp.Input)
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000297 if info.intermediateZip != mergeInput {
298 r.t.Errorf("Expected intermediate zip %s to be an input to merge zips but found %s instead",
299 info.intermediateZip, mergeInput)
300 }
301
302 // Override output zip (which was actually the intermediate zip file) with the actual
303 // output zip.
Paul Duffin9b478b02019-12-10 13:41:51 +0000304 info.outputZip = android.NormalizePathForTesting(bp.Output)
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000305
306 // Save the zips to be merged into the intermediate zip.
Paul Duffin9b478b02019-12-10 13:41:51 +0000307 info.mergeZips = android.NormalizePathsForTesting(bp.Inputs)
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000308 }
309 }
310
311 info.copyRules = copyRules.String()
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000312 info.otherCopyRules = otherCopyRules.String()
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000313
314 return info
315}
316
317func (r *testSdkResult) Module(name string, variant string) android.Module {
318 return r.ctx.ModuleForTests(name, variant).Module()
319}
320
321func (r *testSdkResult) ModuleForTests(name string, variant string) android.TestingModule {
322 return r.ctx.ModuleForTests(name, variant)
323}
324
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000325// Check the snapshot build rules.
326//
327// Takes a list of functions which check different facets of the snapshot build rules.
328// Allows each test to customize what is checked without duplicating lots of code
329// or proliferating check methods of different flavors.
Paul Duffin1356d8c2020-02-25 19:26:33 +0000330func (r *testSdkResult) CheckSnapshot(name string, dir string, checkers ...snapshotBuildInfoChecker) {
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000331 r.t.Helper()
332
Paul Duffin1356d8c2020-02-25 19:26:33 +0000333 // The sdk CommonOS variant is always responsible for generating the snapshot.
334 variant := android.CommonOS.Name
335
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000336 sdk := r.Module(name, variant).(*sdk)
337
338 snapshotBuildInfo := r.getSdkSnapshotBuildInfo(sdk)
339
340 // Check state of the snapshot build.
341 for _, checker := range checkers {
342 checker(snapshotBuildInfo)
343 }
344
345 // Make sure that the generated zip file is in the correct place.
346 actual := snapshotBuildInfo.outputZip
Paul Duffin593b3c92019-12-05 14:31:48 +0000347 if dir != "" {
348 dir = filepath.Clean(dir) + "/"
349 }
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000350 r.AssertStringEquals("Snapshot zip file in wrong place",
Paul Duffin593b3c92019-12-05 14:31:48 +0000351 fmt.Sprintf(".intermediates/%s%s/%s/%s-current.zip", dir, name, variant, name), actual)
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000352
353 // Populate a mock filesystem with the files that would have been copied by
354 // the rules.
355 fs := make(map[string][]byte)
356 for _, dest := range snapshotBuildInfo.snapshotContents {
357 fs[dest] = nil
358 }
359
360 // Process the generated bp file to make sure it is valid.
361 testSdkWithFs(r.t, snapshotBuildInfo.androidBpContents, fs)
362}
363
364type snapshotBuildInfoChecker func(info *snapshotBuildInfo)
365
366// Check that the snapshot's generated Android.bp is correct.
367//
368// Both the expected and actual string are both trimmed before comparing.
369func checkAndroidBpContents(expected string) snapshotBuildInfoChecker {
370 return func(info *snapshotBuildInfo) {
371 info.r.t.Helper()
372 info.r.AssertTrimmedStringEquals("Android.bp contents do not match", expected, info.androidBpContents)
373 }
374}
375
Paul Duffind0759072021-02-17 11:23:00 +0000376// Check that the snapshot's unversioned generated Android.bp is correct.
377//
378// This func should be used to check the general snapshot generation code.
379//
380// Both the expected and actual string are both trimmed before comparing.
381func checkUnversionedAndroidBpContents(expected string) snapshotBuildInfoChecker {
382 return func(info *snapshotBuildInfo) {
383 info.r.t.Helper()
384 info.r.AssertTrimmedStringEquals("unversioned Android.bp contents do not match", expected, info.androidUnversionedBpContents)
385 }
386}
387
388// Check that the snapshot's versioned generated Android.bp is correct.
389//
390// This func should only be used to check the version specific snapshot generation code,
391// i.e. the encoding of version into module names and the generation of the _snapshot module. The
392// general snapshot generation code should be checked using the checkUnversionedAndroidBpContents()
393// func.
394//
395// Both the expected and actual string are both trimmed before comparing.
396func checkVersionedAndroidBpContents(expected string) snapshotBuildInfoChecker {
397 return func(info *snapshotBuildInfo) {
398 info.r.t.Helper()
399 info.r.AssertTrimmedStringEquals("versioned Android.bp contents do not match", expected, info.androidVersionedBpContents)
400 }
401}
402
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000403// Check that the snapshot's copy rules are correct.
404//
405// The copy rules are formatted as <src> -> <dest>, one per line and then compared
406// to the supplied expected string. Both the expected and actual string are trimmed
407// before comparing.
408func checkAllCopyRules(expected string) snapshotBuildInfoChecker {
409 return func(info *snapshotBuildInfo) {
410 info.r.t.Helper()
411 info.r.AssertTrimmedStringEquals("Incorrect copy rules", expected, info.copyRules)
412 }
413}
414
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000415func checkAllOtherCopyRules(expected string) snapshotBuildInfoChecker {
416 return func(info *snapshotBuildInfo) {
417 info.r.t.Helper()
418 info.r.AssertTrimmedStringEquals("Incorrect copy rules", expected, info.otherCopyRules)
419 }
420}
421
Paul Duffin3d1248c2020-04-09 00:10:17 +0100422// Check that the specified paths match the list of zips to merge with the intermediate zip.
423func checkMergeZips(expected ...string) snapshotBuildInfoChecker {
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000424 return func(info *snapshotBuildInfo) {
425 info.r.t.Helper()
426 if info.intermediateZip == "" {
427 info.r.t.Errorf("No intermediate zip file was created")
428 }
Paul Duffin3d1248c2020-04-09 00:10:17 +0100429
430 info.r.AssertDeepEquals("mismatching merge zip files", expected, info.mergeZips)
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000431 }
432}
433
434// Encapsulates information about the snapshot build structure in order to insulate tests from
435// knowing too much about internal structures.
436//
437// All source/input paths are relative either the build directory. All dest/output paths are
438// relative to the snapshot root directory.
439type snapshotBuildInfo struct {
440 r *testSdkResult
441
442 // The contents of the generated Android.bp file
443 androidBpContents string
444
Paul Duffind0759072021-02-17 11:23:00 +0000445 // The contents of the unversioned Android.bp file
446 androidUnversionedBpContents string
447
448 // The contents of the versioned Android.bp file
449 androidVersionedBpContents string
450
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000451 // The paths, relative to the snapshot root, of all files and directories copied into the
452 // snapshot.
453 snapshotContents []string
454
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000455 // A formatted representation of the src/dest pairs for a snapshot, one pair per line,
456 // of the format src -> dest
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000457 copyRules string
458
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000459 // A formatted representation of the src/dest pairs for files not in a snapshot, one pair
460 // per line, of the format src -> dest
461 otherCopyRules string
462
Paul Duffinc3c5d5e2019-11-29 20:45:22 +0000463 // The path to the intermediate zip, which is a zip created from the source files copied
464 // into the snapshot directory and which will be merged with other zips to form the final output.
465 // Is am empty string if there is no intermediate zip because there are no zips to merge in.
466 intermediateZip string
467
468 // The paths to the zips to merge into the output zip, does not include the intermediate
469 // zip.
470 mergeZips []string
471
472 // The final output zip.
473 outputZip string
474}
475
Paul Duffin82d90432019-11-30 09:24:33 +0000476var buildDir string
477
478func setUp() {
479 var err error
480 buildDir, err = ioutil.TempDir("", "soong_sdk_test")
481 if err != nil {
482 panic(err)
483 }
484}
485
486func tearDown() {
487 _ = os.RemoveAll(buildDir)
488}
489
490func runTestWithBuildDir(m *testing.M) {
491 run := func() int {
492 setUp()
493 defer tearDown()
494
495 return m.Run()
496 }
497
498 os.Exit(run())
499}