Colin Cross | 1496fb1 | 2024-09-09 16:44:10 -0700 | [diff] [blame] | 1 | // Copyright 2024 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 golang |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
Cole Faust | d1d08ab | 2024-10-04 15:29:20 -0700 | [diff] [blame] | 19 | "regexp" |
Colin Cross | 1496fb1 | 2024-09-09 16:44:10 -0700 | [diff] [blame] | 20 | "testing" |
Cole Faust | d1d08ab | 2024-10-04 15:29:20 -0700 | [diff] [blame] | 21 | |
| 22 | "github.com/google/blueprint/bootstrap" |
Colin Cross | 1496fb1 | 2024-09-09 16:44:10 -0700 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | func TestGolang(t *testing.T) { |
| 26 | bp := ` |
| 27 | bootstrap_go_package { |
| 28 | name: "gopkg", |
| 29 | pkgPath: "test/pkg", |
| 30 | } |
| 31 | |
| 32 | blueprint_go_binary { |
| 33 | name: "gobin", |
| 34 | deps: ["gopkg"], |
| 35 | } |
| 36 | ` |
| 37 | |
| 38 | result := android.GroupFixturePreparers( |
| 39 | android.PrepareForTestWithArchMutator, |
| 40 | android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { |
| 41 | RegisterGoModuleTypes(ctx) |
| 42 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
Colin Cross | b8533a8 | 2024-10-05 15:25:09 -0700 | [diff] [blame] | 43 | ctx.BottomUpBlueprint("bootstrap_deps", bootstrap.BootstrapDeps).UsesReverseDependencies() |
Colin Cross | 1496fb1 | 2024-09-09 16:44:10 -0700 | [diff] [blame] | 44 | }) |
| 45 | }), |
| 46 | ).RunTestWithBp(t, bp) |
| 47 | |
| 48 | bin := result.ModuleForTests("gobin", result.Config.BuildOSTarget.String()) |
| 49 | |
Cole Faust | d1d08ab | 2024-10-04 15:29:20 -0700 | [diff] [blame] | 50 | expected := "^out/soong/host/" + result.Config.PrebuiltOS() + "/bin/go/gobin/?[^/]*/obj/gobin$" |
| 51 | actual := android.PathsRelativeToTop(bin.OutputFiles(result.TestContext, t, "")) |
| 52 | if len(actual) != 1 { |
| 53 | t.Fatalf("Expected 1 output file, got %v", actual) |
| 54 | } |
| 55 | if match, err := regexp.Match(expected, []byte(actual[0])); err != nil || !match { |
| 56 | t.Fatalf("Expected output file to match %q, but got %q", expected, actual[0]) |
| 57 | } |
Colin Cross | 1496fb1 | 2024-09-09 16:44:10 -0700 | [diff] [blame] | 58 | } |