build system implementation for c/cpp test mode codegen
Bug: b/300488560 Test: added unit test and tested with AconfigDemoActivity app Change-Id: I6ad71cc2dada8feb53662ec47c8acad5bc43d5ce
This commit is contained in:
parent
faa7c7c102
commit
c5e39f521b
4 changed files with 83 additions and 1 deletions
|
@ -32,6 +32,8 @@ bootstrap_go_package {
|
|||
"aconfig_values_test.go",
|
||||
"aconfig_value_set_test.go",
|
||||
"java_aconfig_library_test.go",
|
||||
"cc_aconfig_library_test.go",
|
||||
"rust_aconfig_library_test.go",
|
||||
],
|
||||
pluginFor: ["soong_build"],
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@ package aconfig
|
|||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
|
||||
"fmt"
|
||||
"strings"
|
||||
|
@ -32,6 +34,9 @@ var ccDeclarationsTag = ccDeclarationsTagType{}
|
|||
type CcAconfigLibraryProperties struct {
|
||||
// name of the aconfig_declarations module to generate a library for
|
||||
Aconfig_declarations string
|
||||
|
||||
// whether to generate test mode version of the library
|
||||
Test *bool
|
||||
}
|
||||
|
||||
type CcAconfigLibraryCallbacks struct {
|
||||
|
@ -113,6 +118,12 @@ func (this *CcAconfigLibraryCallbacks) GeneratorBuildActions(ctx cc.ModuleContex
|
|||
}
|
||||
declarations := ctx.OtherModuleProvider(declarationsModules[0], declarationsProviderKey).(declarationsProviderData)
|
||||
|
||||
var mode string
|
||||
if proptools.Bool(this.properties.Test) {
|
||||
mode = "test"
|
||||
} else {
|
||||
mode = "production"
|
||||
}
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: cppRule,
|
||||
Input: declarations.IntermediatePath,
|
||||
|
@ -123,6 +134,7 @@ func (this *CcAconfigLibraryCallbacks) GeneratorBuildActions(ctx cc.ModuleContex
|
|||
Description: "cc_aconfig_library",
|
||||
Args: map[string]string{
|
||||
"gendir": this.generatedDir.String(),
|
||||
"mode": mode,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
67
aconfig/cc_aconfig_library_test.go
Normal file
67
aconfig/cc_aconfig_library_test.go
Normal file
|
@ -0,0 +1,67 @@
|
|||
// Copyright 2023 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 aconfig
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
)
|
||||
|
||||
var codegenModeTestData = []struct {
|
||||
setting, expected string
|
||||
}{
|
||||
{"", "production"},
|
||||
{"test: false,", "production"},
|
||||
{"test: true,", "test"},
|
||||
}
|
||||
|
||||
func TestCCCodegenMode(t *testing.T) {
|
||||
for _, testData := range codegenModeTestData {
|
||||
testCCCodegenModeHelper(t, testData.setting, testData.expected)
|
||||
}
|
||||
}
|
||||
|
||||
func testCCCodegenModeHelper(t *testing.T, bpMode string, ruleMode string) {
|
||||
t.Helper()
|
||||
result := android.GroupFixturePreparers(
|
||||
PrepareForTestWithAconfigBuildComponents,
|
||||
cc.PrepareForTestWithCcDefaultModules).
|
||||
ExtendWithErrorHandler(android.FixtureExpectsNoErrors).
|
||||
RunTestWithBp(t, fmt.Sprintf(`
|
||||
aconfig_declarations {
|
||||
name: "my_aconfig_declarations",
|
||||
package: "com.example.package",
|
||||
srcs: ["foo.aconfig"],
|
||||
}
|
||||
|
||||
cc_library {
|
||||
name: "server_configurable_flags",
|
||||
srcs: ["server_configurable_flags.cc"],
|
||||
}
|
||||
|
||||
cc_aconfig_library {
|
||||
name: "my_cc_aconfig_library",
|
||||
aconfig_declarations: "my_aconfig_declarations",
|
||||
%s
|
||||
}
|
||||
`, bpMode))
|
||||
|
||||
module := result.ModuleForTests("my_cc_aconfig_library", "android_arm64_armv8-a_shared")
|
||||
rule := module.Rule("cc_aconfig_library")
|
||||
android.AssertStringEquals(t, "rule must contain test mode", rule.Args["mode"], ruleMode)
|
||||
}
|
|
@ -64,13 +64,14 @@ var (
|
|||
Command: `rm -rf ${gendir}` +
|
||||
` && mkdir -p ${gendir}` +
|
||||
` && ${aconfig} create-cpp-lib` +
|
||||
` --mode ${mode}` +
|
||||
` --cache ${in}` +
|
||||
` --out ${gendir}`,
|
||||
CommandDeps: []string{
|
||||
"$aconfig",
|
||||
"$soong_zip",
|
||||
},
|
||||
}, "gendir")
|
||||
}, "gendir", "mode")
|
||||
|
||||
rustRule = pctx.AndroidStaticRule("rust_aconfig_library",
|
||||
blueprint.RuleParams{
|
||||
|
|
Loading…
Reference in a new issue