prebuilt_etc: Improve comments and slight refactoring

Comment changes:
* Add top level package description.
* Clarify `OutputFileProducer` usage for `prebuilt_etc.src` field.
* Clarify output file basename selection rule.

Refactor changes:
* Don't emit superfluous `LOCAL_UNINSTALLABLE_MODULE := false` lines.
* `for _, i := range list { entry.AddStrings(prop, i) }` =>
  `entry.AddStrings(prop, list...)`

Bug: 173379413
Test: TH presubmit
Change-Id: Iab90aea5ff2497525ebe1600d3ce5a480923760a
This commit is contained in:
Yo Chiang 2020-11-16 20:32:51 +08:00
parent 99a7622885
commit 803c40daa2
1 changed files with 21 additions and 7 deletions

View File

@ -14,9 +14,20 @@
package etc package etc
import ( // This file implements module types that install prebuilt artifacts.
"strconv" //
// There exist two classes of prebuilt modules in the Android tree. The first class are the ones
// based on `android.Prebuilt`, such as `cc_prebuilt_library` and `java_import`. This kind of
// modules may exist both as prebuilts and source at the same time, though only one would be
// installed and the other would be marked disabled. The `prebuilt_postdeps` mutator would select
// the actual modules to be installed. More details in android/prebuilt.go.
//
// The second class is described in this file. Unlike `android.Prebuilt` based module types,
// `prebuilt_etc` exist only as prebuilts and cannot have a same-named source module counterpart.
// This makes the logic of `prebuilt_etc` to be much simpler as they don't need to go through the
// various `prebuilt_*` mutators.
import (
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
"android/soong/android" "android/soong/android"
@ -42,7 +53,7 @@ func RegisterPrebuiltEtcBuildComponents(ctx android.RegistrationContext) {
} }
type prebuiltEtcProperties struct { type prebuiltEtcProperties struct {
// Source file of this prebuilt. // Source file of this prebuilt. Can reference a genrule type module with the ":module" syntax.
Src *string `android:"path,arch_variant"` Src *string `android:"path,arch_variant"`
// optional subdirectory under which this file is installed into, cannot be specified with relative_install_path, prefer relative_install_path // optional subdirectory under which this file is installed into, cannot be specified with relative_install_path, prefer relative_install_path
@ -209,6 +220,11 @@ func (p *PrebuiltEtc) Installable() bool {
func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
p.sourceFilePath = android.PathForModuleSrc(ctx, android.String(p.properties.Src)) p.sourceFilePath = android.PathForModuleSrc(ctx, android.String(p.properties.Src))
// Determine the output file basename.
// If Filename is set, use the name specified by the property.
// If Filename_from_src is set, use the source file name.
// Otherwise use the module name.
filename := android.String(p.properties.Filename) filename := android.String(p.properties.Filename)
filename_from_src := android.Bool(p.properties.Filename_from_src) filename_from_src := android.Bool(p.properties.Filename_from_src)
if filename == "" { if filename == "" {
@ -274,11 +290,9 @@ func (p *PrebuiltEtc) AndroidMkEntries() []android.AndroidMkEntries {
if len(p.properties.Symlinks) > 0 { if len(p.properties.Symlinks) > 0 {
entries.AddStrings("LOCAL_MODULE_SYMLINKS", p.properties.Symlinks...) entries.AddStrings("LOCAL_MODULE_SYMLINKS", p.properties.Symlinks...)
} }
entries.SetString("LOCAL_UNINSTALLABLE_MODULE", strconv.FormatBool(!p.Installable())) entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.Installable())
if p.additionalDependencies != nil { if p.additionalDependencies != nil {
for _, path := range *p.additionalDependencies { entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", p.additionalDependencies.Strings()...)
entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", path.String())
}
} }
}, },
}, },