os.findheader support relative headerdirs#2469
os.findheader support relative headerdirs#2469mercury233 wants to merge 3 commits intopremake:masterfrom
os.findheader support relative headerdirs#2469Conversation
os.findheader support relative headerdirs
website/docs/os/os.findheader.md
Outdated
| `headerfile` is a file name of a file path to locate. | ||
|
|
||
| `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.
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.
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.
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.
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 |
|
@mercury233 - I'm currently prepping for the next (and final) beta release. Do you have any plans to revive this PR? If not, I will close it (feel free to reopen in the future if you desire) |
|
@nickclark2016 what do you think about creating another API like Jarod42 said? |
|
I would approve a new API |
What does this PR do?
Let
os.findheadercan 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 #XXXXin 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!