blob: 0b84d44b8ddfebcfb6cadd6ba5533e7df81be5e7 [file] [log] [blame]
Colin Crossc0b06f12015-04-08 13:03:43 -07001// 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 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
21import (
22 "path/filepath"
23 "strings"
24
25 "github.com/google/blueprint"
26 "github.com/google/blueprint/pathtools"
27
28 "android/soong/common"
29)
30
31func 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
38var (
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
47func 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
67func 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}