Open-CMSIS-Pack / cbuild

Commandline utility to orchestrate the intermediate build steps of CMSIS Build
Apache License 2.0
3 stars 10 forks source link

cbuild: armclang linux: syntax error near unexpected token `(' #125

Closed Hoohaha closed 9 months ago

Hoohaha commented 9 months ago

Build open cmsis pack examples on linux with ARMCLANG toolchain. It report syntax error, any idea about his?

M652: Generated file for project build: '/home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/tmp/shell/mdk/release/CMakeLists.txt'
-- Registered toolchain version 6.19.0 does not match running version 6.19.4
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/tmp/shell/mdk/release
[1/1] Linking C executable /home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/mdk/release/shell.axf
FAILED: /home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/mdk/release/shell.axf 
: && /usr/local/ArmCompilerforEmbedded6.19/bin/armlink --cpu=Cortex-M0plus --scatter="/home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/mdk/MKE16Z64xxx4_flash.scf" --keep=*(.FlashConfig) --remove --entry=Reset_Handler --map --xref --callgraph --symbols --info sizes --info totals --info unused --info veneers --strict --diag_suppress 6314 --library_type=microlib     CMakeFiles/shell.dir/home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/mdk/RTE/Device/MKE16Z64VLF4/startup_MKE16Z4.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/components/lists/fsl_component_generic_list.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/components/serial_manager/fsl_component_serial_manager.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/components/serial_manager/fsl_component_serial_port_uart.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/components/uart/fsl_adapter_lpuart.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/drivers/fsl_clock.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/drivers/fsl_common.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/drivers/fsl_common_arm.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/drivers/fsl_gpio.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/drivers/fsl_lpuart.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/drivers/fsl_smc.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/system_MKE16Z4.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/utilities/debug_console/fsl_debug_console.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/utilities/fsl_assert.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/utilities/fsl_shell.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/utilities/str/fsl_str.o CMakeFiles/shell.dir/home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/board.o CMakeFiles/shell.dir/home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/clock_config.o CMakeFiles/shell.dir/home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/pin_mux.o CMakeFiles/shell.dir/home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/shell.o -o /home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/mdk/release/shell.axf  --list=/home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/mdk/release/shell.axf.map && :
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `: && /usr/local/ArmCompilerforEmbedded6.19/bin/armlink --cpu=Cortex-M0plus --scatter="/home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/mdk/MKE16Z64xxx4_flash.scf" --keep=*(.FlashConfig) --remove --entry=Reset_Handler --map --xref --callgraph --symbols --info sizes --info totals --info unused --info veneers --strict --diag_suppress 6314 --library_type=microlib     CMakeFiles/shell.dir/home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/mdk/RTE/Device/MKE16Z64VLF4/startup_MKE16Z4.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/components/lists/fsl_component_generic_list.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/components/serial_manager/fsl_component_serial_manager.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/components/serial_manager/fsl_component_serial_port_uart.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/components/uart/fsl_adapter_lpuart.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/drivers/fsl_clock.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/drivers/fsl_common.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/drivers/fsl_common_arm.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/drivers/fsl_gpio.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/drivers/fsl_lpuart.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/drivers/fsl_smc.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/system_MKE16Z4.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/utilities/debug_console/fsl_debug_console.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/utilities/fsl_assert.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/utilities/fsl_shell.o CMakeFiles/shell.dir/home/nxf60078/.cache/arm/packs/NXP/MKE16Z4_DFP/18.0.0/devices/MKE16Z4/utilities/str/fsl_str.o CMakeFiles/shell.dir/home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/board.o CMakeFiles/shell.dir/home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/clock_config.o CMakeFiles/shell.dir/home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/pin_mux.o CMakeFiles/shell.dir/home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/shell.o -o /home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/mdk/release/shell.axf  --list=/home/nxf60078/Downloads/NXP.FRDM-KE16Z_BSP.18.0.0/boards/frdmke16z/demo_apps/shell/mdk/release/shell.axf.map && :'
ninja: build stopped: subcommand failed.
error cbuild: error executing 'cmake' build
error cbuild: error building 'shell.release+mdk.cprj'
error cbuild: exit status 1
Hoohaha commented 9 months ago

Modified the Link parameters by adding \" in --keep option, like this \"--keep=*(.FlashConfig)\". The build can works on linux now. But on windows, it does not need this.

So my questions is cmsis toolbox should add quotes automatically for build/link options.

image
brondani commented 9 months ago

It depends on the underlying shell rules. The ninja-build manual describes the Ninja command differences between Unix and Windows:

On Unixes, commands are arrays of arguments. The Ninja command variable is passed directly to sh -c, which is then responsible for interpreting that string into an argv array. Therefore the quoting rules are those of the shell, and you can use all the normal shell operators, like && to chain multiple commands, or VAR=value cmd to set environment variables.

On Windows, commands are strings, so Ninja passes the command string directly to CreateProcess. (In the common case of simply executing a compiler this means there is less overhead.) Consequently the quoting rules are determined by the called program, which on Windows are usually provided by the C library. If you need shell interpretation of the command (such as the use of && to chain multiple commands), make the command execute the Windows shell by prefixing the command with cmd /c. Ninja may error with "invalid parameter" which usually indicates that the command line length has been exceeded.

An initial investigation shows that the direct escaping of parenthesis with backslashes works on Linux but not on Windows:

--keep=*\(.FlashConfig\)
Warning: L6319W: Ignoring --keep command

Putting the value in-between quotation marks seem to work on both Linux and Windows. In the CPRJ it would look like this:

<ldflags add="... --keep=&quot;*(.FlashConfig)&quot;"/>

However semantic operations over compiler/linker flags have been so far avoided. Pros/cons of having it done automatically need to be discussed.

Hoohaha commented 9 months ago

@brondani What's the best way to handle this?

brondani commented 9 months ago

What's the best way to handle this?

The recommendation is to surround with quotation marks the symbols that may be interpreted differently depending on the shell used in your environment. My suggestion for this case would be like that:

  misc:
    - for-compiler: AC6
      Link:
        - --keep="*(.FlashConfig)"

Your suggestion placing quotes around the whole option is also valid has the same effect.

jkrech commented 9 months ago

@brondani & @Hoohaha can this issue be closed or is there some actions to be taken?

Hoohaha commented 9 months ago

thank you @brondani and @jkrech . close now.