// Copyright (C) 2017 The Android Open Source Project // // 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 wayland_protocol defines an plugin module for the Soong build system, which makes it easier to generate code from a list of Wayland protocol files. The primary build module is "wayland_protocol_codegen", which takes a list of protocol files, and runs a configurable code-generation tool to generate source code for each one. There is also a "wayland_protocol_codegen_defaults" for setting common properties. This package is substantially similar to the base "android/soong/genrule" package, which was originally used for inspiration for this one, and has been recently restructured so that it can be kept in sync with a tool like "vimdiff" to keep things in sync as needed. However this build system plugin will not be needed in the future, as evidenced by some of the other files that have been added as part of the last big sync-up. In the future, Android will be built with Bazel, and it is much simpler there to define our own local version of "gensrcs" that implements the functionality we need See bazel/gensrcs.bzl for it. Notable differences: - This package implements a more powerful template mechanism for specifying what output path/filename should be used for each source filename. The genrule package only allows the extension on each source filename to be replaced. - This package drops support for depfiles, after observing comments that they are problematic in the genrule package sources. - This package drops "Extra" and "CmdModifier" from the public Module structure, as this module is not expected to be extended. - This package drops "rule" from the public Module structure, as it was unused but present in genrule. # Usage wayland_protocol_codegen { // A standard target name. name: "wayland_extension_protocol_sources", // A simple template for generating output filenames. output: "$(in).c" // The command line template. See "Cmd". cmd: "$(location wayland_scanner) code < $(in) > $(out)", // Protocol source files for the expansion. srcs: [":wayland_extension_protocols"], // Any buildable binaries to use as tools tools: ["wayland_scanner"], // Any source files to be used (scripts, template files) tools_files: [], } */ package soong_wayland_protocol_codegen import ( "fmt" "strconv" "strings" "github.com/google/blueprint" "github.com/google/blueprint/bootstrap" "github.com/google/blueprint/proptools" "android/soong/android" "android/soong/bazel" "android/soong/bazel/cquery" "android/soong/genrule" "path/filepath" ) func init() { registerCodeGenBuildComponents(android.InitRegistrationContext) } func registerCodeGenBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("wayland_protocol_codegen_defaults", defaultsFactory) ctx.RegisterModuleType("wayland_protocol_codegen", codegenFactory) ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) { ctx.BottomUp("wayland_protocol_codegen_tool_deps", toolDepsMutator).Parallel() }) } var ( pctx = android.NewPackageContext("android/soong/external/wayland_protocol_codegen") // Used by wayland_protocol_codegen when there is more than 1 shard to merge the outputs // of each shard into a zip file. gensrcsMerge = pctx.AndroidStaticRule("wayland_protocol_codegenMerge", blueprint.RuleParams{ Command: "${soongZip} -o ${tmpZip} @${tmpZip}.rsp && ${zipSync} -d ${genDir} ${tmpZip}", CommandDeps: []string{"${soongZip}", "${zipSync}"}, Rspfile: "${tmpZip}.rsp", RspfileContent: "${zipArgs}", }, "tmpZip", "genDir", "zipArgs") ) func init() { pctx.Import("android/soong/android") pctx.HostBinToolVariable("soongZip", "soong_zip") pctx.HostBinToolVariable("zipSync", "zipsync") } type hostToolDependencyTag struct { blueprint.BaseDependencyTag android.LicenseAnnotationToolchainDependencyTag label string } func (t hostToolDependencyTag) AllowDisabledModuleDependency(target android.Module) bool { // Allow depending on a disabled module if it's replaced by a prebuilt // counterpart. We get the prebuilt through android.PrebuiltGetPreferred in // GenerateAndroidBuildActions. return target.IsReplacedByPrebuilt() } var _ android.AllowDisabledModuleDependency = (*hostToolDependencyTag)(nil) type generatorProperties struct { // The command to run on one or more input files. Cmd supports // substitution of a few variables (the actual substitution is implemented // in GenerateAndroidBuildActions below) // // Available variables for substitution: // // - $(location) // the path to the first entry in tools or tool_files // - $(location