2020-07-15 12:06:41 +02:00
|
|
|
// Copyright 2020 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 android
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
|
|
|
)
|
|
|
|
|
2020-11-05 13:42:11 +01:00
|
|
|
// The Bazel QueryView singleton is responsible for generating the Ninja actions
|
2020-07-15 12:06:41 +02:00
|
|
|
// for calling the soong_build primary builder in the main build.ninja file.
|
|
|
|
func init() {
|
2020-11-09 14:22:25 +01:00
|
|
|
RegisterSingletonType("bazel_queryview", BazelQueryViewSingleton)
|
2020-07-15 12:06:41 +02:00
|
|
|
}
|
|
|
|
|
2020-11-05 13:42:11 +01:00
|
|
|
func BazelQueryViewSingleton() Singleton {
|
|
|
|
return &bazelQueryViewSingleton{}
|
2020-07-15 12:06:41 +02:00
|
|
|
}
|
|
|
|
|
2020-11-05 13:42:11 +01:00
|
|
|
type bazelQueryViewSingleton struct{}
|
2020-07-15 12:06:41 +02:00
|
|
|
|
2020-11-05 13:42:11 +01:00
|
|
|
func (c *bazelQueryViewSingleton) GenerateBuildActions(ctx SingletonContext) {
|
|
|
|
// Create a build and rule statement, using the Bazel QueryView's WORKSPACE
|
2020-07-15 12:06:41 +02:00
|
|
|
// file as the output file marker.
|
|
|
|
var deps Paths
|
|
|
|
moduleListFilePath := pathForBuildToolDep(ctx, ctx.Config().moduleListFile)
|
|
|
|
deps = append(deps, moduleListFilePath)
|
|
|
|
deps = append(deps, pathForBuildToolDep(ctx, ctx.Config().ProductVariablesFileName))
|
|
|
|
|
2020-11-05 13:42:11 +01:00
|
|
|
bazelQueryViewDirectory := PathForOutput(ctx, "queryview")
|
|
|
|
bazelQueryViewWorkspaceFile := bazelQueryViewDirectory.Join(ctx, "WORKSPACE")
|
2020-07-15 12:06:41 +02:00
|
|
|
primaryBuilder := primaryBuilderPath(ctx)
|
2020-11-05 13:42:11 +01:00
|
|
|
bazelQueryView := ctx.Rule(pctx, "bazelQueryView",
|
2020-07-15 12:06:41 +02:00
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: fmt.Sprintf(
|
2020-11-09 14:22:25 +01:00
|
|
|
"rm -rf ${outDir}/* && "+
|
|
|
|
"%s --bazel_queryview_dir ${outDir} %s && "+
|
|
|
|
"echo WORKSPACE: `cat %s` > ${outDir}/.queryview-depfile.d",
|
2020-07-15 12:06:41 +02:00
|
|
|
primaryBuilder.String(),
|
|
|
|
strings.Join(os.Args[1:], " "),
|
|
|
|
moduleListFilePath.String(), // Use the contents of Android.bp.list as the depfile.
|
|
|
|
),
|
|
|
|
CommandDeps: []string{primaryBuilder.String()},
|
|
|
|
Description: fmt.Sprintf(
|
2020-11-13 16:04:17 +01:00
|
|
|
"[EXPERIMENTAL, PRE-PRODUCTION] Creating the Bazel QueryView workspace with %s at $outDir",
|
2020-07-15 12:06:41 +02:00
|
|
|
primaryBuilder.Base()),
|
|
|
|
Deps: blueprint.DepsGCC,
|
2020-11-05 13:42:11 +01:00
|
|
|
Depfile: "${outDir}/.queryview-depfile.d",
|
2020-07-15 12:06:41 +02:00
|
|
|
},
|
|
|
|
"outDir")
|
|
|
|
|
|
|
|
ctx.Build(pctx, BuildParams{
|
2020-11-05 13:42:11 +01:00
|
|
|
Rule: bazelQueryView,
|
|
|
|
Output: bazelQueryViewWorkspaceFile,
|
2020-07-15 12:06:41 +02:00
|
|
|
Inputs: deps,
|
|
|
|
Args: map[string]string{
|
2020-11-05 13:42:11 +01:00
|
|
|
"outDir": bazelQueryViewDirectory.String(),
|
2020-07-15 12:06:41 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-11-05 13:42:11 +01:00
|
|
|
// Add a phony target for building the Bazel QueryView
|
|
|
|
ctx.Phony("queryview", bazelQueryViewWorkspaceFile)
|
2020-07-15 12:06:41 +02:00
|
|
|
}
|