Skip to content

Use skylib path is_absolute #982

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

Merged
merged 1 commit into from
Jan 31, 2020
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
16 changes: 2 additions & 14 deletions scala/private/rule_impls.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
"""Rules for supporting the Scala language."""

load("@bazel_skylib//lib:paths.bzl", "paths")
load(
"@io_bazel_rules_scala//scala/private:coverage_replacements_provider.bzl",
_coverage_replacements_provider = "coverage_replacements_provider",
Expand Down Expand Up @@ -225,25 +226,12 @@ StatsfileOutput: {statsfile_output}
] + ["@" + argfile.path],
)

def _path_is_absolute(path):
# Returns true for absolute path in Linux/Mac (i.e., '/') or Windows (i.e.,
# 'X:\' or 'X:/' where 'X' is a letter), false otherwise.
if len(path) >= 1 and path[0] == "/":
return True
if len(path) >= 3 and \
path[0].isalpha() and \
path[1] == ":" and \
(path[2] == "/" or path[2] == "\\"):
return True

return False

def runfiles_root(ctx):
return "${TEST_SRCDIR}/%s" % ctx.workspace_name

def java_bin(ctx):
java_path = str(ctx.attr._java_runtime[java_common.JavaRuntimeInfo].java_executable_runfiles_path)
if _path_is_absolute(java_path):
if paths.is_absolute(java_path):
javabin = java_path
else:
runfiles_root_var = runfiles_root(ctx)
Expand Down