2017-02-05 02:47:46 +01:00
|
|
|
// Copyright 2016 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 phony
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2024-07-23 09:26:01 +02:00
|
|
|
|
|
|
|
"github.com/google/blueprint/proptools"
|
2017-02-05 02:47:46 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2024-03-26 02:47:18 +01:00
|
|
|
registerPhonyModuleTypes(android.InitRegistrationContext)
|
2017-02-05 02:47:46 +01:00
|
|
|
}
|
|
|
|
|
2024-03-26 02:47:18 +01:00
|
|
|
func registerPhonyModuleTypes(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("phony", PhonyFactory)
|
|
|
|
ctx.RegisterModuleType("phony_rule", PhonyRuleFactory)
|
2024-04-01 05:30:56 +02:00
|
|
|
ctx.RegisterModuleType("phony_rule_defaults", PhonyRuleDefaultsFactory)
|
2024-03-26 02:47:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var PrepareForTestWithPhony = android.FixtureRegisterWithContext(registerPhonyModuleTypes)
|
|
|
|
|
2017-02-05 02:47:46 +01:00
|
|
|
type phony struct {
|
|
|
|
android.ModuleBase
|
2019-04-02 03:37:36 +02:00
|
|
|
requiredModuleNames []string
|
|
|
|
hostRequiredModuleNames []string
|
|
|
|
targetRequiredModuleNames []string
|
2017-02-05 02:47:46 +01:00
|
|
|
}
|
|
|
|
|
2018-07-12 00:24:31 +02:00
|
|
|
func PhonyFactory() android.Module {
|
2017-02-05 02:47:46 +01:00
|
|
|
module := &phony{}
|
|
|
|
|
2019-04-03 02:04:18 +02:00
|
|
|
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
|
2017-06-24 00:06:31 +02:00
|
|
|
return module
|
2017-02-05 02:47:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *phony) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2024-06-17 21:32:40 +02:00
|
|
|
p.requiredModuleNames = ctx.RequiredModuleNames(ctx)
|
2019-04-02 03:37:36 +02:00
|
|
|
p.hostRequiredModuleNames = ctx.HostRequiredModuleNames()
|
|
|
|
p.targetRequiredModuleNames = ctx.TargetRequiredModuleNames()
|
2017-02-05 02:47:46 +01:00
|
|
|
}
|
|
|
|
|
2017-08-11 02:00:19 +02:00
|
|
|
func (p *phony) AndroidMk() android.AndroidMkData {
|
|
|
|
return android.AndroidMkData{
|
2017-08-11 02:07:28 +02:00
|
|
|
Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
|
2022-12-01 19:49:23 +01:00
|
|
|
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)", " # phony.phony")
|
2017-08-11 02:00:19 +02:00
|
|
|
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
|
|
|
|
fmt.Fprintln(w, "LOCAL_MODULE :=", name)
|
2019-04-03 02:04:18 +02:00
|
|
|
if p.Host() {
|
|
|
|
fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
|
|
|
|
}
|
2019-04-02 03:37:36 +02:00
|
|
|
if len(p.requiredModuleNames) > 0 {
|
|
|
|
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=",
|
|
|
|
strings.Join(p.requiredModuleNames, " "))
|
|
|
|
}
|
|
|
|
if len(p.hostRequiredModuleNames) > 0 {
|
|
|
|
fmt.Fprintln(w, "LOCAL_HOST_REQUIRED_MODULES :=",
|
|
|
|
strings.Join(p.hostRequiredModuleNames, " "))
|
|
|
|
}
|
|
|
|
if len(p.targetRequiredModuleNames) > 0 {
|
|
|
|
fmt.Fprintln(w, "LOCAL_TARGET_REQUIRED_MODULES :=",
|
|
|
|
strings.Join(p.targetRequiredModuleNames, " "))
|
|
|
|
}
|
2024-01-11 00:42:36 +01:00
|
|
|
// AconfigUpdateAndroidMkData may have added elements to Extra. Process them here.
|
|
|
|
for _, extra := range data.Extra {
|
|
|
|
extra(w, nil)
|
|
|
|
}
|
2017-08-11 02:00:19 +02:00
|
|
|
fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
|
|
|
|
},
|
2017-02-05 02:47:46 +01:00
|
|
|
}
|
|
|
|
}
|
2023-12-20 03:37:52 +01:00
|
|
|
|
|
|
|
type PhonyRule struct {
|
|
|
|
android.ModuleBase
|
2024-04-01 05:30:56 +02:00
|
|
|
android.DefaultableModuleBase
|
2023-12-20 03:37:52 +01:00
|
|
|
|
2024-07-23 09:26:01 +02:00
|
|
|
phonyDepsModuleNames []string
|
|
|
|
properties PhonyProperties
|
2023-12-20 03:37:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type PhonyProperties struct {
|
|
|
|
// The Phony_deps is the set of all dependencies for this target,
|
|
|
|
// and it can function similarly to .PHONY in a makefile.
|
|
|
|
// Additionally, dependencies within it can even include genrule.
|
2024-07-23 09:26:01 +02:00
|
|
|
Phony_deps proptools.Configurable[[]string]
|
2023-12-20 03:37:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// The phony_rule provides functionality similar to the .PHONY in a makefile.
|
|
|
|
// It can create a phony target and include relevant dependencies associated with it.
|
|
|
|
func PhonyRuleFactory() android.Module {
|
|
|
|
module := &PhonyRule{}
|
|
|
|
android.InitAndroidModule(module)
|
|
|
|
module.AddProperties(&module.properties)
|
2024-04-01 05:30:56 +02:00
|
|
|
android.InitDefaultableModule(module)
|
2023-12-20 03:37:52 +01:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PhonyRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2024-07-29 21:24:25 +02:00
|
|
|
p.phonyDepsModuleNames = p.properties.Phony_deps.GetOrDefault(ctx, nil)
|
2023-12-20 03:37:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PhonyRule) AndroidMk() android.AndroidMkData {
|
|
|
|
return android.AndroidMkData{
|
|
|
|
Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
|
2024-07-23 09:26:01 +02:00
|
|
|
if len(p.phonyDepsModuleNames) > 0 {
|
|
|
|
depModulesStr := strings.Join(p.phonyDepsModuleNames, " ")
|
2023-12-20 03:37:52 +01:00
|
|
|
fmt.Fprintln(w, ".PHONY:", name)
|
|
|
|
fmt.Fprintln(w, name, ":", depModulesStr)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2024-04-01 05:30:56 +02:00
|
|
|
|
|
|
|
// PhonyRuleDefaults
|
|
|
|
type PhonyRuleDefaults struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultsModuleBase
|
|
|
|
}
|
|
|
|
|
|
|
|
// phony_rule_defaults provides a set of properties that can be inherited by other phony_rules.
|
|
|
|
//
|
|
|
|
// A module can use the properties from a phony_rule_defaults module using `defaults: ["defaults_module_name"]`. Each
|
|
|
|
// property in the defaults module that exists in the depending module will be prepended to the depending module's
|
|
|
|
// value for that property.
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// phony_rule_defaults {
|
|
|
|
// name: "add_module1_defaults",
|
|
|
|
// phony_deps: [
|
|
|
|
// "module1",
|
|
|
|
// ],
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// phony_rule {
|
|
|
|
// name: "example",
|
|
|
|
// defaults: ["add_module1_defaults"],
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// is functionally identical to:
|
|
|
|
//
|
|
|
|
// phony_rule {
|
|
|
|
// name: "example",
|
|
|
|
// phony_deps: [
|
|
|
|
// "module1",
|
|
|
|
// ],
|
|
|
|
// }
|
|
|
|
func PhonyRuleDefaultsFactory() android.Module {
|
|
|
|
module := &PhonyRuleDefaults{}
|
|
|
|
module.AddProperties(&PhonyProperties{})
|
|
|
|
android.InitDefaultsModule(module)
|
|
|
|
|
|
|
|
return module
|
|
|
|
}
|