Open-CMSIS-Pack / devtools

Open-CMSIS-Pack development tools - C++
Apache License 2.0
73 stars 54 forks source link

execute commands on windows may fail due to paths specified with '/' instead of '\' #1735

Closed ReinhardKeil closed 3 days ago

ReinhardKeil commented 1 week ago

Describe the bug

Trying this execute command on windows fails:

  executes:
    - execute: dir 
      run: copy $input$ $output$
      input:  
        - $elf(Project)$
      output: 
        - $OutDir(Project)$/Project.out

with this output:

FAILED: C:/Test/Blank4/out/Project/ADuCM320-Board/Debug/Project2.out
C:\WINDOWS\system32\cmd.exe /C "cd /D C:\Test\Blank4\tmp && copy C:/Test/Blank4/out/Project/ADuCM320-Board/Debug/Project.axf C:/Test/Blank4/out/Project/ADuCM320-Board/Debug/Project2.out"
The syntax of the command is incorrect.
ninja: build stopped: subcommand failed.

To Reproduce Add the command to Hello.csolution.yml.

Expected behavior

The reason is that the Windows copy requires \ characters in path names.

It also triggers the question: do we need a for-host-os: key/value as the syntax of copy commands is different across operating systems.

Environment (please complete the following information):

Additional context

I was trying to solve #1043 with in a pragmatic way.

brondani commented 1 week ago

I would recommend to use CMake commands (as well as CMake scripts) to overcome platform specific limitations. For example instead of copy $input$ $output$, the crossplatform command ${CMAKE_COMMAND} -E copy $input$ $output$ could be used.

CMake builtin command line tools: https://cmake.org/cmake/help/latest/manual/cmake.1.html#run-a-command-line-tool

ReinhardKeil commented 1 week ago

Great that seems to solve it. I will add this to documentation

ReinhardKeil commented 3 days ago

Improved documentation https://github.com/ReinhardKeil/cmsis-toolbox/blob/main/docs/YML-Input-Format.md#executes