Visual studio SDK's include path is getting added multiple times to option.txt

Hi,

I have a module to be compiled with visual studio plugin.

There are around 400+ source and header files. While compiling this there is exception thrown for a specific file saying

07:08:10.192 [QUIET] [system.out] UIGridItem.cpp

07:08:23.209 [QUIET] [system.out] Automatically linking with sfl504as.lib

07:08:26.312 [QUIET] [system.out] Automatically linking with ot1104as.lib

07:08:27.790 [QUIET] [system.out] Automatically linking with og1204a.lib

07:08:27.800 [QUIET] [system.out] Automatically linking with RWUXThemeS10.lib

07:10:20.852 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: FAILED

07:10:20.853 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process ‘command ‘C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\cl.exe’’ finished with exit value -1073740777 (state: FAILED)

07:10:20.853 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ‘:Console:compileX86ReleaseConsoleExecutableConsoleCpp’

07:10:20.854 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :Console:compileX86ReleaseConsoleExecutableConsoleCpp FAILED

When I googled for the error code found out that it is

0xC0000417

STATUSINVALIDCRUNTIME_PARAMETER

and typically occurs when command line arguments length is beyond certain threshold (I guess 8k).

When I looked for options.txt in this folder found out that

“/IC:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include”

“/IC:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include”

these two lines are added 191 times to the compiler options. Probably number of files compiled till now.

So my guess is because of this compiler is crashing.

Is there any way we can stop this redundant appending and force gradle to append only once?

Yep, that’s a bug.

It’s been fixed in master, but the fix came too late for the 2.3 release. You can try it out in a nightly.

If you have to use an older release, you can try this workaround (it removes the duplicates from the arguments before they’re sent to the compiler):

model {
    toolChains {
        visualCpp(VisualCpp) {
            eachPlatform { toolChain ->
                toolChain.getCppCompiler().withArguments { args ->
                    args.unique()
                }
            }
        }
    }
}

I created GRADLE-3242 so we’ll be sure to include this in the 2.4 release.

Thanks Sterling.

When I tried to use above snippet, I got below error…

  • What went wrong: A problem occurred configuring project ‘:Console’. > Exception thrown while executing model rule: model.toolChains

Could not find method eachPlatform() for arguments [build_69eqqrdtjqistnifarie5gtlrl$_run_closure1_closure6_closure7_closure8@1892dc8] on Tool chain ‘visualCpp’ (Visual Studio).

I have main build.gradle and around 150+ subproject’s gradle files. What is the right place for this code?

Ihad included it in main build.gradle and it gave error, so moved it to sub module which has more files and have issues, but got same error there as well.

Which version of Gradle are you using?

its 2.1

C:\Developer\workspace\SVN\trunk>gradlew --version

------------------------------------------------------------ Gradle 2.1 ------------------------------------------------------------

Build time:

2014-09-08 10:40:39 UTC Build number: none Revision:

e6cf70745ac11fa943e19294d19a2c527a669a53

Groovy:

2.3.6 Ant:

Apache Ant™ version 1.9.3 compiled on December 23 2013 JVM:

1.6.0_31 (Sun Microsystems Inc. 20.6-b01) OS:

Windows Server 2008 R2 6.1 x86

Ah, sorry. That was added in 2.2+

If you take a look here, there’s an example of customizing the cppCompiler’s arguments: https://gradle.org/docs/2.1/userguide/nativeBinaries.html#native_binaries:tool_chain

I think you can just remove the eachPlatform part.