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

cfg.buildtarget tokens incorrect in postbuildcommands #2248

Open
richard-sim opened this issue Sep 18, 2024 · 3 comments
Open

cfg.buildtarget tokens incorrect in postbuildcommands #2248

richard-sim opened this issue Sep 18, 2024 · 3 comments
Labels

Comments

@richard-sim
Copy link
Contributor

richard-sim commented Sep 18, 2024

What seems to be the problem?
The various cfg.buildtarget tokens appear to be incorrect in postbuildcommands.

The complete (dummy) project I'm using for learning Premake demonstrates the bug: https://github.com/richard-sim/build-sys-eval/blob/248c0abae20a8509e0d8eb63e435fa3925e3cb06/foobar/src/premake5.lua#L62

postbuildcommands {
    "{ECHO} %{prj.name} cfg.buildtarget.directory: %[%{cfg.buildtarget.directory}]",
    "{ECHO} %{prj.name} cfg.buildtarget.relpath: %[%{cfg.buildtarget.relpath}]",
    "{ECHO} %{prj.name} !cfg.buildtarget.relpath: %[%{!cfg.buildtarget.relpath}]",
    "{ECHO} %{prj.name} cfg.buildtarget.abspath: %[%{cfg.buildtarget.abspath}]",
    "{ECHO} %{prj.name} !cfg.buildtarget.abspath: %[%{!cfg.buildtarget.abspath}]",
    "{ECHO} %{prj.name} cfg.buildtarget.name: %[%{cfg.buildtarget.name}]",
    "{ECHO} %{prj.name} cfg.buildtarget.basename: %[%{cfg.buildtarget.basename}]",
    "{ECHO} %{prj.name} cfg.buildtarget.extension: %[%{cfg.buildtarget.extension}]"
}

output:

L3a.vcxproj -> D:\dev\build-sys-eval\foobar\src\.build\bin\windows-x86_64-debug\L3a\L3a.exe
L3a cfg.buildtarget.directory: "D:\dev\build-sys-eval\foobar\src\.build\bin\windows-x86_64-debug\L3a\"
L3a cfg.buildtarget.relpath: "..\bin\windows-x86_64-debug\L3a\L3a.exe"
L3a !cfg.buildtarget.relpath: "..\bin\windows-x86_64-debug\L3a\L3a.exe"
L3a cfg.buildtarget.abspath: "..\bin\windows-x86_64-debug\L3a\L3a.exe"
L3a !cfg.buildtarget.abspath: "bin\windows-x86_64-debug\L3a\L3a.exe"
L3a cfg.buildtarget.name: "L3a.exe"
L3a cfg.buildtarget.basename: "L3a"
L3a cfg.buildtarget.extension: "..\.exe"

Partial directory structure:

foobar/
    src/
        .build/ <-- workspace location
            bin/ <-- workspace targetdir
                <per-config name>/
                    L3a/ <-- project's outputs
            obj/ <-- workspace objdir
                <per-config name>/
                    L3a/ <-- project's object files
        foobar/
            L3a/
                premake5.lua
        premake5.lua

What did you expect to happen?

  • cfg.buildtarget.directory I'd expect to be relative to foobar/src/Premake5.lua as per Premake convention, not absolute.
  • cfg.buildtarget.relpath I'd expect to be relative to foobar/src/Premake5.lua, not relative to what seems to be foobar/src/.build/obj/ for some reason?!
  • !cfg.buildtarget.relpath I'd expect to be the absolute path.
  • cfg.buildtarget.abspath I'd also expect to be the absolute path.
  • !cfg.buildtarget.abspath I'd expect to... also be the abs path.
  • cfg.buildtarget.extension I'd expect to be .exe not ..\.exe. That's quite a unique definition of extension!

What have you tried so far?
I'm using %[%{cfg.buildtarget.directory}%{cfg.buildtarget.basename}.ext], which while is an absolute path, is fine for my needs.

How can we reproduce this?
This bare-bones repo can be cloned: https://github.com/richard-sim/build-sys-eval/blob/248c0abae20a8509e0d8eb63e435fa3925e3cb06/foobar/src/premake5.lua#L62

  • [ x ] Visual Studio 2022 (vs2022)
  • [ x ] Other (Please list below) premake-cmake

What version of Premake are you using?
Latest master branch.

Anything else we should know?
I'm new here. :)

@Jarod42
Copy link
Contributor

Jarod42 commented Sep 19, 2024

%[..] makes path relative and usable for generated solution, so generally make the path relative to generated project.
%{!cfg.buildtarget.abspath} (without enclosing %[..]) would be shown absolute.

Even some relative paths are returned as absolute and transformed into relative path "later" (as in includedirs "%{cfg.xx}/{cfg.yy}")
So %{cfg.buildtarget.relpath} might show relative or absolute path (I don't remember)
Even for some paths and some generators, there are transformed into special token (as $(SolutionDir)).

I'm using %[%{cfg.buildtarget.directory}%{cfg.buildtarget.basename}.ext], which while is an absolute path, is fine for my needs.

I'm expecting resulting path is relative.
But at least it is working :-)
as explained in path in commands

@richard-sim
Copy link
Contributor Author

richard-sim commented Sep 22, 2024

as explained in path in commands

I read that, which is why I was using %[]. To quote that page (ouch, spelling):

When you specify a path inside a commands, you have to wrap path insice %[] to allow correct trnasformation for the generator.

That, to me, says that the %[] is necessary, period - not necessary for only some desired outcome.

I've expanded the postbuildcommands to this:

"{ECHO} %{prj.name} [cfg.buildtarget.directory]: %[%{cfg.buildtarget.directory}]",
"{ECHO} %{prj.name} cfg.buildtarget.directory: %{cfg.buildtarget.directory}",
"{ECHO} %{prj.name} [cfg.buildtarget.relpath]: %[%{cfg.buildtarget.relpath}]",
"{ECHO} %{prj.name} cfg.buildtarget.relpath: %{cfg.buildtarget.relpath}",
"{ECHO} %{prj.name} [!cfg.buildtarget.relpath]: %[%{!cfg.buildtarget.relpath}]",
"{ECHO} %{prj.name} !cfg.buildtarget.relpath: %{!cfg.buildtarget.relpath}",
"{ECHO} %{prj.name} [cfg.buildtarget.abspath]: %[%{cfg.buildtarget.abspath}]",
"{ECHO} %{prj.name} cfg.buildtarget.abspath: %{cfg.buildtarget.abspath}",
"{ECHO} %{prj.name} [!cfg.buildtarget.abspath]: %[%{!cfg.buildtarget.abspath}]",
"{ECHO} %{prj.name} !cfg.buildtarget.abspath: %{!cfg.buildtarget.abspath}",
"{ECHO} %{prj.name} [cfg.buildtarget.name]: %[%{cfg.buildtarget.name}]",
"{ECHO} %{prj.name} cfg.buildtarget.name: %{cfg.buildtarget.name}",
"{ECHO} %{prj.name} [cfg.buildtarget.basename]: %[%{cfg.buildtarget.basename}]",
"{ECHO} %{prj.name} cfg.buildtarget.basename: %{cfg.buildtarget.basename}",
"{ECHO} %{prj.name} [cfg.buildtarget.extension]: %[%{cfg.buildtarget.extension}]",
"{ECHO} %{prj.name} cfg.buildtarget.extension: %{cfg.buildtarget.extension}",

which results in this in the generated vcxproj file:

echo $(ProjectName) [cfg.buildtarget.directory]: "$(TargetDir)"
echo $(ProjectName) cfg.buildtarget.directory: $(TargetDir)
echo $(ProjectName) [cfg.buildtarget.relpath]: "..\bin\windows-x86_64-release\L0a\L0a.dll"
echo $(ProjectName) cfg.buildtarget.relpath: bin/windows-x86_64-release/L0a/L0a.dll
echo $(ProjectName) [!cfg.buildtarget.relpath]: "..\bin\windows-x86_64-release\L0a\L0a.dll"
echo $(ProjectName) !cfg.buildtarget.relpath: bin/windows-x86_64-release/L0a/L0a.dll
echo $(ProjectName) [cfg.buildtarget.abspath]: "..\bin\windows-x86_64-release\L0a\L0a.dll"
echo $(ProjectName) cfg.buildtarget.abspath: bin/windows-x86_64-release/L0a/L0a.dll
echo $(ProjectName) [!cfg.buildtarget.abspath]: "bin\windows-x86_64-release\L0a\L0a.dll"
echo $(ProjectName) !cfg.buildtarget.abspath: D:/dev/build-sys-eval/foobar/src/.build/bin/windows-x86_64-release/L0a/L0a.dll
echo $(ProjectName) [cfg.buildtarget.name]: "$(TargetFileName)"
echo $(ProjectName) cfg.buildtarget.name: $(TargetFileName)
echo $(ProjectName) [cfg.buildtarget.basename]: "$(TargetName)"
echo $(ProjectName) cfg.buildtarget.basename: $(TargetName)
echo $(ProjectName) [cfg.buildtarget.extension]: "..\.dll"
echo $(ProjectName) cfg.buildtarget.extension: .dll

Without %[] relpath and abspath are indeed much more correct, though I'd still expect both %{!cfg.buildtarget.relpath} and %{cfg.buildtarget.abspath} to be absolute paths like %{!cfg.buildtarget.abspath} is.

So the docs stating that %[] is required for paths appears to be entirely incorrect? Even without the %[] the generator transformed %{cfg.buildtarget.directory} into $(TargetDir). 😕

@Jarod42
Copy link
Contributor

Jarod42 commented Oct 26, 2024

I'd still expect both %{!cfg.buildtarget.relpath} and %{cfg.buildtarget.abspath} to be absolute paths like %{!cfg.buildtarget.abspath} is.

IMO, having relpath/abspath is wrong from premake API perspective as confusing...
I think it comes from time before we have %[..] and %{!..}.

So the docs stating that %[] is required for paths appears to be entirely incorrect? Even without the %[] the generator transformed %{cfg.buildtarget.directory} into $(TargetDir).

I won't say doc is incorrect in that concern. As omit %[..] might work with visual generators, but some other generators won't works. %[..] would make path relative to project; Some generator has replacement table for %{..} transforming in their own variable name (which is then considered as absolute, so not replaced by %[..]).

"{ECHO} %{prj.name} [cfg.buildtarget.name]: %[%{cfg.buildtarget.name}]",
"{ECHO} %{prj.name} [cfg.buildtarget.basename]: %[%{cfg.buildtarget.basename}]",
"{ECHO} %{prj.name} [cfg.buildtarget.extension]: %[%{cfg.buildtarget.extension}]",

Those are not paths, so should not be enclosed by %[] (even if name/basename (seems to) works, related to above comment).

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