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 resource_strip_prefix of scala_libary for external repositories #944

Merged
Merged
Show file tree
Hide file tree
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
11 changes: 7 additions & 4 deletions scala/private/phases/phase_compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -480,17 +480,20 @@ def _try_to_compile_java_jar(
java_compilation_provider = provider,
)

def _adjust_resources_path(path, resource_strip_prefix):
def _adjust_resources_path(resource, resource_strip_prefix):
path = resource.path
if resource_strip_prefix:
return _adjust_resources_path_by_strip_prefix(path, resource_strip_prefix)
root = resource.owner.workspace_root + "/" if (resource.owner.workspace_root) else ""
ittaiz marked this conversation as resolved.
Show resolved Hide resolved
prefix = root + resource_strip_prefix
return _adjust_resources_path_by_strip_prefix(path, prefix)
else:
return _adjust_resources_path_by_default_prefixes(path)

def _add_resources_cmd(ctx):
res_cmd = []
for f in ctx.files.resources:
c_dir, res_path = _adjust_resources_path(
f.short_path,
f,
ctx.attr.resource_strip_prefix,
)
target_path = res_path
Expand All @@ -506,7 +509,7 @@ def _add_resources_cmd(ctx):

def _adjust_resources_path_by_strip_prefix(path, resource_strip_prefix):
if not path.startswith(resource_strip_prefix):
fail("Resource file %s is not under the specified prefix to strip" % path)
fail("Resource file %s is not under the specified prefix %s to strip" % (path, resource_strip_prefix))

clean_path = path[len(resource_strip_prefix):]
return resource_strip_prefix, clean_path
Expand Down
10 changes: 10 additions & 0 deletions test/src/main/scala/scalarules/test/resources/strip/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ scala_library(
name = "noSrcsWithResources",
resource_strip_prefix = "test/src/main/scala/scalarules/test/resources/strip",
resources = ["nosrc_jar_resource.txt"],
visibility = ["//visibility:public"],
)

scala_specs2_junit_test(
Expand All @@ -14,3 +15,12 @@ scala_specs2_junit_test(
unused_dependency_checker_mode = "off",
deps = [":noSrcsWithResources"],
)

scala_specs2_junit_test(
name = "resouceStripPrefixFromExternalRepoTest",
size = "small",
srcs = ["ResourceStripPrefixTest.scala"],
suffixes = ["Test"],
unused_dependency_checker_mode = "off",
deps = ["@io_bazel_rules_scala//test/src/main/scala/scalarules/test/resources/strip:noSrcsWithResources"],
ittaiz marked this conversation as resolved.
Show resolved Hide resolved
)