Skip to content

Commit 37df4b6

Browse files
committed
Additional windows path normalization in @erlang_config
1 parent b8f882d commit 37df4b6

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

repositories/erlang_config.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load(
22
"//:util.bzl",
3+
"msys2_path",
34
"path_join",
45
)
56

@@ -143,13 +144,13 @@ def _default_erlang_dict(repository_ctx):
143144
if _is_windows(repository_ctx):
144145
if ERLANG_HOME_ENV_VAR in repository_ctx.os.environ:
145146
erlang_home = repository_ctx.os.environ[ERLANG_HOME_ENV_VAR]
146-
erlang_home = erlang_home.replace("\\", "/")
147-
erl_path = path_join(erlang_home, "bin", "erl.exe")
147+
erl_path = erlang_home + "\\bin\\erl.exe"
148148
else:
149149
erl_path = repository_ctx.which("erl.exe")
150150
if erl_path == None:
151151
erl_path = repository_ctx.path("C:/Program Files/Erlang OTP/bin/erl.exe")
152152
erlang_home = _erlang_home_from_erl_path(repository_ctx, erl_path)
153+
erlang_home = msys2_path(erlang_home)
153154
elif ERLANG_HOME_ENV_VAR in repository_ctx.os.environ:
154155
erlang_home = repository_ctx.os.environ[ERLANG_HOME_ENV_VAR]
155156
erl_path = path_join(erlang_home, "bin", "erl")

util.bzl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
BEGINS_WITH_FUN = """beginswith() { case $2 in "$1"*) true;; *) false;; esac; }"""
22
QUERY_ERL_VERSION = """erl -eval '{ok, Version} = file:read_file(filename:join([code:root_dir(), "releases", erlang:system_info(otp_release), "OTP_VERSION"])), io:fwrite(Version), halt().' -noshell"""
33

4+
_DRIVE_LETTERS = ["c", "d", "e"]
5+
46
def path_join(*components):
57
nec = []
68
for c in components:
@@ -9,7 +11,24 @@ def path_join(*components):
911
return "/".join(nec)
1012

1113
def windows_path(path):
12-
return path.replace("/c/", "C:\\").replace("/", "\\")
14+
for letter in _DRIVE_LETTERS:
15+
prefix = "/%s/" % letter
16+
if path.startswith(prefix):
17+
return path.replace(
18+
prefix,
19+
"%s:\\" % letter.upper(),
20+
).replace("/", "\\")
21+
return path.replace("/", "\\")
22+
23+
def msys2_path(path):
24+
for letter in _DRIVE_LETTERS:
25+
prefix = "%s:\\" % letter.upper()
26+
if path.startswith(prefix):
27+
return path.replace(
28+
prefix,
29+
"/%s/" % letter,
30+
).replace("\\", "/")
31+
return path.replace("\\", "/")
1332

1433
def without(item, elements):
1534
c = list(elements)

0 commit comments

Comments
 (0)