1// Copyright 2022 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 multitree
16
17import (
18	"android/soong/android"
19
20	"github.com/google/blueprint/proptools"
21)
22
23type moduleExportProperty struct {
24	// True if the module is exported to the other components in a multi-tree.
25	// Any components in the multi-tree can import this module to use.
26	Export *bool
27}
28
29type ExportableModuleBase struct {
30	properties moduleExportProperty
31}
32
33type Exportable interface {
34	// Properties for the exporable module.
35	exportableModuleProps() *moduleExportProperty
36
37	// Check if this module can be exported.
38	// If this returns false, the module will not be exported regardless of the 'export' value.
39	Exportable() bool
40
41	// Returns 'true' if this module has 'export: true'
42	// This module will not be exported if it returns 'false' to 'Exportable()' interface even if
43	// it has 'export: true'.
44	IsExported() bool
45
46	// Map from tags to outputs.
47	// Each module can tag their outputs for convenience.
48	TaggedOutputs() map[string]android.Paths
49}
50
51type ExportableModule interface {
52	android.Module
53	android.OutputFileProducer
54	Exportable
55}
56
57func InitExportableModule(module ExportableModule) {
58	module.AddProperties(module.exportableModuleProps())
59}
60
61func (m *ExportableModuleBase) exportableModuleProps() *moduleExportProperty {
62	return &m.properties
63}
64
65func (m *ExportableModuleBase) IsExported() bool {
66	return proptools.Bool(m.properties.Export)
67}
68