Skip to content
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

How to handle conflicting API (in external modules)? #2184

Open
Jarod42 opened this issue Feb 14, 2024 · 1 comment
Open

How to handle conflicting API (in external modules)? #2184

Jarod42 opened this issue Feb 14, 2024 · 1 comment
Labels

Comments

@Jarod42
Copy link
Contributor

Jarod42 commented Feb 14, 2024

What's your question?

I test external modules, I put generators in premake5-system.lua
I have one project which uses one module with "conflicting" api
same name, (and even same definition) leading to errors.
Which is the proper way to handle that?

For actual case, it is premake-qt and premake-qmake with api qtmodules.

Anything else we should know?

From dcourtois/premake-qt#33

The proper way to fixing that would be to have the ability to create addon namespaces, but that's something that needs to be solved in Premake-core.

@samsinsane
Copy link
Member

This is tricky. You could probably override api.register yourself and kind of hack in a namespace. The simplest would be to just prefix something to name but then you would need to call the APIs using _G["prefix.api"] "value" instead of prefix.api "value". There might be some Lua trick to get it to work as expected, or you can just add _G["prefix"]["api"] = _G["prefix.api"] then both ways of calling the API will work.

However, this won't do anything for any instances of modules overriding the same function. Especially ones that extend call arrays and perform the same checks, like this:

premake.override(vc2010.elements, "globals", function (oldfn, prj)
local elements = oldfn(prj)
if prj.system == premake.ANDROID and prj.kind ~= premake.PACKAGING then
-- Remove "IgnoreWarnCompileDuplicatedFilename".
local pos = table.indexof(elements, vc2010.ignoreWarnDuplicateFilename)
table.remove(elements, pos)
elements = table.join(elements, {
android.androidApplicationType
})
end
return elements
end)

Pulling in another Android module that extends VS would likely result in the same kind of override being performed and both will execute and result in two entries for androidApplicationType. Similarly, two modules overriding the same function using the same conditions may cause only one of the overrides to work, this would be an issue for a function like this needing to change/extend the potential values:

function m.languageStandard(cfg, condition)
if _ACTION >= "vs2017" then
if (cfg.cppdialect == "C++14") then
m.element("LanguageStandard", condition, 'stdcpp14')
elseif (cfg.cppdialect == "C++17") then
m.element("LanguageStandard", condition, 'stdcpp17')
elseif (cfg.cppdialect == "C++20") then
m.element("LanguageStandard", condition, iif(_ACTION == "vs2017", 'stdcpplatest', 'stdcpp20'))
elseif (cfg.cppdialect == "C++latest") then
m.element("LanguageStandard", condition, 'stdcpplatest')
end
end
end

So, while you might be able to avoid the situation of two modules adding the same API and causing an error, you won't be able to avoid the situation of two modules extending the same function. The only way to truly do that is to not load both of them together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants