2021-07-27 13:10:32 +02:00
|
|
|
// Copyright 2021 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package bp2build
|
|
|
|
|
|
|
|
import (
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/apex"
|
|
|
|
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2022-06-21 21:28:33 +02:00
|
|
|
func runApexKeyTestCase(t *testing.T, tc Bp2buildTestCase) {
|
2021-07-27 13:10:32 +02:00
|
|
|
t.Helper()
|
2022-06-21 21:28:33 +02:00
|
|
|
RunBp2BuildTestCase(t, registerApexKeyModuleTypes, tc)
|
2021-07-27 13:10:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func registerApexKeyModuleTypes(ctx android.RegistrationContext) {
|
2022-10-05 08:15:15 +02:00
|
|
|
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
2021-07-27 13:10:32 +02:00
|
|
|
}
|
|
|
|
|
2022-10-14 11:56:07 +02:00
|
|
|
func TestApexKeySimple_KeysAreSrcFilesInSameDir(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runApexKeyTestCase(t, Bp2buildTestCase{
|
2022-10-14 11:56:07 +02:00
|
|
|
Description: "apex key - keys are src files, use key attributes",
|
2022-06-21 21:28:33 +02:00
|
|
|
ModuleTypeUnderTest: "apex_key",
|
|
|
|
ModuleTypeUnderTestFactory: apex.ApexKeyFactory,
|
2022-10-14 11:56:07 +02:00
|
|
|
Filesystem: map[string]string{
|
|
|
|
"com.android.apogee.avbpubkey": "",
|
|
|
|
"com.android.apogee.pem": "",
|
|
|
|
},
|
|
|
|
Blueprint: `
|
|
|
|
apex_key {
|
|
|
|
name: "com.android.apogee.key",
|
|
|
|
public_key: "com.android.apogee.avbpubkey",
|
|
|
|
private_key: "com.android.apogee.pem",
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{
|
2023-08-23 06:54:08 +02:00
|
|
|
"private_key": `"com.android.apogee.pem"`,
|
|
|
|
"public_key": `"com.android.apogee.avbpubkey"`,
|
|
|
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
2022-10-14 11:56:07 +02:00
|
|
|
}),
|
|
|
|
}})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestApexKeySimple_KeysAreSrcFilesNotInDir(t *testing.T) {
|
|
|
|
runApexKeyTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "apex key - keys are not src or module, use key_name attributes",
|
|
|
|
ModuleTypeUnderTest: "apex_key",
|
|
|
|
ModuleTypeUnderTestFactory: apex.ApexKeyFactory,
|
|
|
|
Filesystem: map[string]string{
|
|
|
|
// deliberately left empty
|
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `
|
2021-07-27 13:10:32 +02:00
|
|
|
apex_key {
|
|
|
|
name: "com.android.apogee.key",
|
|
|
|
public_key: "com.android.apogee.avbpubkey",
|
|
|
|
private_key: "com.android.apogee.pem",
|
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{
|
2023-08-23 06:54:08 +02:00
|
|
|
"private_key_name": `"com.android.apogee.pem"`,
|
|
|
|
"public_key_name": `"com.android.apogee.avbpubkey"`,
|
|
|
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
2022-10-05 08:15:15 +02:00
|
|
|
}),
|
|
|
|
}})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestApexKey_KeysAreModules(t *testing.T) {
|
|
|
|
runApexKeyTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "apex key - keys are modules, use key attributes",
|
|
|
|
ModuleTypeUnderTest: "apex_key",
|
|
|
|
ModuleTypeUnderTestFactory: apex.ApexKeyFactory,
|
|
|
|
Filesystem: map[string]string{},
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"com.android.apogee.avbpubkey", "com.android.apogee.pem"},
|
2022-10-05 08:15:15 +02:00
|
|
|
Blueprint: `
|
|
|
|
apex_key {
|
|
|
|
name: "com.android.apogee.key",
|
|
|
|
public_key: ":com.android.apogee.avbpubkey",
|
|
|
|
private_key: ":com.android.apogee.pem",
|
|
|
|
}
|
2023-09-19 03:12:48 +02:00
|
|
|
` + simpleModule("filegroup", "com.android.apogee.avbpubkey") +
|
|
|
|
simpleModule("filegroup", "com.android.apogee.pem"),
|
2022-10-05 08:15:15 +02:00
|
|
|
ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{
|
2023-08-23 06:54:08 +02:00
|
|
|
"private_key": `":com.android.apogee.pem"`,
|
|
|
|
"public_key": `":com.android.apogee.avbpubkey"`,
|
|
|
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
2021-11-08 18:56:31 +01:00
|
|
|
}),
|
|
|
|
}})
|
2021-07-27 13:10:32 +02:00
|
|
|
}
|