Skip to content

Commit

Permalink
fix: allow pb2 files to be included in the output of py_gapic_assembl…
Browse files Browse the repository at this point in the history
…y_pkg (#1855)
  • Loading branch information
parthea authored Nov 9, 2023
1 parent 8e1b5e0 commit e374734
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion rules_python_gapic/py_gapic_pkg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ load("@rules_gapic//:gapic_pkg.bzl", "construct_package_dir_paths")
def _py_gapic_src_pkg_impl(ctx):
srcjar_srcs = []
dir_srcs = []
py_srcs = []
for dep in ctx.attr.deps:
for f in dep.files.to_list():
if f.is_directory:
dir_srcs.append(f)
elif f.extension in ("srcjar", "jar", "zip"):
srcjar_srcs.append(f)
# Exclude source files and files for external packages
elif f.extension in ("py") and not f.is_source and 'external' not in f.path:
py_srcs.append(f)

paths = construct_package_dir_paths(ctx.attr.package_dir, ctx.outputs.pkg, ctx.label.name)

Expand All @@ -34,6 +38,9 @@ def _py_gapic_src_pkg_impl(ctx):
for dir_src in {dir_srcs}; do
cp -rT -L $dir_src {package_dir_path}
done
for py_src in {py_srcs}; do
cp $py_src {package_dir_path}
done
# Replace 555 (forced by Bazel) permissions with 644
find {package_dir_path} -type f -exec chmod 644 {{}} \\;
cd {package_dir_path}/..
Expand All @@ -44,14 +51,15 @@ def _py_gapic_src_pkg_impl(ctx):
""".format(
srcjar_srcs = " ".join(["'%s'" % f.path for f in srcjar_srcs]),
dir_srcs = " ".join(["'%s'" % f.path for f in dir_srcs]),
py_srcs = " ".join(["'%s'" % f.path for f in py_srcs]),
package_dir_path = paths.package_dir_path,
package_dir = paths.package_dir,
pkg = ctx.outputs.pkg.path,
package_dir_expr = paths.package_dir_expr,
)

ctx.actions.run_shell(
inputs = srcjar_srcs + dir_srcs,
inputs = srcjar_srcs + dir_srcs + py_srcs,
command = script,
outputs = [ctx.outputs.pkg],
)
Expand Down

0 comments on commit e374734

Please sign in to comment.