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

Fix generated resources #538

Merged
merged 2 commits into from
Jul 10, 2021
Merged
Changes from 1 commit
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
13 changes: 6 additions & 7 deletions kotlin/internal/jvm/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ def _adjust_resources_path_by_strip_prefix(path, resource_strip_prefix):
fail("Resource file %s is not under the specified prefix to strip" % path)

clean_path = path[len(resource_strip_prefix):]
return resource_strip_prefix, clean_path
return clean_path

def _adjust_resources_path_by_default_prefixes(path):
for cp in _CONVENTIONAL_RESOURCE_PATHS:
dir_1, dir_2, rel_path = path.partition(cp)
if rel_path:
return dir_1 + dir_2, rel_path
return "", path
return rel_path
return path

def _adjust_resources_path(path, resource_strip_prefix):
if resource_strip_prefix:
Expand Down Expand Up @@ -266,14 +266,13 @@ def _fold_jars_action(ctx, rule_kind, toolchains, output_jar, input_jars, action
def _resourcejar_args_action(ctx):
res_cmd = []
for f in ctx.files.resources:
c_dir, res_path = _adjust_resources_path(f.short_path, ctx.attr.resource_strip_prefix)
res_path = _adjust_resources_path(f.short_path, ctx.attr.resource_strip_prefix)
target_path = res_path
if target_path[0] == "/":
target_path = target_path[1:]
line = "{target_path}={c_dir}{res_path}\n".format(
res_path = res_path,
line = "{target_path}={f_path}\n".format(
Comment on lines -273 to +272
Copy link

@freetheinterns freetheinterns May 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change @jdai8! I was so confused why zipping was failing for some resource files generated under bazel-out.

To be super clear this argument line {target_path}={c_dir}{res_path} is saying that the file located at {c_dir}{res_path} should be zipped under {target_path} for the resource jar. So moving to {target_path}={f_path} should be more stable, because f.path should always be how input files are located by a bazel action and {target_path} remains the same.

target_path = target_path,
c_dir = c_dir,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only usage of c_dir. Since we don't need it anymore I removed it from the return values as well.

f_path = f.path,
)
res_cmd.extend([line])
zipper_args_file = ctx.actions.declare_file("%s_resources_zipper_args" % ctx.label.name)
Expand Down