iarsystems / iar-vsc-build

Visual Studio Code extension for developing and building IAR projects
Mozilla Public License 2.0
38 stars 5 forks source link

Build fails when using the $WS_DIR$ macro in the prebuild command #66

Closed integerfn closed 9 months ago

integerfn commented 9 months ago

Describe the bug: Build fails with error: ERROR, Unknown argument variable: Failed to expand argument variable "$WS_DIR$" when building from Visual Studio Code, but works on IAR. It happens when the $WS_DIR$ macro is used in the "Pre-build command" field, within "Build Actions".

I want to run a command as a prebuild action and, due to the directory structure, it's better to use the WS_DIR macro rather than $PROJ_DIR$.

To Reproduce: Build the project in Visual Studio Code

Expected behavior: Successful build

Actual behavior: Build fails.

Environment:

HampusAdolfsson commented 9 months ago

Hi,

I can't reproduce this on my end (I tested with the prebuild command echo '$WS_DIR$). I have two ideas that could help narrow down the issue:

integerfn commented 9 months ago

Hi,

'C:\Program Files\IAR Systems\Embedded Workbench 9.1 for ARM v9.30/common/bin/iarbuild.exe' 'c:\Users\.......\myproject.ewp' '-make' 'Debug' '-log' 'info' '-parallel' '4' '-varfile' 'c:\Users\.......\myfile.custom_argvars'

What you explained seemed like the VS Code IAR Build extension is creating a temporary .custom_argvars file to pass the $WS_DIR$, but if I'm supplying my on file, would that prevent that mechanism from working?

HampusAdolfsson commented 9 months ago

The extension creates a temporary .custom_argvars file that is a copy of your .custom_argvars file, but which also defines the $WS_DIR$ variable. This is so that you can use $WS_DIR$ in your projects, even though IAR Build does not yet support workspaces. Your own argument variables should still work.

Are there any unusual paths involved (e.g. symlinks or network drives)? These can cause issues if they are handled differently by VS Code and the IDE.

In any case, you can try overriding the .custom_argvars file the extension uses:

  1. Create a copy of your .custom_argvars file that you can use for experimenting.
  2. In VS Code, go to Terminal->Configure Tasks... and select iar: Build Project.
  3. In the tasks.json file, replace the value for argumentVariablesFile with the path to your new .custom_argvars file. You might also want to change the label to something else.

If you run this task (Terminal->Run Task...), it will use the .custom_argvars file you provided instead of creating a temporary one. You can experiment with setting your own value for $WS_DIR$ like this (in the .custom_argvars file):

<?xml version="1.0" encoding="UTF-8"?>
<iarUserArgVars>
    <!-- other groups... -->
    <group name="MyGroup" active="true">
        <variable>
            <name>WS_DIR</name>
            <value>PATH_TO_WSDIR</value>
        </variable>
    </group>
</iarUserArgVars>

If you can find out what values work or don't work, I'd be very interested to know.

integerfn commented 9 months ago

If I add the WS_DIR variable to the .custom_argvars file VS Code build works correctly. It looks like the temporary copy is not being done. The command line in VS Code shows the path to my file, not a file under temp like you said.

There are no funny things with the paths, like symlinks or network drives. The only thing slightly out of the ordinary is that the path has spaces.

What could cause the VSCode extension not to create the temporary copy?

HampusAdolfsson commented 9 months ago

If you've configured the build task in your tasks.json file and provided a value for argumentVariablesFile that is not a .eww file, the extension doesn't create the copy for you. To have it create the copy and supply the correct value for $WS_DIR$, the argumentVariablesFile needs to be a .eww file. The default value is ${command:iar-config.workspace-file}, which resolves to the workspace file that's selected in the extension configuration dropdown.

How are you normally running the build task? If you use the "Build Project" button in the extension toolbar and it still doesn't create the copy for you, there is definitely a bug somewhere.

integerfn commented 9 months ago

Thank you! That was the issue. For some reason the tasks.json had this "argumentVariablesFile": "${command:iar-config.argument-variables-file}. I changed it to ${command:iar-config.workspace-file} and now it works. I don't recall setting that by hand, perhaps it's the default value from an older version?

Thank you!

HampusAdolfsson commented 9 months ago

Great, happy to help! You're right, ${command:iar-config.argument-variables-file} used to be the default before the extension had support for .eww files.