Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to create database if there is a space in the command argument #73

Open
sandilyabhagi opened this issue Jul 26, 2021 · 10 comments
Open
Labels

Comments

@sandilyabhagi
Copy link

From, https://docs.microsoft.com/en-us/windows-hardware/drivers/devtest/static-tools-and-codeql

C:\codeql-home>C:\codeql-home\codeql\codeql.cmd database create -l=cpp -s=C:\codeql-home\drivers\kmdf -c "msbuild /t:rebuild "C:\codeql-home\drivers\kmdf\kmdfecho.sln" /p:UseSharedCompilation=false" "C:\codeql-home\databases\kmdf" -j 0

If the above command is modified to incorporate configuration the database creation fails,
C:\codeql-home>C:\codeql-home\codeql\codeql.cmd database create -l=cpp -s=C:\codeql-home\drivers\kmdf -c "msbuild /t:rebuild "C:\codeql-home\drivers\kmdf\kmdfecho.sln" /p:Configuration="win10 Debug" /p:UseSharedCompilation=false" "C:\codeql-home\databases\kmdf" -j 0

Error:
The system cannot find the file specified.
Invalid value for positional parameter at index 0 (): cannot convert 'Debug /p:UseSharedCompilation=false' to Path (java.nio.file.InvalidPathException: Trailing char < > at index 5: Debug /p:UseSharedCompilation=false)
Try codeql database create --help for usage help.

However the same command using msbuild succeeds. Also the same command without space works,
C:\codeql-home>C:\codeql-home\codeql\codeql.cmd database create -l=cpp -s=C:\codeql-home\drivers\kmdf -c "msbuild /t:rebuild "C:\codeql-home\drivers\kmdf\kmdfecho.sln" /p:Configuration="win10Debug" /p:UseSharedCompilation=false" "C:\codeql-home\databases\kmdf" -j 0

Creates database successfully.
Initializing database at C:\codeql-home\databases\kmdf.
Running build command: [msbuild, /t:rebuild, kmdfecho.sln, /p:Configuration=win10Debug, /p:UseSharedCompilation=false]

@github-actions github-actions bot added the CLI label Jul 26, 2021
@adityasharad
Copy link
Contributor

Thanks for reporting this! We have a fix in progress that will make it into a future version of CodeQL, most likely 2.6.0.

@sandilyabhagi
Copy link
Author

Thank you Aditya.

@m4sachi
Copy link

m4sachi commented Jul 28, 2021

@adityasharad Is the beta version have the fix for this above issue?

@sandilyabhagi
Copy link
Author

@adityasharad Is this issue fixed in the latest v2.6.0 ? Can you please confirm. Thank you.
I have tried and looks like either it is not fixed or I have tried it incorrectly.

@adityasharad
Copy link
Contributor

To handle spaces in your command arguments, I believe the safest approach is to create a separate batch script that contains your build command, and invoke that from codeql database create. (An alternative is to escape the quotes within the argument to -c "...", but I recommend the separate script as a first approach.)

For example, create a script build.bat containing

msbuild /t:rebuild "C:\codeql-home\drivers\kmdf\kmdfecho.sln" /p:Configuration="win10 Debug" /p:UseSharedCompilation=false

and then run

C:\codeql-home\codeql\codeql.cmd database create -l=cpp -s="C:\codeql-home\drivers\kmdf" -c "build.bat" "C:\codeql-home\databases\kmdf" -j 0

Could you please try that with CodeQL 2.6.0?

@sandilyabhagi
Copy link
Author

@adityasharad Thank you for your response.

To handle spaces in your command arguments, I believe the safest approach is to create a separate batch script that contains your build command, and invoke that from codeql database create. (An alternative is to escape the quotes within the argument to -c "...", but I recommend the separate script as a first approach.)

We are currently using this approach and it is working well from v2.5.8(we started from this version). Only issue is we are adding additional bat file in the process and want to know if it can be avoided. If this is the preferred solution we will continue as suggested.

Thanks for reporting this! We have a fix in progress that will make it into a future version of CodeQL, most likely 2.6.0.

Just confirming since it was mentioned. Please keep us posted in case if it can be expected in upcoming releases.

@sandilyabhagi
Copy link
Author

(An alternative is to escape the quotes within the argument to -c "...", but I recommend the separate script as a first approach.)

Hi @adityasharad tried escaping the quotes and didn't work. Tried the following and none of them worked. Do you have anything to suggest here to escape the quotes,

  1. Without any quotes for msbuild command argument
    call D:\work\CodeQL\codeql-home\codeql-win64-2.6.0\codeql\codeql.cmd database create -l=cpp -s=%CURDIR%\Src\kernel\mydrv -c "msbuild myproj.VcxProj /t:Rebuild /p:Configuration=Windows 10 Release" "D:\work\CodeQL\codeql-home\databases\myproj" -j 0
    Running build command: [msbuild, myproj.VcxProj, /t:Rebuild, /p:Configuration=Windows, 10, Release]
    [2021-08-30 12:08:43] [build-stdout] Switch: 10
    [2021-08-30 12:08:43] [ERROR] Spawned process exited abnormally (code 1; tried to run: [D:\work\CodeQL\codeql-home\codeql-win64-2.6.0\codeql\tools\win64\tracer.exe, D:\work\CodeQL\codeql-home\codeql-win64-2.6.0\codeql\tools\win64\runner.exe, cmd.exe, /C, type, NUL, &&, msbuild, myproj.VcxProj, /t:Rebuild, /p:Configuration=Windows, 10, Release])
    A fatal error occurred: Exit status 1 from command: [D:\work\CodeQL\codeql-home\codeql-win64-2.6.0\codeql\tools\win64\runner.exe, cmd.exe, /C, type, NUL, &&, msbuild, myproj.VcxProj, /t:Rebuild, /p:Configuration=Windows, 10, Release]

  2. With Single quote for msbuild command argument
    call D:\work\CodeQL\codeql-home\codeql-win64-2.6.0\codeql\codeql.cmd database create -l=cpp -s=%CURDIR%\Src\kernel\mydrv -c "msbuild myproj.VcxProj /t:Rebuild /p:Configuration='Windows 10 Release'" "D:\work\CodeQL\codeql-home\databases\myproj" -j 0
    Running build command: [msbuild, myproj.VcxProj, /t:Rebuild, /p:Configuration='Windows, 10, Release']
    [2021-08-30 12:09:19] [build-stdout] Switch: 10
    [2021-08-30 12:09:19] [ERROR] Spawned process exited abnormally (code 1; tried to run: [D:\work\CodeQL\codeql-home\codeql-win64-2.6.0\codeql\tools\win64\tracer.exe, D:\work\CodeQL\codeql-home\codeql-win64-2.6.0\codeql\tools\win64\runner.exe, cmd.exe, /C, type, NUL, &&, msbuild, myproj.VcxProj, /t:Rebuild, /p:Configuration='Windows, 10, Release'])
    A fatal error occurred: Exit status 1 from command: [D:\work\CodeQL\codeql-home\codeql-win64-2.6.0\codeql\tools\win64\runner.exe, cmd.exe, /C, type, NUL, &&, msbuild, myproj.VcxProj, /t:Rebuild, /p:Configuration='Windows, 10, Release']

  3. With Double quotes for msbuild command argument
    call D:\work\CodeQL\codeql-home\codeql-win64-2.6.0\codeql\codeql.cmd database create -l=cpp -s=%CURDIR%\Src\kernel\mydrv -c "msbuild myproj.VcxProj /t:Rebuild /p:Configuration="Windows 10 Release"" "D:\work\CodeQL\codeql-home\databases\myproj" -j 0
    The system cannot find the file specified.
    Unmatched arguments from index 5: 'Release', 'D:\work\CodeQL\codeql-home\databases\myproj'

  4. With Double quotes escaped with \ for msbuild command argument
    call D:\work\CodeQL\codeql-home\codeql-win64-2.6.0\codeql\codeql.cmd database create -l=cpp -s=%CURDIR%\Src\kernel\mydrv -c "msbuild myproj.VcxProj /t:Rebuild /p:Configuration=\"Windows 10 Release\"" "D:\work\CodeQL\codeql-home\databases\myproj" -j 0
    Initializing database at D:\work\CodeQL\codeql-home\databases\myproj.
    A fatal error occurred: Failed to expand 'msbuild myproj.VcxProj /t:Rebuild /p:Configuration="Windows 10 Release"' as an argument list.
    (eventual cause: UserError "At position 54, the quote should either be preceded by a space (if it is intende...")

  5. With Double quotes only for msbuild command argument
    call D:\work\CodeQL\codeql-home\codeql-win64-2.6.0\codeql\codeql.cmd database create -l=cpp -s=%CURDIR%\Src\kernel\mydrv -c msbuild myproj.VcxProj /t:Rebuild /p:Configuration="Windows 10 Release" "D:\work\CodeQL\codeql-home\databases\myproj" -j 0
    Unmatched arguments from index 5: '/t:Rebuild', '/p:Configuration=Windows 10 Release', 'D:\work\CodeQL\codeql-home\databases\myproj'
    Try codeql database create --help for usage help.

@sam-cha-tfs
Copy link

Has this been resolved? running into the same issue

@qianfei11
Copy link

Running into the same issue in release 2.15.1, solved by putting the commands into a shell script and replace the command with the script.

@sam-cha-tfs
Copy link

@qianfei11 I think this is a ongoing issue. I had to do the same thing in order to get the commands to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants