diff options
| author | Spandan Das <spandandas@google.com> | 2023-06-05 22:43:13 +0000 |
|---|---|---|
| committer | Spandan Das <spandandas@google.com> | 2023-06-07 22:08:30 +0000 |
| commit | bd1568178bc786766e6165d7529bf52b5034f8f8 (patch) | |
| tree | 8ef5d82823607d3088c7dca4dfe656eddad95942 /bazel | |
| parent | 331c7d77c4554857db48ac0055340b5bf9f056b1 (diff) | |
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
Diffstat (limited to 'bazel')
| -rw-r--r-- | bazel/cquery/request_type.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/bazel/cquery/request_type.go b/bazel/cquery/request_type.go index ca96f2339..791c6bc23 100644 --- a/bazel/cquery/request_type.go +++ b/bazel/cquery/request_type.go @@ -11,6 +11,7 @@ var ( GetCcInfo = &getCcInfoType{} GetApexInfo = &getApexInfoType{} GetCcUnstrippedInfo = &getCcUnstrippedInfoType{} + GetPrebuiltFileInfo = &getPrebuiltFileInfo{} ) type CcAndroidMkInfo struct { @@ -375,3 +376,51 @@ func parseJson(jsonString string, info interface{}) error { } 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 +} |
