• 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
17import (
18	"github.com/google/blueprint"
19
20	"android/soong/android"
21)
22
23func init() {
24	pctx.HostBinToolVariable("aidlCmd", "aidl")
25	pctx.HostBinToolVariable("syspropCmd", "sysprop_java")
26	pctx.SourcePathVariable("logtagsCmd", "build/tools/java-event-log-tags.py")
27	pctx.SourcePathVariable("mergeLogtagsCmd", "build/tools/merge-event-log-tags.py")
28}
29
30var (
31	aidl = pctx.AndroidStaticRule("aidl",
32		blueprint.RuleParams{
33			Command:     "$aidlCmd -d$depFile $aidlFlags $in $out",
34			CommandDeps: []string{"$aidlCmd"},
35		},
36		"depFile", "aidlFlags")
37
38	logtags = pctx.AndroidStaticRule("logtags",
39		blueprint.RuleParams{
40			Command:     "$logtagsCmd -o $out $in",
41			CommandDeps: []string{"$logtagsCmd"},
42		})
43
44	mergeLogtags = pctx.AndroidStaticRule("mergeLogtags",
45		blueprint.RuleParams{
46			Command:     "$mergeLogtagsCmd -o $out $in",
47			CommandDeps: []string{"$mergeLogtagsCmd"},
48		})
49
50	sysprop = pctx.AndroidStaticRule("sysprop",
51		blueprint.RuleParams{
52			Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` +
53				`$syspropCmd --java-output-dir $out.tmp $in && ` +
54				`${config.SoongZipCmd} -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
55			CommandDeps: []string{
56				"$syspropCmd",
57				"${config.SoongZipCmd}",
58			},
59		})
60)
61
62func genAidl(ctx android.ModuleContext, aidlFile android.Path, aidlFlags string, deps android.Paths) android.Path {
63	javaFile := android.GenPathWithExt(ctx, "aidl", aidlFile, "java")
64	depFile := javaFile.String() + ".d"
65
66	ctx.Build(pctx, android.BuildParams{
67		Rule:        aidl,
68		Description: "aidl " + aidlFile.Rel(),
69		Output:      javaFile,
70		Input:       aidlFile,
71		Implicits:   deps,
72		Args: map[string]string{
73			"depFile":   depFile,
74			"aidlFlags": aidlFlags,
75		},
76	})
77
78	return javaFile
79}
80
81func genLogtags(ctx android.ModuleContext, logtagsFile android.Path) android.Path {
82	javaFile := android.GenPathWithExt(ctx, "logtags", logtagsFile, "java")
83
84	ctx.Build(pctx, android.BuildParams{
85		Rule:        logtags,
86		Description: "logtags " + logtagsFile.Rel(),
87		Output:      javaFile,
88		Input:       logtagsFile,
89	})
90
91	return javaFile
92}
93
94func genSysprop(ctx android.ModuleContext, syspropFile android.Path) android.Path {
95	srcJarFile := android.GenPathWithExt(ctx, "sysprop", syspropFile, "srcjar")
96
97	ctx.Build(pctx, android.BuildParams{
98		Rule:        sysprop,
99		Description: "sysprop_java " + syspropFile.Rel(),
100		Output:      srcJarFile,
101		Input:       syspropFile,
102	})
103
104	return srcJarFile
105}
106
107func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths,
108	flags javaBuilderFlags) android.Paths {
109
110	outSrcFiles := make(android.Paths, 0, len(srcFiles))
111
112	for _, srcFile := range srcFiles {
113		switch srcFile.Ext() {
114		case ".aidl":
115			javaFile := genAidl(ctx, srcFile, flags.aidlFlags, flags.aidlDeps)
116			outSrcFiles = append(outSrcFiles, javaFile)
117		case ".logtags":
118			j.logtagsSrcs = append(j.logtagsSrcs, srcFile)
119			javaFile := genLogtags(ctx, srcFile)
120			outSrcFiles = append(outSrcFiles, javaFile)
121		case ".proto":
122			srcJarFile := genProto(ctx, srcFile, flags.proto)
123			outSrcFiles = append(outSrcFiles, srcJarFile)
124		case ".sysprop":
125			srcJarFile := genSysprop(ctx, srcFile)
126			outSrcFiles = append(outSrcFiles, srcJarFile)
127		default:
128			outSrcFiles = append(outSrcFiles, srcFile)
129		}
130	}
131
132	return outSrcFiles
133}
134
135func LogtagsSingleton() android.Singleton {
136	return &logtagsSingleton{}
137}
138
139type logtagsProducer interface {
140	logtags() android.Paths
141}
142
143type logtagsSingleton struct{}
144
145func (l *logtagsSingleton) GenerateBuildActions(ctx android.SingletonContext) {
146	var allLogtags android.Paths
147	ctx.VisitAllModules(func(module android.Module) {
148		if logtags, ok := module.(logtagsProducer); ok {
149			allLogtags = append(allLogtags, logtags.logtags()...)
150		}
151	})
152
153	ctx.Build(pctx, android.BuildParams{
154		Rule:        mergeLogtags,
155		Description: "merge logtags",
156		Output:      android.PathForIntermediates(ctx, "all-event-log-tags.txt"),
157		Inputs:      allLogtags,
158	})
159}
160