Spandan Das | ea2abba | 2023-06-14 21:30:38 +0000 | [diff] [blame^] | 1 | // Copyright 2023 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 bp2build |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
| 19 | |
| 20 | "github.com/google/blueprint/bootstrap" |
| 21 | |
| 22 | "android/soong/android" |
| 23 | ) |
| 24 | |
| 25 | func runGoTests(t *testing.T, tc Bp2buildTestCase) { |
| 26 | RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { |
| 27 | tCtx := ctx.(*android.TestContext) |
| 28 | bootstrap.RegisterGoModuleTypes(tCtx.Context.Context) // android.TestContext --> android.Context --> blueprint.Context |
| 29 | }, tc) |
| 30 | } |
| 31 | |
| 32 | func TestConvertGoPackage(t *testing.T) { |
| 33 | bp := ` |
| 34 | bootstrap_go_package { |
| 35 | name: "foo", |
| 36 | pkgPath: "android/foo", |
| 37 | deps: [ |
| 38 | "bar", |
| 39 | ], |
| 40 | srcs: [ |
| 41 | "foo1.go", |
| 42 | "foo2.go", |
| 43 | ], |
| 44 | linux: { |
| 45 | srcs: [ |
| 46 | "foo_linux.go", |
| 47 | ], |
| 48 | }, |
| 49 | darwin: { |
| 50 | srcs: [ |
| 51 | "foo_darwin.go", |
| 52 | ], |
| 53 | }, |
| 54 | testSrcs: [ |
| 55 | "foo1_test.go", |
| 56 | "foo2_test.go", |
| 57 | ], |
| 58 | } |
| 59 | ` |
| 60 | depBp := ` |
| 61 | bootstrap_go_package { |
| 62 | name: "bar", |
| 63 | } |
| 64 | ` |
| 65 | t.Parallel() |
| 66 | runGoTests(t, Bp2buildTestCase{ |
| 67 | Description: "Convert bootstrap_go_package to go_library", |
| 68 | ModuleTypeUnderTest: "bootrstap_go_package", |
| 69 | Blueprint: bp, |
| 70 | Filesystem: map[string]string{ |
| 71 | "bar/Android.bp": depBp, // Put dep in Android.bp to reduce boilerplate in ExpectedBazelTargets |
| 72 | }, |
| 73 | ExpectedBazelTargets: []string{makeBazelTargetHostOrDevice("go_library", "foo", |
| 74 | AttrNameToString{ |
| 75 | "deps": `["//bar:bar"]`, |
| 76 | "importpath": `"android/foo"`, |
| 77 | "srcs": `[ |
| 78 | ":foo1.go", |
| 79 | ":foo2.go", |
| 80 | ] + select({ |
| 81 | "//build/bazel/platforms/os:darwin": [":foo_darwin.go"], |
| 82 | "//build/bazel/platforms/os:linux_glibc": [":foo_linux.go"], |
| 83 | "//conditions:default": [], |
| 84 | })`, |
| 85 | }, |
| 86 | android.HostSupported, |
| 87 | )}, |
| 88 | }) |
| 89 | } |