Create GetPrebuiltFileInfo to Mixed builds cquery api
prebuilt_file Bazel targets do not have any build actions per se, but return a PrebuiltFileInfo provider that determines installation rules. To integrate this info into mixed builds, add a `GetPrebuiltFileInfo` method to the API. Bug: 280094612 Test: unit tests for prebuilt_etc in the next CL of this stack Change-Id: I79da6b75b6a6cbd30869860d3620aeda731ea36a
This commit is contained in:
parent
331c7d77c4
commit
bd1568178b
2 changed files with 78 additions and 5 deletions
|
@ -187,6 +187,9 @@ type BazelContext interface {
|
||||||
// Returns the results of the GetCcUnstrippedInfo query
|
// Returns the results of the GetCcUnstrippedInfo query
|
||||||
GetCcUnstrippedInfo(label string, cfgkey configKey) (cquery.CcUnstrippedInfo, error)
|
GetCcUnstrippedInfo(label string, cfgkey configKey) (cquery.CcUnstrippedInfo, error)
|
||||||
|
|
||||||
|
// Returns the results of the GetPrebuiltFileInfo query
|
||||||
|
GetPrebuiltFileInfo(label string, cfgKey configKey) (cquery.PrebuiltFileInfo, error)
|
||||||
|
|
||||||
// ** end Cquery Results Retrieval Functions
|
// ** end Cquery Results Retrieval Functions
|
||||||
|
|
||||||
// Issues commands to Bazel to receive results for all cquery requests
|
// Issues commands to Bazel to receive results for all cquery requests
|
||||||
|
@ -272,11 +275,12 @@ var _ BazelContext = noopBazelContext{}
|
||||||
type MockBazelContext struct {
|
type MockBazelContext struct {
|
||||||
OutputBaseDir string
|
OutputBaseDir string
|
||||||
|
|
||||||
LabelToOutputFiles map[string][]string
|
LabelToOutputFiles map[string][]string
|
||||||
LabelToCcInfo map[string]cquery.CcInfo
|
LabelToCcInfo map[string]cquery.CcInfo
|
||||||
LabelToPythonBinary map[string]string
|
LabelToPythonBinary map[string]string
|
||||||
LabelToApexInfo map[string]cquery.ApexInfo
|
LabelToApexInfo map[string]cquery.ApexInfo
|
||||||
LabelToCcBinary map[string]cquery.CcUnstrippedInfo
|
LabelToCcBinary map[string]cquery.CcUnstrippedInfo
|
||||||
|
LabelToPrebuiltFileInfo map[string]cquery.PrebuiltFileInfo
|
||||||
|
|
||||||
BazelRequests map[string]bool
|
BazelRequests map[string]bool
|
||||||
}
|
}
|
||||||
|
@ -325,6 +329,14 @@ func (m MockBazelContext) GetCcUnstrippedInfo(label string, _ configKey) (cquery
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m MockBazelContext) GetPrebuiltFileInfo(label string, _ configKey) (cquery.PrebuiltFileInfo, error) {
|
||||||
|
result, ok := m.LabelToPrebuiltFileInfo[label]
|
||||||
|
if !ok {
|
||||||
|
return cquery.PrebuiltFileInfo{}, fmt.Errorf("no target with label %q in LabelToPrebuiltFileInfo", label)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m MockBazelContext) InvokeBazel(_ Config, _ invokeBazelContext) error {
|
func (m MockBazelContext) InvokeBazel(_ Config, _ invokeBazelContext) error {
|
||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
}
|
}
|
||||||
|
@ -433,6 +445,14 @@ func (bazelCtx *mixedBuildBazelContext) GetCcUnstrippedInfo(label string, cfgKey
|
||||||
return cquery.CcUnstrippedInfo{}, fmt.Errorf("no bazel response for %s", key)
|
return cquery.CcUnstrippedInfo{}, fmt.Errorf("no bazel response for %s", key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bazelCtx *mixedBuildBazelContext) GetPrebuiltFileInfo(label string, cfgKey configKey) (cquery.PrebuiltFileInfo, error) {
|
||||||
|
key := makeCqueryKey(label, cquery.GetPrebuiltFileInfo, cfgKey)
|
||||||
|
if rawString, ok := bazelCtx.results[key]; ok {
|
||||||
|
return cquery.GetPrebuiltFileInfo.ParseResult(strings.TrimSpace(rawString))
|
||||||
|
}
|
||||||
|
return cquery.PrebuiltFileInfo{}, fmt.Errorf("no bazel response for %s", key)
|
||||||
|
}
|
||||||
|
|
||||||
func (n noopBazelContext) QueueBazelRequest(_ string, _ cqueryRequest, _ configKey) {
|
func (n noopBazelContext) QueueBazelRequest(_ string, _ cqueryRequest, _ configKey) {
|
||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
}
|
}
|
||||||
|
@ -454,6 +474,10 @@ func (n noopBazelContext) GetCcUnstrippedInfo(_ string, _ configKey) (cquery.CcU
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n noopBazelContext) GetPrebuiltFileInfo(_ string, _ configKey) (cquery.PrebuiltFileInfo, error) {
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
func (n noopBazelContext) InvokeBazel(_ Config, _ invokeBazelContext) error {
|
func (n noopBazelContext) InvokeBazel(_ Config, _ invokeBazelContext) error {
|
||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ var (
|
||||||
GetCcInfo = &getCcInfoType{}
|
GetCcInfo = &getCcInfoType{}
|
||||||
GetApexInfo = &getApexInfoType{}
|
GetApexInfo = &getApexInfoType{}
|
||||||
GetCcUnstrippedInfo = &getCcUnstrippedInfoType{}
|
GetCcUnstrippedInfo = &getCcUnstrippedInfoType{}
|
||||||
|
GetPrebuiltFileInfo = &getPrebuiltFileInfo{}
|
||||||
)
|
)
|
||||||
|
|
||||||
type CcAndroidMkInfo struct {
|
type CcAndroidMkInfo struct {
|
||||||
|
@ -375,3 +376,51 @@ func parseJson(jsonString string, info interface{}) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type getPrebuiltFileInfo struct{}
|
||||||
|
|
||||||
|
// Name returns a string name for this request type. Such request type names must be unique,
|
||||||
|
// and must only consist of alphanumeric characters.
|
||||||
|
func (g getPrebuiltFileInfo) Name() string {
|
||||||
|
return "getPrebuiltFileInfo"
|
||||||
|
}
|
||||||
|
|
||||||
|
// StarlarkFunctionBody returns a starlark function body to process this request type.
|
||||||
|
// The returned string is the body of a Starlark function which obtains
|
||||||
|
// all request-relevant information about a target and returns a string containing
|
||||||
|
// this information.
|
||||||
|
// The function should have the following properties:
|
||||||
|
// - The arguments are `target` (a configured target) and `id_string` (the label + configuration).
|
||||||
|
// - The return value must be a string.
|
||||||
|
// - The function body should not be indented outside of its own scope.
|
||||||
|
func (g getPrebuiltFileInfo) StarlarkFunctionBody() string {
|
||||||
|
return `
|
||||||
|
p = providers(target)
|
||||||
|
prebuilt_file_info = p.get("//build/bazel/rules:prebuilt_file.bzl%PrebuiltFileInfo")
|
||||||
|
if not prebuilt_file_info:
|
||||||
|
fail("%s did not provide PrebuiltFileInfo" % id_string)
|
||||||
|
|
||||||
|
return json.encode({
|
||||||
|
"Src": prebuilt_file_info.src.path,
|
||||||
|
"Dir": prebuilt_file_info.dir,
|
||||||
|
"Filename": prebuilt_file_info.filename,
|
||||||
|
"Installable": prebuilt_file_info.installable,
|
||||||
|
})`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PrebuiltFileInfo struct {
|
||||||
|
// TODO: b/207489266 - Fully support all properties in prebuilt_file
|
||||||
|
Src string
|
||||||
|
Dir string
|
||||||
|
Filename string
|
||||||
|
Installable bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseResult returns a value obtained by parsing the result of the request's Starlark function.
|
||||||
|
// The given rawString must correspond to the string output which was created by evaluating the
|
||||||
|
// Starlark given in StarlarkFunctionBody.
|
||||||
|
func (g getPrebuiltFileInfo) ParseResult(rawString string) (PrebuiltFileInfo, error) {
|
||||||
|
var info PrebuiltFileInfo
|
||||||
|
err := parseJson(rawString, &info)
|
||||||
|
return info, err
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue