• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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	"github.com/google/blueprint"
23
24	"android/soong/common"
25)
26
27func init() {
28	pctx.HostBinToolVariable("aidlCmd", "aidl")
29	pctx.SourcePathVariable("logtagsCmd", "build/tools/java-event-log-tags.py")
30	pctx.SourcePathVariable("mergeLogtagsCmd", "build/tools/merge-event-log-tags.py")
31
32	pctx.IntermediatesPathVariable("allLogtagsFile", "all-event-log-tags.txt")
33}
34
35var (
36	aidl = pctx.StaticRule("aidl",
37		blueprint.RuleParams{
38			Command:     "$aidlCmd -d$depFile $aidlFlags $in $out",
39			CommandDeps: []string{"$aidlCmd"},
40			Description: "aidl $out",
41		},
42		"depFile", "aidlFlags")
43
44	logtags = pctx.StaticRule("logtags",
45		blueprint.RuleParams{
46			Command:     "$logtagsCmd -o $out $in $allLogtagsFile",
47			CommandDeps: []string{"$logtagsCmd"},
48			Description: "logtags $out",
49		})
50
51	mergeLogtags = pctx.StaticRule("mergeLogtags",
52		blueprint.RuleParams{
53			Command:     "$mergeLogtagsCmd -o $out $in",
54			CommandDeps: []string{"$mergeLogtagsCmd"},
55			Description: "merge logtags $out",
56		})
57)
58
59func genAidl(ctx common.AndroidModuleContext, aidlFile common.Path, aidlFlags string) common.Path {
60	javaFile := common.GenPathWithExt(ctx, aidlFile, "java")
61	depFile := javaFile.String() + ".d"
62
63	ctx.ModuleBuild(pctx, common.ModuleBuildParams{
64		Rule:   aidl,
65		Output: javaFile,
66		Input:  aidlFile,
67		Args: map[string]string{
68			"depFile":   depFile,
69			"aidlFlags": aidlFlags,
70		},
71	})
72
73	return javaFile
74}
75
76func genLogtags(ctx common.AndroidModuleContext, logtagsFile common.Path) common.Path {
77	javaFile := common.GenPathWithExt(ctx, logtagsFile, "java")
78
79	ctx.ModuleBuild(pctx, common.ModuleBuildParams{
80		Rule:   logtags,
81		Output: javaFile,
82		Input:  logtagsFile,
83	})
84
85	return javaFile
86}
87
88func (j *javaBase) genSources(ctx common.AndroidModuleContext, srcFiles common.Paths,
89	flags javaBuilderFlags) common.Paths {
90
91	for i, srcFile := range srcFiles {
92		switch srcFile.Ext() {
93		case ".aidl":
94			javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
95			srcFiles[i] = javaFile
96		case ".logtags":
97			j.logtagsSrcs = append(j.logtagsSrcs, srcFile)
98			javaFile := genLogtags(ctx, srcFile)
99			srcFiles[i] = javaFile
100		}
101	}
102
103	return srcFiles
104}
105
106func LogtagsSingleton() blueprint.Singleton {
107	return &logtagsSingleton{}
108}
109
110type logtagsProducer interface {
111	logtags() common.Paths
112}
113
114type logtagsSingleton struct{}
115
116func (l *logtagsSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
117	var allLogtags common.Paths
118	ctx.VisitAllModules(func(module blueprint.Module) {
119		if logtags, ok := module.(logtagsProducer); ok {
120			allLogtags = append(allLogtags, logtags.logtags()...)
121		}
122	})
123
124	ctx.Build(pctx, blueprint.BuildParams{
125		Rule:    mergeLogtags,
126		Outputs: []string{"$allLogtagsFile"},
127		Inputs:  allLogtags.Strings(),
128	})
129}
130