1

I'm running VSCode 1.54.3 on Windows10 along with Ubuntu in WSL.

This is the task I'm trying to build.

{
        "label": "Verilog: Compile iVerilog File ",
        "command": "iverilog", 
        "type": "shell",
        "args": [
            "-t vvp",
            "-o ${fileBasename}.vvp",
            "-l /opt/Xilinx/14.7/ISE_DS/ISE/DCM_SP.v",
            "-I /opt/Xilinx/14.7/ISE_DS/ISE/verilog/src/unisims",
            "-I /opt/Xilinx/14.7/ISE_DS/ISE/verilog/src/XilinxCoreLib/",
            "wslpath ${workspaceFolder}${pathSeparator}${relativeFileDirname}${pathSeparator}${fileBasenameNoExtension}.v"                
        ],
        "problemMatcher": [
            "$tsc"
        ],
        "presentation": {
            "reveal": "always"
        },
        "group": "build"
    }

Clearly I'm here because it doesn't work so I'm here to throw myself at the feet of smarter people.

This is what it actually runs

> Executing task in folder xilinx_projects: iverilog '-t vvp' '-o pulse2.v.vvp' '-l /opt/Xilinx/14.7/ISE_DS/ISE/DCM_SP.v' '-I /opt/Xilinx/14.7/ISE_DS/ISE/verilog/src/unisims' '-I /opt/Xilinx/14.7/ISE_DS/ISE/verilog/src/XilinxCoreLib/' 'wslpath C:\demand\xilinx_projects\pulse2\pulse2.v

I've been to the following pages for help:

Single quotes not escaped in debug commands #91578

how-do-i-use-bash-on-ubuntu-on-windows-wsl-for-my-vs-code-terminal

Regression: WSL Shell Task command containing spaces fails

Paths separators in build config being escaped/stripped out prior to build command being run #35593

All double quotes removed from command in tasks.json in powershell #72039

Variable Reference

And of course: Integrate with External Tools via Tasks

I see other people struggling with it. I can't tell if that is current. These things find a way dead ending when someone finally gets it or the problem goes away from some other feature that I must not know about.

I'm sure the answer is somewhere in those links. I just can't find one that works for me. I've tried all kinds of variations of escape characters and none work for me.

You'll also see that the final argument is obscene compared to what someone that knows what they are doing would use. That same command works in "command":, but not as an arg.

I try to avoid asking questions but this is killing me. I fill very close to being able to use tasks to do more but I find the documentation incomplete and without examples of what the shell sees.

You can probably see what I'm trying to accomplish. Can you offer any advice on how to do this as painlessly as possible?

Kritischer
  • 13
  • 4
  • `-t` and `-o` are separate arguments, everything with a space in between is a separate argument, the quotes in the run command output show that the strings are grouped to a single argument with a space – rioV8 Apr 07 '21 at 02:30
  • That solves part of my problem. Thank you. – Kritischer Apr 07 '21 at 02:40
  • What I still don't understand is how to use escape characters or how to invoke wslpath${workspaceFolder}${pathSeparator}${relativeFileDirname}${pathSeparator}${fileBasenameNoExtension}.v from an argument. How do I cheat and use multiple commands? I saw some posts reverring to using && but I can't get that to work (might have been powershell only) – Kritischer Apr 07 '21 at 02:42
  • https://code.visualstudio.com/docs/editor/tasks#_compound-tasks – rioV8 Apr 07 '21 at 09:57

2 Answers2

1

From the "containing spaces fails" issue that you linked to, I wasn't able to get the original version of the sample "My Task" to work, so it almost does seem like the fixed regression has regressed again. Either that, or the new 2.0.0 task system doesn't parse it the same way.

That example used one long "command", but specified the "executable" as wsl.exe. Something else may have changed here, because reading the ${env:windir} as specified there doesn't work for me either when launching vscode from WSL. But no matter, I'm just going to leave off the path for now.

One alternative presented there was to specify each element as a separate arg (i.e. "args": [ "ls", "/", "&&", "echo", "OK", "#", "comment" ]). That does work for me, and your iverilog arguments seem to work when parsed that way as well. At least, it comes out as an unquoted command line. To be honest, the way the "Quoting" section of the Tasks doc reads, it sounds like that is the expected way to do it -- Have each element be a separate "arg". From that page:

If a command and arguments are provided, the task system will use single quotes if the command or arguments contain spaces.

That's exactly what we are seeing, of course.

But there's another alternative I found, as well. A comment further down that thread mentioned passing -c to the (old) ubuntu1804.exe executable. That led me to try something similar for the wsl.exe command, and it worked to pass in args of "-e", "sh", and "-c", along with the full commandline in the "command", like so:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Verilog: Compile iVerilog File",
            "options": {
                "shell": {
                    "executable": "wsl.exe",
                    "args": [
                        "-e"
                      "sh",
                        "-c"
                    ]
                }
            },
            "type": "shell",
            "command": "iverilog -t vvp -o ${fileBasename}.vvp -l /opt/Xilinx/14.7/ISE_DS/ISE/DCM_SP.v -I /opt/Xilinx/14.7/ISE_DS/ISE/verilog/src/unisims -I /opt/Xilinx/14.7/ISE_DS/ISE/verilog/src/XilinxCoreLib/ wslpath ${workspaceFolder}${pathSeparator}${relativeFileDirname}${pathSeparator}${fileBasenameNoExtension}.v",
            "problemMatcher": [
                "$tsc"
            ],
            "presentation": {
                "reveal": "always"
            },
            "group": "build"
        },
        {
            "label": "My Task",
            "options": {
                "shell": {
                    "executable": "wsl.exe",
                    "args": [
                        "-e",
                        "sh",
                        "-c"
                    ]
                }
            },
            "type": "shell",
            "command": "ls / && echo OK # comment",
            "problemMatcher": [],
            "presentation": {
                "reveal": "always"
            },
            "group": "build"
        }
    ]
}

I believe that's your consolidated full command-line for iverilog. I've also included the "My Task" example, which is generic enough that it should work on any WSL system.

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
0

Can you replace corresponding setion of tasks.json with this ?

            "type": "shell",
            "command": "wsl",
            "args": ["bash", "-c", "iverilog\
                -t vvp -o ${fileBasename}.vvp -l /opt/Xilinx/14.7/ISE_DS/ISE/DCM_SP.v\
                -I /opt/Xilinx/14.7/ISE_DS/ISE/verilog/src/unisims\
                -I /opt/Xilinx/14.7/ISE_DS/ISE/verilog/src/XilinxCoreLib/\
 $(wslpath '${workspaceFolder}${pathSeparator}${relativeFileDirname}${pathSeparator}${fileBasenameNoExtension}.v')"]
Philippe
  • 20,025
  • 2
  • 23
  • 32