Skip to content

Commit

Permalink
Use externally available dependencies in build_dependencies.bzl
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 570495757
  • Loading branch information
mai93 authored and copybara-github committed Nov 1, 2023
1 parent e221aa6 commit 5e9fd3e
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions aspect/build_dependencies.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Aspects to build and collect project dependencies."""

load(
"//tools/build_defs/cc:action_names.bzl",
"@bazel_tools//tools/build_defs/cc:action_names.bzl",
"CPP_COMPILE_ACTION_NAME",
"C_COMPILE_ACTION_NAME",
)
Expand Down Expand Up @@ -612,34 +612,22 @@ def _build_ide_aar_file_map(manifest_file, resource_files):
file_map[res_dir_path] = f
return file_map

_CONTROL_FILE_ENTRY = '''entry {
zip_path: "%s"
exec_path: "%s"
}'''

def _package_ide_aar(ctx, aar, file_map):
"""
Declares a file and defines actions to build .aar according to file_map.
The IDE.aar file is produces by an aspect and therefore it cannot define
additional targets and thus cannot use genzip() rule. This function reuses
//tools/genzip:build_zip tool, which is used by getzip() rule.
"""
actions = ctx.actions
control_file = actions.declare_file(".control", sibling = aar)
control_content = ['output_filename: "%s"' % aar.path]
files_map_args = []
files = []
for aar_dir_path, f in file_map.items():
files.append(f)
control_content.append(_CONTROL_FILE_ENTRY % (aar_dir_path, f.path))
control_content.append("compression: STORED")
actions.write(control_file, "\n".join(control_content))
actions.run(
files_map_args.append("%s=%s" % (aar_dir_path, f.path))

ctx.actions.run(
mnemonic = "GenerateIdeAar",
executable = ctx.executable._build_zip,
inputs = files + [control_file],
inputs = files,
outputs = [aar],
arguments = ["--control", control_file.path],
arguments = ["c", aar.path] + files_map_args,
)

def _output_relative_path(path):
Expand Down Expand Up @@ -701,7 +689,7 @@ collect_dependencies = aspect(
allow_files = True,
cfg = "exec",
executable = True,
default = "@//tools/genzip:build_zip",
default = "@@bazel_tools//tools/zip:zipper",
),
},
fragments = ["cpp"],
Expand All @@ -724,7 +712,7 @@ collect_all_dependencies_for_tests = aspect(
allow_files = True,
cfg = "exec",
executable = True,
default = "@//tools/genzip:build_zip",
default = "@@bazel_tools//tools/zip:zipper",
),
},
fragments = ["cpp"],
Expand Down

0 comments on commit 5e9fd3e

Please sign in to comment.