2015-04-08 01:50:10 +02:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package cc
|
|
|
|
|
|
|
|
import (
|
2018-09-05 17:55:20 +02:00
|
|
|
"path/filepath"
|
|
|
|
|
2015-04-08 01:50:10 +02:00
|
|
|
"github.com/google/blueprint"
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
"android/soong/android"
|
2015-04-08 01:50:10 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2018-05-25 00:45:21 +02:00
|
|
|
pctx.SourcePathVariable("lexCmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/flex")
|
2018-01-09 02:26:13 +01:00
|
|
|
pctx.SourcePathVariable("yaccCmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/bison")
|
|
|
|
pctx.SourcePathVariable("yaccDataDir", "prebuilts/build-tools/common/bison")
|
2016-11-03 22:28:51 +01:00
|
|
|
|
|
|
|
pctx.HostBinToolVariable("aidlCmd", "aidl-cpp")
|
2018-09-05 17:55:20 +02:00
|
|
|
pctx.HostBinToolVariable("syspropCmd", "sysprop_cpp")
|
2015-04-08 01:50:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2016-08-30 01:14:13 +02:00
|
|
|
yacc = pctx.AndroidStaticRule("yacc",
|
2015-04-08 01:50:10 +02:00
|
|
|
blueprint.RuleParams{
|
2016-11-03 22:28:31 +01:00
|
|
|
Command: "BISON_PKGDATADIR=$yaccDataDir $yaccCmd -d $yaccFlags --defines=$hFile -o $out $in",
|
2015-11-18 00:27:28 +01:00
|
|
|
CommandDeps: []string{"$yaccCmd"},
|
2015-04-08 01:50:10 +02:00
|
|
|
},
|
2016-11-03 22:28:31 +01:00
|
|
|
"yaccFlags", "hFile")
|
2015-04-08 01:50:10 +02:00
|
|
|
|
2016-08-30 01:14:13 +02:00
|
|
|
lex = pctx.AndroidStaticRule("lex",
|
2015-04-08 01:50:10 +02:00
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "$lexCmd -o$out $in",
|
2015-11-18 00:27:28 +01:00
|
|
|
CommandDeps: []string{"$lexCmd"},
|
2015-04-08 01:50:10 +02:00
|
|
|
})
|
2016-11-03 22:28:51 +01:00
|
|
|
|
|
|
|
aidl = pctx.AndroidStaticRule("aidl",
|
|
|
|
blueprint.RuleParams{
|
2018-07-06 20:36:32 +02:00
|
|
|
Command: "$aidlCmd -d${out}.d --ninja $aidlFlags $in $outDir $out",
|
2016-11-03 22:28:51 +01:00
|
|
|
CommandDeps: []string{"$aidlCmd"},
|
|
|
|
Depfile: "${out}.d",
|
|
|
|
Deps: blueprint.DepsGCC,
|
|
|
|
},
|
|
|
|
"aidlFlags", "outDir")
|
2017-09-09 10:15:26 +02:00
|
|
|
|
2018-09-05 17:55:20 +02:00
|
|
|
sysprop = pctx.AndroidStaticRule("sysprop",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "$syspropCmd --header-output-dir=$headerOutDir --source-output-dir=$srcOutDir --include-name=$includeName $in",
|
|
|
|
CommandDeps: []string{"$syspropCmd"},
|
|
|
|
},
|
|
|
|
"headerOutDir", "srcOutDir", "includeName")
|
|
|
|
|
2017-09-09 10:15:26 +02:00
|
|
|
windmc = pctx.AndroidStaticRule("windmc",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "$windmcCmd -r$$(dirname $out) -h$$(dirname $out) $in",
|
|
|
|
CommandDeps: []string{"$windmcCmd"},
|
|
|
|
},
|
|
|
|
"windmcCmd")
|
2015-04-08 01:50:10 +02:00
|
|
|
)
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func genYacc(ctx android.ModuleContext, yaccFile android.Path, outFile android.ModuleGenPath, yaccFlags string) (headerFile android.ModuleGenPath) {
|
2016-11-03 04:43:13 +01:00
|
|
|
headerFile = android.GenPathWithExt(ctx, "yacc", yaccFile, "h")
|
2015-04-08 01:50:10 +02:00
|
|
|
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2016-11-03 22:28:31 +01:00
|
|
|
Rule: yacc,
|
2017-05-09 22:45:28 +02:00
|
|
|
Description: "yacc " + yaccFile.Rel(),
|
2016-11-03 22:28:31 +01:00
|
|
|
Output: outFile,
|
|
|
|
ImplicitOutput: headerFile,
|
|
|
|
Input: yaccFile,
|
2015-04-08 01:50:10 +02:00
|
|
|
Args: map[string]string{
|
|
|
|
"yaccFlags": yaccFlags,
|
2015-09-24 00:26:20 +02:00
|
|
|
"hFile": headerFile.String(),
|
2015-04-08 01:50:10 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2016-03-02 00:15:26 +01:00
|
|
|
return headerFile
|
2015-04-08 01:50:10 +02:00
|
|
|
}
|
|
|
|
|
2016-11-03 22:28:51 +01:00
|
|
|
func genAidl(ctx android.ModuleContext, aidlFile android.Path, outFile android.ModuleGenPath, aidlFlags string) android.Paths {
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Rule: aidl,
|
|
|
|
Description: "aidl " + aidlFile.Rel(),
|
|
|
|
Output: outFile,
|
|
|
|
Input: aidlFile,
|
2016-11-03 22:28:51 +01:00
|
|
|
Args: map[string]string{
|
|
|
|
"aidlFlags": aidlFlags,
|
|
|
|
"outDir": android.PathForModuleGen(ctx, "aidl").String(),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO: This should return the generated headers, not the source file.
|
|
|
|
return android.Paths{outFile}
|
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func genLex(ctx android.ModuleContext, lexFile android.Path, outFile android.ModuleGenPath) {
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Rule: lex,
|
|
|
|
Description: "lex " + lexFile.Rel(),
|
|
|
|
Output: outFile,
|
|
|
|
Input: lexFile,
|
2015-04-08 01:50:10 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-09-05 17:55:20 +02:00
|
|
|
func genSysprop(ctx android.ModuleContext, syspropFile android.Path) (android.Path, android.Path) {
|
|
|
|
headerFile := android.PathForModuleGen(ctx, "sysprop", "include", syspropFile.Rel()+".h")
|
|
|
|
cppFile := android.PathForModuleGen(ctx, "sysprop", syspropFile.Rel()+".cpp")
|
|
|
|
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: sysprop,
|
|
|
|
Description: "sysprop " + syspropFile.Rel(),
|
|
|
|
Output: cppFile,
|
|
|
|
ImplicitOutput: headerFile,
|
|
|
|
Input: syspropFile,
|
|
|
|
Args: map[string]string{
|
|
|
|
"headerOutDir": filepath.Dir(headerFile.String()),
|
|
|
|
"srcOutDir": filepath.Dir(cppFile.String()),
|
|
|
|
"includeName": syspropFile.Rel() + ".h",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return cppFile, headerFile
|
|
|
|
}
|
|
|
|
|
2017-09-09 10:15:26 +02:00
|
|
|
func genWinMsg(ctx android.ModuleContext, srcFile android.Path, flags builderFlags) (android.Path, android.Path) {
|
|
|
|
headerFile := android.GenPathWithExt(ctx, "windmc", srcFile, "h")
|
|
|
|
rcFile := android.GenPathWithExt(ctx, "windmc", srcFile, "rc")
|
|
|
|
|
|
|
|
windmcCmd := gccCmd(flags.toolchain, "windmc")
|
|
|
|
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-09-09 10:15:26 +02:00
|
|
|
Rule: windmc,
|
|
|
|
Description: "windmc " + srcFile.Rel(),
|
|
|
|
Output: rcFile,
|
|
|
|
ImplicitOutput: headerFile,
|
|
|
|
Input: srcFile,
|
|
|
|
Args: map[string]string{
|
|
|
|
"windmcCmd": windmcCmd,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return rcFile, headerFile
|
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func genSources(ctx android.ModuleContext, srcFiles android.Paths,
|
|
|
|
buildFlags builderFlags) (android.Paths, android.Paths) {
|
2015-04-08 01:50:10 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
var deps android.Paths
|
2015-04-08 01:50:10 +02:00
|
|
|
|
2017-05-02 02:37:24 +02:00
|
|
|
var rsFiles android.Paths
|
|
|
|
|
2015-04-08 01:50:10 +02:00
|
|
|
for i, srcFile := range srcFiles {
|
2015-09-24 00:26:20 +02:00
|
|
|
switch srcFile.Ext() {
|
2016-03-02 00:15:26 +01:00
|
|
|
case ".y":
|
2016-11-03 04:43:13 +01:00
|
|
|
cFile := android.GenPathWithExt(ctx, "yacc", srcFile, "c")
|
2016-03-02 00:15:26 +01:00
|
|
|
srcFiles[i] = cFile
|
|
|
|
deps = append(deps, genYacc(ctx, srcFile, cFile, buildFlags.yaccFlags))
|
|
|
|
case ".yy":
|
2016-11-03 04:43:13 +01:00
|
|
|
cppFile := android.GenPathWithExt(ctx, "yacc", srcFile, "cpp")
|
2015-04-08 01:50:10 +02:00
|
|
|
srcFiles[i] = cppFile
|
2016-03-02 00:15:26 +01:00
|
|
|
deps = append(deps, genYacc(ctx, srcFile, cppFile, buildFlags.yaccFlags))
|
|
|
|
case ".l":
|
2016-11-03 04:43:13 +01:00
|
|
|
cFile := android.GenPathWithExt(ctx, "lex", srcFile, "c")
|
2016-03-02 00:15:26 +01:00
|
|
|
srcFiles[i] = cFile
|
|
|
|
genLex(ctx, srcFile, cFile)
|
|
|
|
case ".ll":
|
2016-11-03 04:43:13 +01:00
|
|
|
cppFile := android.GenPathWithExt(ctx, "lex", srcFile, "cpp")
|
2015-04-08 01:50:10 +02:00
|
|
|
srcFiles[i] = cppFile
|
2016-03-02 00:15:26 +01:00
|
|
|
genLex(ctx, srcFile, cppFile)
|
2016-10-21 01:11:43 +02:00
|
|
|
case ".proto":
|
2018-11-17 06:05:32 +01:00
|
|
|
ccFile, headerFile := genProto(ctx, srcFile, buildFlags)
|
2017-09-20 21:59:05 +02:00
|
|
|
srcFiles[i] = ccFile
|
|
|
|
deps = append(deps, headerFile)
|
2016-11-03 22:28:51 +01:00
|
|
|
case ".aidl":
|
|
|
|
cppFile := android.GenPathWithExt(ctx, "aidl", srcFile, "cpp")
|
|
|
|
srcFiles[i] = cppFile
|
|
|
|
deps = append(deps, genAidl(ctx, srcFile, cppFile, buildFlags.aidlFlags)...)
|
2017-05-02 02:37:24 +02:00
|
|
|
case ".rs", ".fs":
|
|
|
|
cppFile := rsGeneratedCppFile(ctx, srcFile)
|
|
|
|
rsFiles = append(rsFiles, srcFiles[i])
|
|
|
|
srcFiles[i] = cppFile
|
2017-09-09 10:15:26 +02:00
|
|
|
case ".mc":
|
|
|
|
rcFile, headerFile := genWinMsg(ctx, srcFile, buildFlags)
|
|
|
|
srcFiles[i] = rcFile
|
|
|
|
deps = append(deps, headerFile)
|
2018-09-05 17:55:20 +02:00
|
|
|
case ".sysprop":
|
|
|
|
cppFile, headerFile := genSysprop(ctx, srcFile)
|
|
|
|
srcFiles[i] = cppFile
|
|
|
|
deps = append(deps, headerFile)
|
2015-04-08 01:50:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-02 02:37:24 +02:00
|
|
|
if len(rsFiles) > 0 {
|
|
|
|
deps = append(deps, rsGenerateCpp(ctx, rsFiles, buildFlags.rsFlags)...)
|
|
|
|
}
|
|
|
|
|
2015-04-08 01:50:10 +02:00
|
|
|
return srcFiles, deps
|
|
|
|
}
|