/
CppIncrementalBuildIntegrationTest.groovy
1602 lines (1262 loc) · 40.6 KB
/
CppIncrementalBuildIntegrationTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.language.cpp
import org.gradle.integtests.fixtures.CompilationOutputsFixture
import org.gradle.integtests.fixtures.ToBeFixedForConfigurationCache
import org.gradle.integtests.fixtures.executer.GradleContextualExecuter
import org.gradle.integtests.fixtures.executer.GradleExecuter
import org.gradle.nativeplatform.fixtures.AbstractInstalledToolChainIntegrationSpec
import org.gradle.nativeplatform.fixtures.AvailableToolChains
import org.gradle.test.fixtures.file.TestFile
import spock.lang.IgnoreIf
import spock.lang.Unroll
import static org.junit.Assume.assumeFalse
// This is failing on release6x and we don't want to spent time on it
@IgnoreIf({ GradleContextualExecuter.isForceRealize() })
class CppIncrementalBuildIntegrationTest extends AbstractInstalledToolChainIntegrationSpec implements CppTaskNames {
private static final String LIBRARY = ':library'
private static final String APP = ':app'
TestFile appSourceFile
TestFile appOtherSourceFile
TestFile appHeaderFile
TestFile libraryHeaderFile
TestFile libraryImplHeaderFile
TestFile librarySourceFile
TestFile libraryOtherSourceFile
String sourceType = "cpp"
def libObjects = new CompilationOutputsFixture(file("library/build/obj/main/debug"), [".o", ".obj"])
def appObjects = new CompilationOutputsFixture(file("app/build/obj/main/debug"), [".o", ".obj"])
def install = installation("app/build/install/main/debug")
def libraryDebug = tasks(LIBRARY).debug
def appDebug = tasks(APP).debug
def installApp = appDebug.install
def setup() {
assumeFalse(toolChain.family == AvailableToolChains.ToolFamily.CYGWIN_GCC) // [test setup issue] fails with - greet.cpp:2:22: fatal error: app.hpp: No such file or directory
buildFile << """
project(':library') {
apply plugin: 'cpp-library'
}
project(':app') {
apply plugin: 'cpp-application'
dependencies {
implementation project(':library')
}
}
"""
settingsFile << """
rootProject.name = 'test'
include 'library', 'app'
"""
appHeaderFile = file("app/src/main/cpp/app.hpp") << """
#include <string>
extern void greeting(const char* name, std::string& result);
"""
appSourceFile = file("app/src/main/cpp/main.cpp") << """
#include <lib.h>
#include <iostream>
#include "app.hpp"
using namespace std;
int main() {
string msg;
greeting("world", msg);
log(msg);
return 0;
}
"""
appOtherSourceFile = file("app/src/main/cpp/greet.cpp")
appOtherSourceFile << """
#include "app.hpp"
#define PREFIX "hello"
using namespace std;
extern void greeting(const char* name, string& result) {
result.append(PREFIX);
result.append(" ");
result.append(name);
}
"""
libraryHeaderFile = file("library/src/main/public/lib.h")
libraryHeaderFile << """
#pragma once
#include <string>
#ifdef _WIN32
#define EXPORT_FUNC __declspec(dllexport)
#else
#define EXPORT_FUNC
#endif
void EXPORT_FUNC log(const std::string& message);
void EXPORT_FUNC log(const char* message);
"""
libraryImplHeaderFile = file("library/src/main/headers/lib_impl.h")
libraryImplHeaderFile << """
#pragma once
"""
librarySourceFile = file("library/src/main/cpp/log_string.cpp")
librarySourceFile << """
#include <lib.h>
#include <lib_impl.h>
#include <iostream>
using namespace std;
void log(const string& message) {
cout << message;
}
"""
libraryOtherSourceFile = file("library/src/main/cpp/log_chars.cpp")
libraryOtherSourceFile << """
#include <lib.h>
#include <iostream>
#include "lib_impl.h"
using namespace std;
void log(const char* message) {
cout << message;
}
"""
}
@ToBeFixedForConfigurationCache
def "rebuilds executable with single source file change"() {
given:
run installApp
libObjects.snapshot()
appObjects.snapshot()
when:
appSourceFile.replace("world", "planet")
and:
run installApp
then:
result.assertTasksExecuted(libraryDebug.allToLink, appDebug.allToInstall)
result.assertTasksSkipped(libraryDebug.allToLink)
result.assertTasksNotSkipped(appDebug.allToInstall)
and:
libObjects.noneRecompiled()
appObjects.recompiledFile(appSourceFile)
// Test assumes that the app has multiple source files and only one of them has changed. Verify that assumption
appObjects.hasFiles(appSourceFile, appOtherSourceFile)
and:
install.assertInstalled()
install.exec().out == "hello planet"
when:
run installApp
then:
allSkipped()
}
@ToBeFixedForConfigurationCache
def "recompiles library and relinks executable after single library source file change"() {
given:
run installApp
libObjects.snapshot()
appObjects.snapshot()
when:
librarySourceFile.replace("cout << message", 'cout << "[" << message << "]"')
and:
run installApp
then:
result.assertTasksExecuted(libraryDebug.allToLink, appDebug.allToInstall)
if (toolChain.visualCpp) {
// App link may or may not be required
skipped appDebug.compile
executed libraryDebug.compile, libraryDebug.link
executed appDebug.install
} else {
result.assertTasksSkipped(appDebug.compile)
result.assertTasksNotSkipped(libraryDebug.allToLink, appDebug.link, appDebug.install)
}
and:
appObjects.noneRecompiled()
libObjects.recompiledFile(librarySourceFile)
and:
install.assertInstalled()
install.exec().out == "[hello world]"
when:
run installApp
then:
allSkipped()
}
@ToBeFixedForConfigurationCache
def "recompiles binary and does not relink when public header file changes in a way that does not affect the object files"() {
given:
run installApp
libObjects.snapshot()
appObjects.snapshot()
when:
libraryHeaderFile << """
// Comment added to the end of the header file
"""
run installApp
then:
executedAndNotSkipped libraryDebug.compile
executedAndNotSkipped appDebug.compile
if (nonDeterministicCompilation) {
// Relinking may (or may not) be required after recompiling
executed libraryDebug.link
executed appDebug.link, installApp
} else {
skipped libraryDebug.link
skipped appDebug.link, installApp
}
and:
appObjects.recompiledFile(appSourceFile)
libObjects.recompiledFiles(librarySourceFile, libraryOtherSourceFile)
when:
run installApp
then:
allSkipped()
}
@ToBeFixedForConfigurationCache
def "recompiles binary when implementation header file changes"() {
given:
run installApp
libObjects.snapshot()
appObjects.snapshot()
when:
libraryImplHeaderFile << """
#define UNUSED_MACRO 123
"""
run installApp
then:
executedAndNotSkipped libraryDebug.compile
skipped appDebug.compile
if (nonDeterministicCompilation) {
// Relinking may (or may not) be required after recompiling
executed libraryDebug.link
executed appDebug.link, installApp
} else {
skipped libraryDebug.link
skipped appDebug.link, installApp
}
and:
appObjects.noneRecompiled()
libObjects.recompiledFiles(librarySourceFile, libraryOtherSourceFile)
when:
run installApp
then:
allSkipped()
}
@ToBeFixedForConfigurationCache
def "recompiles only those source files affected by a header file change"() {
given:
def greetingHeader = file("app/src/main/headers/greeting.hpp")
greetingHeader << """
#define PREFIX "hello"
"""
appOtherSourceFile.text = """
#include "app.hpp"
#include "greeting.hpp"
using namespace std;
void greeting(const char* name, string& result) {
result.append(PREFIX);
result.append(" ");
result.append(name);
}
"""
run installApp
libObjects.snapshot()
appObjects.snapshot()
when:
greetingHeader.replace("hello", "hi")
run installApp
then:
result.assertTasksSkipped(libraryDebug.allToLink)
executedAndNotSkipped appDebug.compile
and:
libObjects.noneRecompiled()
appObjects.recompiledFile(appOtherSourceFile)
// Test assumes there are multiple source files: one that includes the header and one that does not. Verify that assumption
appObjects.hasFiles(appSourceFile, appOtherSourceFile)
when:
libObjects.snapshot()
appObjects.snapshot()
run installApp
then:
allSkipped()
and:
libObjects.noneRecompiled()
appObjects.noneRecompiled()
}
@ToBeFixedForConfigurationCache
def "considers only those headers that are reachable from source files as inputs"() {
given:
def unused = file("app/src/main/headers/ignore1.h") << "broken!"
def unusedPrivate = file("app/src/main/cpp/ignore2.h") << "broken!"
run installApp
libObjects.snapshot()
appObjects.snapshot()
when:
unused << "even more broken"
unusedPrivate << "even more broken"
file("src/main/headers/ignored3.h") << "broken"
file("src/main/headers/some-dir").mkdirs()
file("src/main/cpp/ignored4.h") << "broken"
file("src/main/cpp/some-dir").mkdirs()
run installApp
then:
allSkipped()
when:
unused.delete()
unusedPrivate.delete()
run installApp
then:
allSkipped()
when:
libraryHeaderFile << """
int unused();
"""
run installApp
then:
executedAndNotSkipped libraryDebug.compile
executedAndNotSkipped appDebug.compile
and:
appObjects.recompiledFile(appSourceFile)
libObjects.recompiledFiles(librarySourceFile, libraryOtherSourceFile)
}
@ToBeFixedForConfigurationCache
def "header file referenced using relative path is considered an input"() {
given:
def unused = file("app/src/main/headers/ignore1.h") << "broken!"
appOtherSourceFile.replace('#define PREFIX "hello"', '#include "../not_included/hello.h"')
def headerFile = file("app/src/main/not_included/hello.h") << """
const char* get_hello();
#define PREFIX get_hello()
"""
def sourceFile = file("app/src/main/cpp/hello.cpp")
sourceFile.text = """
#include <iostream>
#include "../not_included/hello.h"
const char* get_hello() {
return "Hi";
}
"""
run installApp
appObjects.snapshot()
libObjects.snapshot()
when:
succeeds installApp
install.exec().out == "Hi world"
then:
allSkipped()
when:
headerFile << "void another_thing();"
then:
succeeds installApp
and:
executedAndNotSkipped appDebug.compile
skipped libraryDebug.compile
and:
appObjects.recompiledFiles(appOtherSourceFile, sourceFile)
libObjects.noneRecompiled()
and:
install.exec().out == "Hi world"
when:
unused << "broken again"
then:
succeeds installApp
install.exec().out == "Hi world"
and:
allSkipped()
}
@Unroll
@ToBeFixedForConfigurationCache
def "header file referenced using macro #macro is considered an input"() {
when:
def unused = file("app/src/main/headers/ignore1.h") << "broken!"
file("app/src/main/headers/defs.h") << """
#define _HELLO_HEADER_2 "hello.h"
#define _HELLO_HEADER_1 _HELLO_HEADER_2
#define HELLO_HEADER MACRO_FUNCTION() // some indirection
#define MACRO_FUNCTION( ) _HELLO_HEADER_1
#define FUNCTION_RETURNS_STRING(X) "hello.h"
#define FUNCTION_RETURNS_MACRO(X) HELLO_HEADER
#define FUNCTION_RETURNS_MACRO_CALL(X) FUNCTION_RETURNS_ARG(X)
#define FUNCTION_RETURNS_ARG(X) X
#define PREFIX MACRO_USES
#define SUFFIX() _FUNCTION
#define ARGS (MACRO_FUNCTION())
// Token concatenation ## does not macro expand macro function args, so is usually wrapped by another macro function
#define CONCAT_FUNCTION2(X, Y) X ## Y
#define CONCAT_FUNCTION(X, Y) CONCAT_FUNCTION2(X, Y)
"""
def headerFile = file("app/src/main/headers/hello.h") << """
#define MESSAGE "one"
"""
appSourceFile.text = """
#include "defs.h"
#define MACRO_USES_ANOTHER_MACRO HELLO_HEADER
#define MACRO_USES_STRING_CONSTANT "hello.h"
#define MACRO_USES_SYSTEM_PATH <hello.h>
#define MACRO_USES_FUNCTION MACRO_FUNCTION()
#define MACRO_USES_FUNCTION_WITH_ARGS FUNCTION_RETURNS_MACRO_CALL(MACRO_USES_FUNCTION)
#define MACRO_USES_CONCAT_FUNCTION CONCAT_FUNCTION(PREFIX, SUFFIX())
#ifdef _MSC_VER // only for Visual C++
#define MACRO_PRODUCES_FUNCTION_CALL CONCAT_FUNCTION(FUNCTION_RETURNS_ARG, ARGS)
#else
#define MACRO_PRODUCES_FUNCTION_CALL "hello.h" // ignore
#endif
#include ${macro}
#include <iostream>
int main () {
std::cout << MESSAGE;
return 0;
}
"""
then:
succeeds installApp
and:
assert install.exec().out == "one"
when:
succeeds installApp
appObjects.snapshot()
libObjects.snapshot()
then:
allSkipped()
when:
headerFile.replace('one', 'two')
succeeds installApp
then:
executedAndNotSkipped appDebug.compile
skipped libraryDebug.compile
and:
appObjects.recompiledFiles(appSourceFile)
libObjects.noneRecompiled()
and:
install.exec().out == "two"
when:
unused << "more broken"
succeeds installApp
then:
allSkipped()
where:
macro << [
"MACRO_USES_STRING_CONSTANT",
"MACRO_USES_SYSTEM_PATH",
"MACRO_USES_ANOTHER_MACRO",
"MACRO_USES_FUNCTION",
"MACRO_USES_FUNCTION_WITH_ARGS",
"MACRO_USES_CONCAT_FUNCTION",
"MACRO_PRODUCES_FUNCTION_CALL",
"MACRO_FUNCTION()",
"FUNCTION_RETURNS_STRING(ignore)",
"FUNCTION_RETURNS_MACRO(ignore)",
"FUNCTION_RETURNS_ARG(HELLO_HEADER)"
]
}
@Unroll
@ToBeFixedForConfigurationCache
def "header file referenced using external macro #macro is considered an input"() {
when:
def unused = file("app/src/main/headers/ignore1.h") << "broken!"
file("app/src/main/headers/defs.h") << """
#define HEADER "hello.h"
#define HEADER_FUNC() "hello.h"
"""
def headerFile = file("app/src/main/headers/hello.h") << """
#define MESSAGE "one"
"""
appSourceFile.text = """
#include "defs.h"
#include MACRO
#include <iostream>
int main () {
std::cout << MESSAGE;
return 0;
}
"""
buildFile << """
project(':app') {
tasks.withType(CppCompile) {
macros.put('MACRO','${macro}')
}
}
"""
then:
succeeds installApp
and:
assert install.exec().out == "one"
when:
succeeds installApp
appObjects.snapshot()
libObjects.snapshot()
then:
allSkipped()
when:
headerFile.replace('one', 'two')
succeeds installApp
then:
executedAndNotSkipped appDebug.compile
skipped libraryDebug.compile
and:
appObjects.recompiledFiles(appSourceFile)
libObjects.noneRecompiled()
and:
install.exec().out == "two"
when:
unused << "more broken"
succeeds installApp
then:
allSkipped()
where:
macro << [
'"hello.h"',
'<hello.h>',
'HEADER',
'HEADER_FUNC()'
]
}
@Unroll
@ToBeFixedForConfigurationCache
def "considers all header files as input to source file with complex macro include #include"() {
when:
appSourceFile.text = """
$text
#include <iostream>
int main () {
std::cout << GREETING;
return 0;
}
"""
def headerFile = file("app/src/main/headers/ignore.h") << """
IGNORE ME
"""
file("app/src/main/headers/hello.h") << """
#define GREETING "hello"
"""
then:
executer.withArgument("-i")
succeeds installApp
output.contains("Cannot locate header file for '#include $include' in source file 'main.cpp'. Assuming changed.")
install.exec().out == "hello"
// Test assumes there are 2 source files: one with unresolvable macros and one without. Verify that assumption
appObjects.hasFiles(appSourceFile, appOtherSourceFile)
when:
headerFile.text = "changed"
appObjects.snapshot()
libObjects.snapshot()
then:
executer.withArgument("-i")
succeeds installApp
and:
appObjects.recompiledFiles(appSourceFile)
libObjects.noneRecompiled()
and:
executedAndNotSkipped appDebug.compile
skipped libraryDebug.compile
unresolvedHeadersDetected(appDebug.compile)
when:
headerFile.delete()
appObjects.snapshot()
libObjects.snapshot()
then:
executer.withArgument("-i")
succeeds installApp
and:
appObjects.recompiledFiles(appSourceFile)
libObjects.noneRecompiled()
and:
executedAndNotSkipped appDebug.compile
skipped libraryDebug.compile
unresolvedHeadersDetected(appDebug.compile)
when:
succeeds installApp
then:
allSkipped()
when:
file("app/src/main/headers/some-dir").mkdirs()
succeeds installApp
then:
allSkipped()
when:
file("app/src/main/headers/some-dir").deleteDir()
succeeds installApp
then:
allSkipped()
when:
disableTransitiveUnresolvedHeaderDetection()
headerFile.text = "changed again"
appObjects.snapshot()
libObjects.snapshot()
then:
succeeds installApp
and:
appObjects.noneRecompiled()
libObjects.noneRecompiled()
and:
skipped appDebug.compile
skipped libraryDebug.compile
where:
include | text
'HELLO' | '''
#define _HELLO(X) #X
#define HELLO _HELLO(hello.h)
#include HELLO
'''
'_HELLO(hello . h)' | '''
#define _HELLO(X) #X
#include _HELLO(hello.h)
'''
'MISSING' | '''
#ifdef MISSING
#include MISSING
#else
#include "hello.h"
#endif
'''
'GARBAGE' | '''
#if 0
#define GARBAGE a b c
#include GARBAGE
#else
#include "hello.h"
#endif
'''
'a b c' | '''
#if 0
#include a b c
#else
#include "hello.h"
#endif
'''
}
@ToBeFixedForConfigurationCache
def "does not consider all header files as inputs if complex macro include is found in dependency and special flag is active"() {
when:
appSourceFile.text = """
#include "headers.h"
#include <iostream>
int main () {
std::cout << GREETING;
return 0;
}
"""
file("app/src/main/headers/headers.h") << """
#define _HELLO(X) #X
#define HELLO _HELLO(hello.h)
#include HELLO
"""
file("app/src/main/headers/hello.h") << """
#define GREETING "hello"
"""
def headerFile = file("app/src/main/headers/ignore.h") << """
IGNORE ME
"""
then:
succeeds installApp
install.exec().out == "hello"
when:
appObjects.snapshot()
libObjects.snapshot()
and:
headerFile.text = "changed 1"
then:
succeeds installApp, '--info'
and:
executedAndNotSkipped appDebug.compile
skipped libraryDebug.compile
unresolvedHeadersDetected(appDebug.compile)
and:
appObjects.recompiledFiles(appSourceFile)
libObjects.noneRecompiled()
when:
disableTransitiveUnresolvedHeaderDetection()
and:
appObjects.snapshot()
libObjects.snapshot()
and:
headerFile.text = "changed 3"
then:
succeeds installApp
and:
allSkipped()
and:
appObjects.noneRecompiled()
libObjects.noneRecompiled()
}
private GradleExecuter disableTransitiveUnresolvedHeaderDetection() {
executer.beforeExecute {
withArgument("-Dorg.gradle.internal.native.headers.unresolved.dependencies.ignore=true")
}
return executer
}
@ToBeFixedForConfigurationCache
def "can have a cycle between header files"() {
def header1 = file("app/src/main/headers/hello.h")
def header2 = file("app/src/main/headers/other.h")
when:
header1 << """
#ifndef HELLO
#define HELLO
#include "other.h"
#endif
"""
header2 << """
#ifndef OTHER
#define OTHER
#define MESSAGE "hello"
#include "hello.h"
#endif
"""
appSourceFile.text = """
#include <iostream>
#include "hello.h"
int main () {
std::cout << MESSAGE;
return 0;
}
"""
then:
succeeds installApp
install.exec().out == "hello"
when:
succeeds installApp
then:
allSkipped()
when:
appObjects.snapshot()
libObjects.snapshot()
header1 << """// some extra stuff"""
then:
succeeds installApp
executedAndNotSkipped appDebug.compile
skipped libraryDebug.compile
and:
appObjects.recompiledFiles(appSourceFile)
libObjects.noneRecompiled()
when:
succeeds installApp
then:
allSkipped()
}
@ToBeFixedForConfigurationCache
def "can reference a missing header file"() {
def header = file("app/src/main/headers/hello.h")
when:
header << """
#pragma once
#define MESSAGE "hello"
#if 0
#include "missing.h"
#endif
"""
appSourceFile.text = """
#include <iostream>
#include "hello.h"
int main () {
std::cout << MESSAGE;
return 0;
}
"""
then:
succeeds installApp
install.exec().out == "hello"
when:
succeeds installApp
then:
allSkipped()
when:
header << """// some extra stuff"""
and:
appObjects.snapshot()
libObjects.snapshot()
then:
succeeds installApp
executedAndNotSkipped appDebug.compile
skipped libraryDebug.compile
and:
appObjects.recompiledFiles(appSourceFile)
libObjects.noneRecompiled()
when:
succeeds installApp
then:
allSkipped()
}
@ToBeFixedForConfigurationCache
def "source file can reference multiple header files using the same macro"() {
def header1 = file("app/src/main/headers/hello1.h")
def header2 = file("app/src/main/headers/hello2.h")
def header3 = file("app/src/main/headers/hello3.h")
def unused = file("app/src/main/headers/ignoreme.h")
when:
file("app/src/main/headers/hello.h") << """
#if 0
#include "def1.h"
#else
#include "def2.h"
#endif
#include HEADER
"""
file("app/src/main/headers/def1.h") << """
#define HEADER "hello1.h"
"""
file("app/src/main/headers/def2.h") << """
#define _HEADER "hello2.h"
#ifndef _HEADER