Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gpd): export aspect utils for reusability #3373

Merged
merged 1 commit into from
Dec 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions go/tools/gopackagesdriver/aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,38 @@ PROTO_COMPILER_ATTRS = [
"compilers",
]

def _is_file_external(f):
def is_file_external(f):
return f.owner.workspace_root != ""

def _file_path(f):
def file_path(f):
prefix = "__BAZEL_WORKSPACE__"
if not f.is_source:
prefix = "__BAZEL_EXECROOT__"
elif _is_file_external(f):
elif is_file_external(f):
prefix = "__BAZEL_OUTPUT_BASE__"
return paths.join(prefix, f.path)

def _go_archive_to_pkg(archive):
return struct(
ID = str(archive.data.label),
PkgPath = archive.data.importpath,
ExportFile = _file_path(archive.data.export_file),
ExportFile = file_path(archive.data.export_file),
GoFiles = [
_file_path(src)
file_path(src)
for src in archive.data.orig_srcs if src.path.endswith(".go")
],
CompiledGoFiles = [
_file_path(src)
file_path(src)
for src in archive.data.srcs if src.path.endswith(".go")
],
OtherFiles = [
_file_path(src)
file_path(src)
for src in archive.data.orig_srcs if not src.path.endswith(".go")
]
)

def _make_pkg_json(ctx, archive, pkg_info):
pkg_json_file = ctx.actions.declare_file(archive.data.name + ".pkg.json")
def make_pkg_json(ctx, name, pkg_info):
pkg_json_file = ctx.actions.declare_file(name + ".pkg.json")
ctx.actions.write(pkg_json_file, content = pkg_info.to_json())
return pkg_json_file

Expand Down Expand Up @@ -98,14 +98,14 @@ def _go_pkg_info_aspect_impl(target, ctx):
compiled_go_files.extend(archive.source.srcs)
export_files.append(archive.data.export_file)
pkg = _go_archive_to_pkg(archive)
pkg_json_files.append(_make_pkg_json(ctx, archive, pkg))
pkg_json_files.append(make_pkg_json(ctx, archive.data.name, pkg))

if ctx.rule.kind == "go_test":
for dep_archive in archive.direct:
# find the archive containing the test sources
if archive.data.label == dep_archive.data.label:
pkg = _go_archive_to_pkg(dep_archive)
pkg_json_files.append(_make_pkg_json(ctx, dep_archive, pkg))
pkg_json_files.append(make_pkg_json(ctx, dep_archive.data.name, pkg))
compiled_go_files.extend(dep_archive.source.srcs)
export_files.append(dep_archive.data.export_file)
break
Expand Down