• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package selinux
16
17import (
18	"android/soong/android"
19	"path/filepath"
20)
21
22func init() {
23	android.RegisterModuleType("se_filegroup", FileGroupFactory)
24}
25
26func FileGroupFactory() android.Module {
27	module := &fileGroup{}
28	module.AddProperties(&module.properties)
29	android.InitAndroidModule(module)
30	return module
31}
32
33type fileGroupProperties struct {
34	// list of source file suffixes used to collect selinux policy files.
35	// Source files will be looked up in the following local directories:
36	// system/sepolicy/{public, private, vendor, reqd_mask}
37	// and directories specified by following config variables:
38	// BOARD_SEPOLICY_DIRS, BOARD_ODM_SEPOLICY_DIRS
39	// BOARD_PLAT_PUBLIC_SEPOLICY_DIR, BOARD_PLAT_PRIVATE_SEPOLICY_DIR
40	Srcs []string
41}
42
43type fileGroup struct {
44	android.ModuleBase
45	properties fileGroupProperties
46
47	systemPublicSrcs   android.Paths
48	systemPrivateSrcs  android.Paths
49	systemVendorSrcs   android.Paths
50	systemReqdMaskSrcs android.Paths
51
52	systemExtPublicSrcs  android.Paths
53	systemExtPrivateSrcs android.Paths
54
55	vendorSrcs android.Paths
56	odmSrcs    android.Paths
57}
58
59// Source files from system/sepolicy/public
60func (fg *fileGroup) SystemPublicSrcs() android.Paths {
61	return fg.systemPublicSrcs
62}
63
64// Source files from system/sepolicy/private
65func (fg *fileGroup) SystemPrivateSrcs() android.Paths {
66	return fg.systemPrivateSrcs
67}
68
69// Source files from system/sepolicy/vendor
70func (fg *fileGroup) SystemVendorSrcs() android.Paths {
71	return fg.systemVendorSrcs
72}
73
74// Source files from system/sepolicy/reqd_mask
75func (fg *fileGroup) SystemReqdMaskSrcs() android.Paths {
76	return fg.systemReqdMaskSrcs
77}
78
79// Source files from BOARD_PLAT_PUBLIC_SEPOLICY_DIR
80func (fg *fileGroup) SystemExtPublicSrcs() android.Paths {
81	return fg.systemExtPublicSrcs
82}
83
84// Source files from BOARD_PLAT_PRIVATE_SEPOLICY_DIR
85func (fg *fileGroup) SystemExtPrivateSrcs() android.Paths {
86	return fg.systemExtPrivateSrcs
87}
88
89// Source files from BOARD_SEPOLICY_DIRS
90func (fg *fileGroup) VendorSrcs() android.Paths {
91	return fg.vendorSrcs
92}
93
94// Source files from BOARD_ODM_SEPOLICY_DIRS
95func (fg *fileGroup) OdmSrcs() android.Paths {
96	return fg.odmSrcs
97}
98
99func (fg *fileGroup) findSrcsInDirs(ctx android.ModuleContext, dirs []string) android.Paths {
100	result := android.Paths{}
101	for _, f := range fg.properties.Srcs {
102		for _, d := range dirs {
103			path := filepath.Join(d, f)
104			files, _ := ctx.GlobWithDeps(path, nil)
105			for _, f := range files {
106				result = append(result, android.PathForSource(ctx, f))
107			}
108		}
109	}
110	return result
111}
112
113func (fg *fileGroup) findSrcsInDir(ctx android.ModuleContext, dir string) android.Paths {
114	return fg.findSrcsInDirs(ctx, []string{dir})
115}
116
117func (fg *fileGroup) DepsMutator(ctx android.BottomUpMutatorContext) {}
118
119func (fg *fileGroup) GenerateAndroidBuildActions(ctx android.ModuleContext) {
120	fg.systemPublicSrcs = fg.findSrcsInDir(ctx, filepath.Join(ctx.ModuleDir(), "public"))
121	fg.systemPrivateSrcs = fg.findSrcsInDir(ctx, filepath.Join(ctx.ModuleDir(), "private"))
122	fg.systemVendorSrcs = fg.findSrcsInDir(ctx, filepath.Join(ctx.ModuleDir(), "vendor"))
123	fg.systemReqdMaskSrcs = fg.findSrcsInDir(ctx, filepath.Join(ctx.ModuleDir(), "reqd_mask"))
124
125	fg.systemExtPublicSrcs = fg.findSrcsInDirs(ctx, ctx.DeviceConfig().PlatPublicSepolicyDirs())
126	fg.systemExtPrivateSrcs = fg.findSrcsInDirs(ctx, ctx.DeviceConfig().PlatPrivateSepolicyDirs())
127
128	fg.vendorSrcs = fg.findSrcsInDirs(ctx, ctx.DeviceConfig().VendorSepolicyDirs())
129	fg.odmSrcs = fg.findSrcsInDirs(ctx, ctx.DeviceConfig().OdmSepolicyDirs())
130}
131