• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2017 The Android Open Source Project
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 hidl
16
17import (
18	"sync"
19
20	"github.com/google/blueprint/proptools"
21
22	"android/soong/android"
23)
24
25func init() {
26	android.RegisterModuleType("hidl_package_root", hidlPackageRootFactory)
27}
28
29type hidlPackageRoot struct {
30	android.ModuleBase
31
32	properties struct {
33		// Path to the package root from android build root. It is recommended not to set this and
34		// use the current path. This will be deprecated in the future.
35		Path *string
36
37		// True to require a current.txt API file here.
38		//
39		// When false, it uses the file only when it exists.
40		Use_current *bool
41	}
42
43	currentPath android.OptionalPath
44}
45
46func (r *hidlPackageRoot) getFullPackageRoot() string {
47	return "-r" + r.Name() + ":" + *r.properties.Path
48}
49
50func (r *hidlPackageRoot) getCurrentPath() android.OptionalPath {
51	return r.currentPath
52}
53
54func (r *hidlPackageRoot) GenerateAndroidBuildActions(ctx android.ModuleContext) {
55	if r.properties.Path == nil {
56		r.properties.Path = proptools.StringPtr(ctx.ModuleDir())
57	}
58
59	if proptools.BoolDefault(r.properties.Use_current, false) {
60		r.currentPath = android.OptionalPathForPath(android.PathForModuleSrc(ctx, "current.txt"))
61	} else {
62		r.currentPath = android.ExistentPathForSource(ctx, ctx.ModuleDir(), "current.txt")
63	}
64}
65func (r *hidlPackageRoot) DepsMutator(ctx android.BottomUpMutatorContext) {
66}
67
68var packageRootsMutex sync.Mutex
69var packageRoots []*hidlPackageRoot
70
71func hidlPackageRootFactory() android.Module {
72	r := &hidlPackageRoot{}
73	r.AddProperties(&r.properties)
74	android.InitAndroidModule(r)
75
76	packageRootsMutex.Lock()
77	packageRoots = append(packageRoots, r)
78	packageRootsMutex.Unlock()
79
80	return r
81}
82
83func lookupPackageRoot(name string) *hidlPackageRoot {
84	for _, i := range packageRoots {
85		if i.ModuleBase.Name() == name {
86			return i
87		}
88	}
89	return nil
90}
91