Skip to content

Commit 775e6ba

Browse files
authored
Merge pull request premake#1739 from starkos/issue/1628
Fix premake#1628 failing macOS os.findlib() test
2 parents a2e37e6 + f466e4b commit 775e6ba

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

src/base/os.lua

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,26 @@
103103
return path
104104
end
105105

106-
function os.findlib(libname, libdirs)
107-
-- libname: library name with or without prefix and suffix
108-
-- libdirs: (array or string): A set of additional search paths
109106

107+
---
108+
-- Attempt to locate and return the path to a shared library.
109+
--
110+
-- This function does not work to locate system libraries on macOS 11 or later; it may still
111+
-- be used to locate user libraries: _"New in macOS Big Sur 11.0.1, the system ships with
112+
-- a built-in dynamic linker cache of all system-provided libraries. As part of this change,
113+
-- copies of dynamic libraries are no longer present on the filesystem. Code that attempts to
114+
-- check for dynamic library presence by looking for a file at a path or enumerating a directory
115+
-- will fail."
116+
-- https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11_0_1-release-notes
117+
--
118+
-- @param libname
119+
-- The library name with or without prefix and suffix.
120+
-- @param libdirs
121+
-- An array of paths to be searched.
122+
-- @returns
123+
-- The full path to the library if found; `nil` otherwise.
124+
---
125+
function os.findlib(libname, libdirs)
110126
local path = get_library_search_path()
111127
local formats
112128

@@ -458,7 +474,7 @@
458474
--
459475
-- @param cmd Command to execute
460476
-- @param streams Standard stream(s) to output
461-
-- Must be one of
477+
-- Must be one of
462478
-- - "both" (default)
463479
-- - "output" Return standard output stream content only
464480
-- - "error" Return standard error stream content only

tests/base/test_os.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
--
2424

2525
function suite.findlib_FindSystemLib()
26-
if os.istarget("windows") then
26+
if os.istarget("macosx") then
27+
-- macOS no longer stores system libraries on filesystem; see
28+
-- https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11_0_1-release-notes
29+
elseif os.istarget("windows") then
2730
test.istrue(os.findlib("user32"))
2831
elseif os.istarget("haiku") then
2932
test.istrue(os.findlib("root"))
@@ -184,7 +187,7 @@
184187
end
185188
end
186189
end
187-
190+
188191
-- Check outputof content
189192
function suite.outputof_streams_output()
190193
if (os.istarget("macosx")
@@ -198,12 +201,12 @@
198201
test.isequal (oo, ob)
199202
local s, e = string.find (oo, "test_os.lua")
200203
test.istrue(s ~= nil)
201-
204+
202205
local o, e = os.outputof ("ls " .. cwd .. "/base", "error")
203206
test.istrue(o == nil or #o == 0)
204207
end
205208
end
206-
209+
207210
--
208211
-- os.translateCommand() tests
209212
--

website/docs/os.findlib.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@ Scan the well-known system locations looking for a library file.
44
p = os.findlib("libname" [, additionalpaths])
55
```
66

7+
This function does not work to locate system libraries on macOS 11 or later; it may still be used to locate user libraries. From [the release notes](https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11_0_1-release-notes):
8+
9+
> New in macOS Big Sur 11.0.1, the system ships with a built-in dynamic linker cache of all system-provided libraries. As part of this change, copies of dynamic libraries are no longer present on the filesystem. Code that attempts to check for dynamic library presence by looking for a file at a path or enumerating a directory will fail.
10+
711
### Parameters ###
812

9-
`libname` is name of the library to locate. It may be specified with (libX11.so) or without (X11) system-specific decorations.
13+
`libname` is name of the library to locate. It may be specified with (`libX11.so`) or without (`X11`) system-specific decorations.
14+
15+
`additionalpaths` is a string or a table of one or more additional search path.
1016

11-
`additionalpaths` is a string or a table of one or more additional search path
1217
### Return Value ###
1318

1419
The path containing the library file, if found. Otherwise, nil.
1520

16-
1721
### Availability ###
1822

19-
Premake 4.0 or later.
23+
Premake 4.0 or later. Non-macOS host systems only.
24+

0 commit comments

Comments
 (0)