iarsystems / iar-vsc-build

Visual Studio Code extension for developing and building IAR projects
https://marketplace.visualstudio.com/items?itemName=iarsystems.iar-build
Mozilla Public License 2.0
38 stars 5 forks source link

WS_DIR from custom arguments file is not working #52

Closed gcampbell-msft closed 1 year ago

gcampbell-msft commented 1 year ago

@HampusAdolfsson Thanks for getting workspace and batch build support enabled!

I just tested it out and the UI looks great! However, I noticed that while WS_DIR is supported in certain contexts, it isn't working for me in batch builds, as it doesn't seem to be propagating the WS_DIR value replacement into the custom_argvars files.

image

I was able to make a slight modification in the code to get this to work, though I doubt it's a long term solution as it modifies the custom_argvars files in place, which wouldn't do great with git repos (as it replaces the $WS_DIR$ in place), but it fixed my issue for me in the current time.

This is my code that I modified in eworkspace.ts.

getArgvarsFile(): string | undefined {
      const argvarsPath = Path.join(
          Path.dirname(this.path),
          Path.basename(this.path, ".eww") + ".custom_argvars"
      );

      if (Fs.existsSync(argvarsPath)) {
          const data = Fs.readFileSync(argvarsPath);
          Fs.writeFileSync(argvarsPath, data.toString().replace(/\$WS_DIR\$/, Path.dirname(this.path)));
          return argvarsPath;
      }
      return undefined;
  }

A possible better way that I can think of is to create a temporary file with WS_DIR replaced and use this as the custom_arguments file.

Thanks!

HampusAdolfsson commented 1 year ago

Hi! The same problem exists for non-batch builds too, even if it's easier to work around for those. This should "just work", so that all non-configured builds automatically populate $WS_DIR$ according to the UI selection. I think you've got the right idea with creating a temporary .custom_argvars file, so that it's mostly invisible to the user.

We'll probably allow a build task to point to either a .eww file (which will default to the one selected in the UI) or a .custom_argvars file. When pointed to a .eww file, we'll inject the correct $WS_DIR$ using a temporary file.