-
-
Notifications
You must be signed in to change notification settings - Fork 631
os.findheader
support relative headerdirs
#2469
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
base: master
Are you sure you want to change the base?
Conversation
os.findheader
support relative headerdirs
website/docs/os/os.findheader.md
Outdated
|
||
`additionalpaths` is a string or a table of one or more additional search path. | ||
`additionalpaths` is a string or a table of one or more additional search path. Can be absolute or relative paths. If relative, they are relative to all the default search paths. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: "The paths may be absolute or relative. If the path is a relative path, it is relative to each of the default search paths."
|
||
for _, userpath in ipairs(userpaths) do | ||
if path.isabsolute(userpath) then | ||
paths = table.join({userpath}, paths) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "append" should be use instead of "prepend", to keep original order
paths = table.join({userpath}, paths) | ||
else | ||
for _, p in ipairs(paths) do | ||
paths = table.join({path.join(p, userpath)}, paths) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the search should prioritize subdirectories. For example, if a user's computer has both /usr/include/lua.h
and /usr/include/lua5.1/lua.h
, and the user calls os.findheader("lua.h", "lua5.1")
, they are more likely looking for the latter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition you iterate and modify paths
, so os.findheader('lib.h', {'dir1', dir2})
will result in something like
{'/usr/dir1/dir2', '/usr/include/dir2', '/usr/dir1', '/usr/include'}
A table.transform(userpaths
to transform relative paths into a table, and keep absolute path as-is would be better, then flatten userpaths, and finally paths = table.join(userpaths, paths)
In fact behavior changes
would no longer search from local directory. Maybe creating another API would be cleaner, something like
|
What does this PR do?
Let
os.findheader
can support searching relative paths.Some libraries, by default, install header files within folders. For example, the header files for libfreetype-dev are located in:
/usr/include/freetype2/freetype/*.h
/usr/include/freetype2/ft2build.h
Previously, if a program included the header with
#include <ft2build.h>
, you had to use:os.findheader("freetype2/ft2build.h") .. "freetype2"
to locate it.
Now you can simply use:
os.findheader("ft2build.h", "freetype2")
to achieve the same result.
How does this PR change Premake's behavior?
Nothing.
Anything else we should know?
Nothing.
Did you check all the boxes?
closes #XXXX
in comment to auto-close issue when PR is merged)You can now support Premake on our OpenCollective. Your contributions help us spend more time responding to requests like these!