1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
// Copyright (C) 2024 The Android Open Source Project
//
// 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 filesystem
import (
"android/soong/android"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
type PartitionNameProperties struct {
// Name of the boot partition filesystem module
Boot_partition_name *string
// Name of the vendor boot partition filesystem module
Vendor_boot_partition_name *string
// Name of the init boot partition filesystem module
Init_boot_partition_name *string
// Name of the system partition filesystem module
System_partition_name *string
// Name of the system_ext partition filesystem module
System_ext_partition_name *string
// Name of the product partition filesystem module
Product_partition_name *string
// Name of the vendor partition filesystem module
Vendor_partition_name *string
// Name of the odm partition filesystem module
Odm_partition_name *string
// Name of the recovery partition filesystem module
Recovery_partition_name *string
// The vbmeta partition and its "chained" partitions
Vbmeta_partitions []string
// Name of the userdata partition filesystem module
Userdata_partition_name *string
}
type androidDevice struct {
android.ModuleBase
partitionProps PartitionNameProperties
}
func AndroidDeviceFactory() android.Module {
module := &androidDevice{}
module.AddProperties(&module.partitionProps)
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
return module
}
type partitionDepTagType struct {
blueprint.BaseDependencyTag
}
var filesystemDepTag partitionDepTagType
func (a *androidDevice) DepsMutator(ctx android.BottomUpMutatorContext) {
addDependencyIfDefined := func(dep *string) {
if dep != nil {
ctx.AddFarVariationDependencies(nil, filesystemDepTag, proptools.String(dep))
}
}
addDependencyIfDefined(a.partitionProps.Boot_partition_name)
addDependencyIfDefined(a.partitionProps.System_partition_name)
addDependencyIfDefined(a.partitionProps.System_ext_partition_name)
addDependencyIfDefined(a.partitionProps.Product_partition_name)
addDependencyIfDefined(a.partitionProps.Vendor_partition_name)
addDependencyIfDefined(a.partitionProps.Odm_partition_name)
addDependencyIfDefined(a.partitionProps.Userdata_partition_name)
for _, vbmetaPartition := range a.partitionProps.Vbmeta_partitions {
ctx.AddDependency(ctx.Module(), filesystemDepTag, vbmetaPartition)
}
}
func (a *androidDevice) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.buildTargetFilesZip(ctx)
}
func (a *androidDevice) buildTargetFilesZip(ctx android.ModuleContext) {
targetFilesDir := android.PathForModuleOut(ctx, "target_files_dir")
targetFilesZip := android.PathForModuleOut(ctx, "target_files.zip")
builder := android.NewRuleBuilder(pctx, ctx)
builder.Command().Textf("rm -rf %s", targetFilesDir.String())
builder.Command().Textf("mkdir -p %s", targetFilesDir.String())
if a.partitionProps.Vendor_partition_name != nil {
fsInfo := a.getFilesystemInfo(ctx, *a.partitionProps.Vendor_partition_name)
builder.Command().Textf("mkdir -p %s/VENDOR", targetFilesDir.String())
builder.Command().
BuiltTool("acp").
Textf("-rd %s/. %s/VENDOR", fsInfo.RootDir, targetFilesDir).
Implicit(fsInfo.Output) // so that the staging dir is built
}
builder.Command().
BuiltTool("soong_zip").
Text("-d").
FlagWithOutput("-o ", targetFilesZip).
FlagWithArg("-C ", targetFilesDir.String()).
FlagWithArg("-D ", targetFilesDir.String()).
Text("-sha256")
builder.Build("target_files_"+ctx.ModuleName(), "Build target_files.zip")
}
func (a *androidDevice) getFilesystemInfo(ctx android.ModuleContext, depName string) FilesystemInfo {
fsMod := ctx.GetDirectDepWithTag(depName, filesystemDepTag)
fsInfo, ok := android.OtherModuleProvider(ctx, fsMod, FilesystemProvider)
if !ok {
ctx.ModuleErrorf("Expected dependency %s to be a filesystem", depName)
}
return fsInfo
}
|