Colin Cross | c0b06f1 | 2015-04-08 13:03:43 -0700 | [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 java |
| 16 | |
| 17 | // This file generates the final rules for compiling all C/C++. All properties related to |
| 18 | // compiling should have been translated into builderFlags or another argument to the Transform* |
| 19 | // functions. |
| 20 | |
| 21 | import ( |
| 22 | "path/filepath" |
| 23 | "strings" |
| 24 | |
| 25 | "github.com/google/blueprint" |
| 26 | "github.com/google/blueprint/pathtools" |
| 27 | |
| 28 | "android/soong/common" |
| 29 | ) |
| 30 | |
| 31 | func init() { |
| 32 | pctx.VariableFunc("aidlCmd", func(c interface{}) (string, error) { |
| 33 | return c.(common.Config).HostBinTool("aidl") |
| 34 | }) |
| 35 | pctx.VariableConfigMethod("srcDir", common.Config.SrcDir) |
| 36 | } |
| 37 | |
| 38 | var ( |
| 39 | aidl = pctx.StaticRule("aidl", |
| 40 | blueprint.RuleParams{ |
| 41 | Command: "$aidlCmd -d$depFile $aidlFlags $in $out", |
| 42 | Description: "aidl $out", |
| 43 | }, |
| 44 | "depFile", "aidlFlags") |
| 45 | ) |
| 46 | |
| 47 | func genAidl(ctx common.AndroidModuleContext, aidlFile, aidlFlags string) string { |
| 48 | javaFile := strings.TrimPrefix(aidlFile, common.ModuleSrcDir(ctx)) |
| 49 | javaFile = filepath.Join(common.ModuleGenDir(ctx), javaFile) |
| 50 | javaFile = pathtools.ReplaceExtension(javaFile, "java") |
| 51 | depFile := javaFile + ".d" |
| 52 | |
| 53 | ctx.Build(pctx, blueprint.BuildParams{ |
| 54 | Rule: aidl, |
| 55 | Outputs: []string{javaFile}, |
| 56 | Inputs: []string{aidlFile}, |
| 57 | Implicits: []string{"$aidlCmd"}, |
| 58 | Args: map[string]string{ |
| 59 | "depFile": depFile, |
| 60 | "aidlFlags": aidlFlags, |
| 61 | }, |
| 62 | }) |
| 63 | |
| 64 | return javaFile |
| 65 | } |
| 66 | |
| 67 | func genSources(ctx common.AndroidModuleContext, srcFiles []string, |
| 68 | flags javaBuilderFlags) []string { |
| 69 | |
| 70 | for i, srcFile := range srcFiles { |
| 71 | switch filepath.Ext(srcFile) { |
| 72 | case ".aidl": |
| 73 | javaFile := genAidl(ctx, srcFile, flags.aidlFlags) |
| 74 | srcFiles[i] = javaFile |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | return srcFiles |
| 79 | } |