question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Command Line too long

See original GitHub issue

The command line generated appears to exceed a threshold

Perhaps it would be better to generate a command file, to avoid command length limitations

The command line is too long.
Write-Err : Cannot bind argument to parameter 'msg' because it is an empty string.
At C:\Users\GeorgeRu\AppData\Local\Microsoft\VisualStudio\15.0_13f2e2ac\Extensions\43s1b10b.dwz\clang-build.ps1:567 
char:15
+     Write-Err ($compileResult.Output)
+               ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Write-Err], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Write-Err

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
ghostcommented, Jul 16, 2018

Hello guys,

I had some time and looked into why Tidy does not work. The mentioned “YAML” error indeed means, Tidy does not treat the “–config” option the same way as Clang does.

To put it short: for a Clang run, we can put the whole command line into a file and call Clang with “–config filename” For a Tidy run, we have a command line like this: clang-tidy.exe tidy-params – params-passed-from-tidy-to-clang

So the command line includes the Tidy params as well as the params passed on from Tidy to Clang, separated by “–”.

You guessed the solution yet? Split the Tidy command line at the “–” separator and pass the left side to Tidy, and pass the right side as in a file to Clang.

I have tested this and it works for me with LLVM6, VS2017 with Clang and Tidy runs.

To patch your installation, please:

  1. find and backup the clang-build.ps1 file
  2. find the Run-ClangJobs function
  3. find the code block which starts with: if ($aUseParallelCompile)
  4. Copy-paste this code BEFORE the above block:
    $tmp = [System.IO.Path]::GetTempFileName()
    Write-Verbose "Params saved to $tmp"

    if($job.FilePath -like '*tidy*')
    {
      #Tidy: split parameters: tidy params and clang params
      $splitparams = $job.ArgumentList -split "--"
      $splitparams[1] -replace '\\', '/' | Out-File $tmp
      #pass clang params as file
      $job.ArgumentList = ($splitparams[0] + " -- --config $tmp")
    }
    else
    {
      #Clang: save options to config file
      $job.ArgumentList -replace '\\', '/' | Out-File $tmp
      $job.ArgumentList = "--config $tmp"
    }

  1. Now you should be able to run Clang compile and Tidy using the PowerTools Plugin.

I am not a PowerShell programmer so maybe it is not elegant, not optimal, but it works. It checks if we are doing a Clang or a Tidy run. For a Clang run, the command line is simply saved. For a Tidy run, the string will be split and the left side goes to Tidy, the rest to Clang.

I hope the developers will look into this and give us a fix soon. Have fun guys.

1reaction
hero101111commented, Jul 23, 2018

Excellent solution, @dzolee.

At first, we were skeptical of this approach, since it means creating and deleting thousands of temporary files, one per cpp. We don’t want to slow down Clang Power Tools and we also want to avoid having two (or more) ways of doing things. So we decided to test for it…

We ran a multitude of compilation tests on our test repository, consisting of around 140 projects and 8000 CPP files. To our surprise, we found that the temporary-file creation and deletion additional cost is practically zero.

In the majority of tests the compilation was slightly faster (around 1%) than the baseline of the control group. There appears to be a tiny time cost associated with a long command line, perhaps from CMD.EXE command line parsing. The tests were ran on the same machine, in identical conditions, on both SSDs and HDDs, yielding similar results.

We are very pleased with the results and are happy to inform you that starting with Clang Power Tools v3.8 (i.e. next release) we’ll move to using config files for giving arguments to clang.

Thank you all for your very insightful and helpful feedback.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IDEA 10.5 Command line is too long
In Intellij, go to "edit configurations" (Run -> Edit Configurations), in the configuration tab that comes up in the line "shorten command ......
Read more >
"command line is too long" error message
First, "command line" is where you type and execute commands, not the command itself. I suggest renaming the option to Shorten command.
Read more >
Command prompt line string limitation - Windows Client
The maximum length of the string that you can use at the command prompt is 8191 characters. This limitation applies to: the command...
Read more >
Intellij - fix for Error running unit tests. Command line is too ...
Command line is too long. Shorten the command line via JAR manifest or via a classpath file and rerun.
Read more >
How to fix " Command line is too long. Shorten ... - YouTube
Error running 'CSVExample': Command line is too long. Shorten command line for CSVExample.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found