Skip to content

Commit c253f55

Browse files
authored
fix: force symlink dereference when using file command (#1880)
On macOS, the `file` command dereferences symbolic links by default (`--dereference` implied). On Linux it's the opposite (`--no-dereference` implied). We want the dereference behavior on both, otherwise `file` outputs `symbolic link to Versions/Current/MyFrameworkBinary` on Linux when checking the file type of an iOS framework (we then fallback to the `otool` command which fails).
1 parent c126c63 commit c253f55

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

swiftpkg/internal/repository_files.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def _file_type(repository_ctx, path):
280280
A `string` representing the file type for the path as returned by the
281281
`file` utility.
282282
"""
283-
file_args = ["file", "--brief", path]
283+
file_args = ["file", "--dereference", "--brief", path]
284284
exec_result = repository_ctx.execute(file_args, quiet = True)
285285
if exec_result.return_code != 0:
286286
fail("Failed to determine the file type for {path}. stderr:\n{stderr}".format(

swiftpkg/tests/testutils.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def _new_stub_repository_ctx(
3636
exec_result = _new_exec_result(
3737
stdout = "\n".join(results),
3838
)
39-
elif args_len == 3 and args[0] == "file" and args[1] == "--brief":
40-
# Expected command: `file --brief path`
41-
path = args[2]
39+
elif args_len == 4 and args[0] == "file" and args[1] == "--dereference" and args[2] == "--brief":
40+
# Expected command: `file --dereference --brief path`
41+
path = args[3]
4242
results = file_type_results.get(path, "")
4343
exec_result = _new_exec_result(stdout = results)
4444
elif args_len == 3 and args[0] == "otool" and args[1] == "-l":

0 commit comments

Comments
 (0)