Skip to content

Commit

Permalink
feat: Addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bakjos committed Jan 12, 2023
1 parent e85024c commit 97e0d8b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 23 deletions.
1 change: 0 additions & 1 deletion go/private/actions/archive.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ def emit_archive(go, source = None, _recompile_suffix = ""):
_cxxopts = as_tuple(source.cxxopts),
_clinkopts = as_tuple(source.clinkopts),
_cgo_exports = as_tuple(source.cgo_exports),
_root_dir = source.root_dir,
# Information on dependencies
_dep_labels = tuple([d.data.label for d in direct]),
_dep_importmaps = tuple([d.data.importmap for d in direct]),
Expand Down
9 changes: 0 additions & 9 deletions go/private/context.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,10 @@ def _dedup_deps(deps):
return deduped_deps

def _library_to_source(go, attr, library, coverage_instrumented):
root_dir = None

#TODO: stop collapsing a depset in this line...
attr_srcs = [f for t in getattr(attr, "srcs", []) for f in as_iterable(t.files)]
if len(attr_srcs) > 0:
root_dir = attr_srcs[0].dirname
generated_srcs = getattr(library, "srcs", [])
srcs = attr_srcs + generated_srcs
if root_dir == None and len(generated_srcs) > 0:
root_dir = generated_srcs[0].dirname
if root_dir.startswith(go._ctx.bin_dir.path + "/"):
root_dir = root_dir[len(go._ctx.bin_dir.path) + 1:]
embedsrcs = [f for t in getattr(attr, "embedsrcs", []) for f in as_iterable(t.files)]
source = {
"library": library,
Expand All @@ -265,7 +257,6 @@ def _library_to_source(go, attr, library, coverage_instrumented):
"cgo_deps": [],
"cgo_exports": [],
"cc_info": None,
"root_dir": root_dir,
}
if coverage_instrumented:
source["cover"] = attr_srcs
Expand Down
15 changes: 2 additions & 13 deletions go/private/tools/path.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,13 @@ def _go_path_impl(ctx):
importpath, pkgpath = effective_importpath_pkgpath(archive)
if importpath == "":
continue # synthetic archive or inferred location

# Uses an array so it can be updated during the merge package
root_dir = []
if archive._root_dir:
root_dir = [archive._root_dir]
pkg = struct(
importpath = importpath,
dir = "src/" + pkgpath,
srcs = as_list(archive.orig_srcs),
data = as_list(archive.data_files),
embedsrcs = as_list(archive._embedsrcs),
pkgs = {mode: archive.file},
root_dir = root_dir,
)
if pkgpath in pkg_map:
_merge_pkg(pkg_map[pkgpath], pkg)
Expand All @@ -81,19 +75,16 @@ def _go_path_impl(ctx):
# src_dir is the path to the directory holding the source.
# Paths to embedded sources will be relative to this path.
src_dir = None
if len(pkg.root_dir) > 0:
src_dir = pkg.root_dir[0]

for f in pkg.srcs:
src_dir = f.dirname
dst = pkg.dir + "/" + f.basename
_add_manifest_entry(manifest_entries, manifest_entry_map, inputs, f, dst)
for f in pkg.embedsrcs:
if src_dir == None:
fail("cannot relativize {}: src_dir is unset".format(f.path))
embedpath = paths.relativize(f.path, f.root.path)
if embedpath.startswith(ctx.bin_dir.path + "/"):
embedpath = embedpath[len(ctx.bin_dir.path) + 1:]
dst = pkg.dir + "/" + paths.relativize(embedpath, src_dir)
dst = pkg.dir + "/" + paths.relativize(embedpath.lstrip(ctx.bin_dir.path + "/"), src_dir.lstrip(ctx.bin_dir.path + "/"))
_add_manifest_entry(manifest_entries, manifest_entry_map, inputs, f, dst)
if ctx.attr.include_pkg:
for pkg in pkg_map.values():
Expand Down Expand Up @@ -274,8 +265,6 @@ def _merge_pkg(x, y):
x.srcs.extend([f for f in y.srcs if f.path not in x_srcs])
x.data.extend([f for f in y.data if f.path not in x_srcs])
x.embedsrcs.extend([f for f in y.embedsrcs if f.path not in x_embedsrcs])
if y.root_dir and not x.root_dir:
x.root_dir.extend(y.root_dir)
x.pkgs.update(y.pkgs)

def _add_manifest_entry(entries, entry_map, inputs, src, dst):
Expand Down

0 comments on commit 97e0d8b

Please sign in to comment.