blob: 070662adbb9960019f0a29221aaedfc6e395c1d6 [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// Copyright 2015 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 common
16
17import (
18 "path/filepath"
Colin Crossf2298272015-05-12 11:36:53 -070019 "os"
Colin Cross3f40fa42015-01-30 17:27:36 -080020)
21
Colin Cross3f40fa42015-01-30 17:27:36 -080022// ModuleOutDir returns the path to the module-specific output directory.
23func ModuleOutDir(ctx AndroidModuleContext) string {
Colin Cross1332b002015-04-07 17:11:30 -070024 return filepath.Join(ctx.AConfig().IntermediatesDir(),
25 ctx.ModuleDir(), ctx.ModuleName(), ctx.ModuleSubDir())
Colin Cross3f40fa42015-01-30 17:27:36 -080026}
27
28// ModuleSrcDir returns the path of the directory that all source file paths are
29// specified relative to.
Colin Cross1332b002015-04-07 17:11:30 -070030func ModuleSrcDir(ctx AndroidModuleContext) string {
31 return filepath.Join(ctx.AConfig().SrcDir(), ctx.ModuleDir())
Colin Cross3f40fa42015-01-30 17:27:36 -080032}
33
34// ModuleBinDir returns the path to the module- and architecture-specific binary
35// output directory.
36func ModuleBinDir(ctx AndroidModuleContext) string {
37 return filepath.Join(ModuleOutDir(ctx), "bin")
38}
39
40// ModuleLibDir returns the path to the module- and architecture-specific
41// library output directory.
42func ModuleLibDir(ctx AndroidModuleContext) string {
43 return filepath.Join(ModuleOutDir(ctx), "lib")
44}
45
46// ModuleGenDir returns the module directory for generated files
47// path.
48func ModuleGenDir(ctx AndroidModuleContext) string {
49 return filepath.Join(ModuleOutDir(ctx), "gen")
50}
51
52// ModuleObjDir returns the module- and architecture-specific object directory
53// path.
54func ModuleObjDir(ctx AndroidModuleContext) string {
55 return filepath.Join(ModuleOutDir(ctx), "obj")
56}
57
58// ModuleGoPackageDir returns the module-specific package root directory path.
59// This directory is where the final package .a files are output and where
60// dependent modules search for this package via -I arguments.
61func ModuleGoPackageDir(ctx AndroidModuleContext) string {
62 return filepath.Join(ModuleOutDir(ctx), "pkg")
63}
64
65// ModuleIncludeDir returns the module-specific public include directory path.
66func ModuleIncludeDir(ctx AndroidModuleContext) string {
67 return filepath.Join(ModuleOutDir(ctx), "include")
68}
69
70// ModuleProtoDir returns the module-specific public proto include directory path.
71func ModuleProtoDir(ctx AndroidModuleContext) string {
72 return filepath.Join(ModuleOutDir(ctx), "proto")
73}
74
75func ModuleJSCompiledDir(ctx AndroidModuleContext) string {
76 return filepath.Join(ModuleOutDir(ctx), "js")
77}
Colin Crossf2298272015-05-12 11:36:53 -070078
79// CheckModuleSrcDirsExist logs an error on a property if any of the directories relative to the
80// Blueprints file don't exist.
81func CheckModuleSrcDirsExist(ctx AndroidModuleContext, dirs []string, prop string) {
82 for _, dir := range dirs {
83 fullDir := filepath.Join(ModuleSrcDir(ctx), dir)
84 if _, err := os.Stat(fullDir); err != nil {
85 if os.IsNotExist(err) {
86 ctx.PropertyErrorf(prop, "module source directory %q does not exist", dir)
87 } else {
88 ctx.PropertyErrorf(prop, "%s", err.Error())
89 }
90 }
91 }
92}
93
94// CheckModuleSrcDirsExist logs an error on a property if any of the directories relative to the
95// top of the source tree don't exist.
96func CheckSrcDirsExist(ctx AndroidModuleContext, dirs []string, prop string) {
97 for _, dir := range dirs {
98 fullDir := filepath.Join(ctx.AConfig().SrcDir(), dir)
99 if _, err := os.Stat(fullDir); err != nil {
100 if os.IsNotExist(err) {
101 ctx.PropertyErrorf(prop, "top-level source directory %q does not exist", dir)
102 } else {
103 ctx.PropertyErrorf(prop, "%s", err.Error())
104 }
105 }
106 }
107}