premake / premake-core

Premake
https://premake.github.io/
BSD 3-Clause "New" or "Revised" License
3.18k stars 617 forks source link

cfg.buildtarget tokens incorrect in postbuildcommands #2248

Open richard-sim opened 3 days ago

richard-sim commented 3 days ago

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?

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

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

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

Jarod42 commented 2 days ago

%[..] 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