blob: 3704b2d7b10e3341cb625cf24286521b121432c1 [file] [log] [blame]
Sasha Smundak8bea2672022-08-04 13:31:14 -07001// Copyright 2022 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 bp2build
16
17import (
18 "android/soong/android"
19 "android/soong/genrule"
20 "testing"
21)
22
23func registerDependentModules(ctx android.RegistrationContext) {
24 ctx.RegisterModuleType("license", android.LicenseFactory)
25 ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
26}
27
28func TestPackage(t *testing.T) {
29 tests := []struct {
30 description string
31 modules string
32 expected []ExpectedRuleTarget
33 }{
34 {
35 description: "with default applicable licenses",
36 modules: `
37license {
38 name: "my_license",
39 visibility: [":__subpackages__"],
40 license_kinds: ["SPDX-license-identifier-Apache-2.0"],
41 license_text: ["NOTICE"],
42}
43
44package {
45 default_applicable_licenses: ["my_license"],
46}
47`,
48 expected: []ExpectedRuleTarget{
49 {
50 "package",
51 "",
52 AttrNameToString{
53 "default_applicable_licenses": `[":my_license"]`,
54 "default_visibility": `["//visibility:public"]`,
55 },
56 android.HostAndDeviceDefault,
57 },
58 {
59 "android_license",
60 "my_license",
61 AttrNameToString{
62 "license_kinds": `["SPDX-license-identifier-Apache-2.0"]`,
63 "license_text": `"NOTICE"`,
64 "visibility": `[":__subpackages__"]`,
65 },
66 android.HostAndDeviceDefault,
67 },
68 },
69 },
70 }
71 for _, test := range tests {
72 expected := make([]string, 0, len(test.expected))
73 for _, e := range test.expected {
74 expected = append(expected, e.String())
75 }
76 RunBp2BuildTestCase(t, registerDependentModules,
77 Bp2buildTestCase{
78 Description: test.description,
79 ModuleTypeUnderTest: "package",
80 ModuleTypeUnderTestFactory: android.PackageFactory,
81 Blueprint: test.modules,
82 ExpectedBazelTargets: expected,
83 })
84 }
85}