Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1 | // 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 | |
| 15 | package common |
| 16 | |
| 17 | import ( |
| 18 | "path/filepath" |
Colin Cross | f229827 | 2015-05-12 11:36:53 -0700 | [diff] [blame^] | 19 | "os" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 20 | ) |
| 21 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 22 | // ModuleOutDir returns the path to the module-specific output directory. |
| 23 | func ModuleOutDir(ctx AndroidModuleContext) string { |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 24 | return filepath.Join(ctx.AConfig().IntermediatesDir(), |
| 25 | ctx.ModuleDir(), ctx.ModuleName(), ctx.ModuleSubDir()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | // ModuleSrcDir returns the path of the directory that all source file paths are |
| 29 | // specified relative to. |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 30 | func ModuleSrcDir(ctx AndroidModuleContext) string { |
| 31 | return filepath.Join(ctx.AConfig().SrcDir(), ctx.ModuleDir()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | // ModuleBinDir returns the path to the module- and architecture-specific binary |
| 35 | // output directory. |
| 36 | func 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. |
| 42 | func ModuleLibDir(ctx AndroidModuleContext) string { |
| 43 | return filepath.Join(ModuleOutDir(ctx), "lib") |
| 44 | } |
| 45 | |
| 46 | // ModuleGenDir returns the module directory for generated files |
| 47 | // path. |
| 48 | func 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. |
| 54 | func 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. |
| 61 | func ModuleGoPackageDir(ctx AndroidModuleContext) string { |
| 62 | return filepath.Join(ModuleOutDir(ctx), "pkg") |
| 63 | } |
| 64 | |
| 65 | // ModuleIncludeDir returns the module-specific public include directory path. |
| 66 | func ModuleIncludeDir(ctx AndroidModuleContext) string { |
| 67 | return filepath.Join(ModuleOutDir(ctx), "include") |
| 68 | } |
| 69 | |
| 70 | // ModuleProtoDir returns the module-specific public proto include directory path. |
| 71 | func ModuleProtoDir(ctx AndroidModuleContext) string { |
| 72 | return filepath.Join(ModuleOutDir(ctx), "proto") |
| 73 | } |
| 74 | |
| 75 | func ModuleJSCompiledDir(ctx AndroidModuleContext) string { |
| 76 | return filepath.Join(ModuleOutDir(ctx), "js") |
| 77 | } |
Colin Cross | f229827 | 2015-05-12 11:36:53 -0700 | [diff] [blame^] | 78 | |
| 79 | // CheckModuleSrcDirsExist logs an error on a property if any of the directories relative to the |
| 80 | // Blueprints file don't exist. |
| 81 | func 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. |
| 96 | func 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 | } |