Intermittent error -- Changing header files does not trigger recompilation


(Aleksey) #1

Hello
It looks like gradle have a problem with defining if a header file was changed or not
Here is an example:

`
ak@ak:~/g/header_change$ tree
.
├── build.gradle
└── src
├── header1
│ └── headers
│ └── header1.hpp
└── main
└── cpp
└── main.cpp

5 directories, 3 files
ak@ak:~/g/header_change$

ak@ak:~/g/header_change$ cat build.gradle

task wrapper(type: Wrapper) {
gradleVersion = ‘2.11’
}

apply plugin: ‘cpp’

model {
components {
header1(NativeLibrarySpec)
main(NativeExecutableSpec) {
sources {
cpp.lib library: ‘header1’
}
}
}
}ak@ak:~/g/header_change$

ak@ak:~/g/header_change$ cat ./src/header1/headers/header1.hpp
#include
ak@ak:~/g/header_change$

ak@ak:~/g/header_change$ cat ./src/main/cpp/main.cpp
#include “header1.hpp”

int main(int argc, char *argv[])
{
return 0;
}
ak@ak:~/g/header_change$

`

Next, I compile the example:
`
ak@ak:~/g/header_change$ gradle wrapper
:wrapper

BUILD SUCCESSFUL

Total time: 4.434 secs

This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.11-20160310115910+0000/userguide/gradle_daemon.html
ak@ak:~/g/header_change$

ak@ak:~/g/header_change$ ./gradlew build
:linkHeader1SharedLibrary UP-TO-DATE
:header1SharedLibrary UP-TO-DATE
:createHeader1StaticLibrary UP-TO-DATE
:header1StaticLibrary UP-TO-DATE
:compileMainExecutableMainCpp
:linkMainExecutable
:mainExecutable
:assemble
:check UP-TO-DATE
:build

BUILD SUCCESSFUL

Total time: 3.879 secs
`

Then I change header1.cpp:
ak@ak:~/g/header_change$ cat ./src/header1/headers/header1.hpp #include <string> "GREAT CHANGE" ak@ak:~/g/header_change$

Gradle does not see the change in header1.cpp

`
ak@ak:~/g/header_change$ ./gradlew build
:linkHeader1SharedLibrary UP-TO-DATE
:header1SharedLibrary UP-TO-DATE
:createHeader1StaticLibrary UP-TO-DATE
:header1StaticLibrary UP-TO-DATE
:compileMainExecutableMainCpp
:linkMainExecutable UP-TO-DATE
:mainExecutable UP-TO-DATE
:assemble UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE

BUILD SUCCESSFUL

Total time: 3.454 secs
`

If I change header1.cpp in a bit different way, gradle can see that cahnge:

ak@ak:~/g/header_change$ cat ./src/header1/headers/header1.hpp #include <string> "GREAT CHANGE" ak@ak:~/g/header_change$

`
ak@ak:~/g/header_change$ ./gradlew build
:linkHeader1SharedLibrary UP-TO-DATE
:header1SharedLibrary UP-TO-DATE
:createHeader1StaticLibrary UP-TO-DATE
:header1StaticLibrary UP-TO-DATE
:compileMainExecutableMainCpp
In file included from /home/ak/g/header_change/src/main/cpp/main.cpp:1:0:
/home/ak/g/header_change/src/header1/headers/header1.hpp:2:1: error: expected unqualified-id before string constant
"GREAT CHANGE"
^

:compileMainExecutableMainCpp FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:compileMainExecutableMainCpp’.

A build operation failed.
C++ compiler failed while compiling main.cpp.
See the complete log at: file:///home/ak/g/header_change/build/tmp/compileMainExecutableMainCpp/output.txt

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 3.477 secs

`

Aleksey

Gradle Version:
2.11 in the example, but it also found in 2,14
Operating System:
Linux


(Aleksey) #2

Unfortunately I did not notice something like “preview” button and my message looks ugly

here is what I wanted to write

original header file:

"#include "


(Aleksey) #3

original header file:
#include <string>

the change which gradle cannot see:
#include <string> "GREAT CHANGE"

the change which gradle can see:
#include <string>
"GREAT CHANGE"


(Thomas Pohl) #4

Has anybody an idea what caused this behavior. I’ve the impression in our build we also don’t get the incremental check right if we just change something in a header file.

Is there any specific logic in gradle to ignore header changes in some cases? Like parsing the headers and only create checksums of certain aspects in the files?

Or are there cases when simply headers are not considered as inputs?

Any clarification on the underlying concepts would help a lot understand the issues.