[native] how can I get compile warnings printed in the console window?


(Ralf Schallenberg) #1

I want to see compiler and linker warnings in the output that is printed to the console, just like compiler and linker errors. Is there a way to configure that?


(Sterling Greene) #2

At the moment, there’s not a way to configure the native tools to always display output. We only show the output when something fails.

You can see the warnings with --info, but you’ll get other output too.


(Ralf Schallenberg) #3

The reason I want this, is to populate the “Error List” window in Visual Studio with warnings and errors, not just errors. How can I create the Visual Studio projects such that they include --info when calling Gradle? I know I could add that by hand, but I would have to touch quite a few projects, and the change would be overwritten, the next time I let Gradle create the Visual Studio files again.


(Sterling Greene) #4

You can try:

tasks.withType(GenerateProjectFileTask) {
    gradleArgs = "--info"
}

I think we’ll still limit the output to the first 10 files compiled.


(Ralf Schallenberg) #5

That worked, thanks! :slight_smile:


(Donal Mac Carthy) #6

Hi, I noticed this hasn’t received any updates since, but as of gradle 3.1 this behaviour still exists. Are there any plans to implement this? I’ve submitted a bug on github: https://github.com/gradle/gradle/issues/810


(Andre Kampling) #7

I’m also interested in the compiler warnings and errors printed at the console window.
The following worked for me, but there is too much output I don’t want to see.

So I tried the following with the intention to only set the log level for compiling tasks.

tasks.whenTaskAdded { task ->
   if (task instanceof CCompile || task instanceof CppCompile) {
      logging.setLevel(LogLevel.INFO)
   }
}

But it has no effect!
Any help will be appreciated.


(Andre Kampling) #8

To output the compiler warnings and options I do the following which I also posted on StackOverflow, see here. It is not while the compiler is doing his actions but afterwards.

To add a task after the compile and link task I add the following (this task will be executed if the build failed or succeeded).

tasks.withType(InstallExecutable) {
   finalizedBy showCompilerOutput
}

If you just want to execute showCompilerOutput if the build was successful you can use this:

build.finalizedBy showCompilerOutput

The task showCompilerOutput is for displaying the output of the files I mentioned in my question. Therefore it builds a file tree which points to the files that I mentioned: output.txt.

task showCompilerOutput {
   dependsOn showCompilerOptions
   doLast {
      println '\n-----------------------------------------------------\n'
      println 'Compiler output:'
      FileTree tree = fileTree('build').include('**/output.txt')
      // Iterate over the contents of a tree
      tree.each {File file ->
          println 'Content of file ' + file + ':\n'
          println file.text
          println '------\n'
      }
   }
}

This task is also dependend of another task which is called showCompilerOptions, which is doing the same but for the files with the compiler options: options.txt.

task showCompilerOptions {
   doLast {
      println '\n-----------------------------------------------------\n'
      println 'Compiler options:'
      FileTree tree = fileTree('build').include('**/options.txt')
      // Iterate over the contents of a tree
      tree.each {File file ->
          println 'Content of file ' + file + ':\n'
          println file.text
          println '------\n'
      }
   }
}