-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.gradle
3541 lines (3185 loc) · 158 KB
/
build.gradle
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 (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* The main build script for JavaFX.
*
* MUST FIX tasks to complete:
* - build check -- making sure the final artifact has the right bits
* - some things worth automatically sanity checking:
* - are there images in the javadocs?
* - are all of the expected dylibs etc there?
* - is jfxrt.jar there?
* - does jfxrt.jar contain stuff it shouldn't (doc-files, iml, etc)
* - does jfxrt.jar contain stuff it should (bss files, etc)
* - Perform sanity checking to make sure a JDK exists with javac, javah, etc
* - Support building with no known JDK location, as long as javac, javah, etc are on the path
* - Check all of the native flags. We're adding weight to some libs that don't need it, and so forth.
*
* Additional projects to work on as we go:
* - Add "developer debug". This is where the natives do not have debug symbols, but the Java code does
* - The genVSproperties.bat doesn't find the directory where RC.exe lives. So it is hard coded. Might be a problem.
* - special tasks for common needs, such as:
* - updating copyright headers
* - stripping trailing whitespace (?)
* - checkstyle
* - findbugs
* - re needs?
* - sqe testing
* - API change check
* - Pushing results to a repo?
* - ServiceWithSecurityManagerTest fails to complete when run from gradle.
* - Integrate Parfait reports for C code
* - FXML Project tests are not running
*/
defaultTasks = ["sdk"]
import java.util.concurrent.CountDownLatch
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.Future
/******************************************************************************
* Utility methods *
*****************************************************************************/
/**
* If the given named property is not defined, then this method will define
* it with the given defaultValue. Any properties defined by this method can
* be substituted on the command line by using -P, or by specifying a
* gradle.properties file in the user home dir
*
* @param name The name of the property to define
* @param defaultValue The default value to assign the property
*/
void defineProperty(String name, String defaultValue) {
if (!project.hasProperty(name)) {
project.ext.set(name, defaultValue);
}
}
/**
* If the given named property is not defined, then this method will attempt to
* look up the property in the props map, and use the defaultValue if it cannot be found.
*
* @param name The name of the property to look up and/or define
* @param props The properties to look for the named property in, if it has not already been defined
* @param defaultValue The default value if the property has not been defined and the
* props map does not contain the named property
*/
void defineProperty(String name, Properties props, String defaultValue) {
if (!project.hasProperty(name)) {
project.ext.set(name, props.getProperty(name, defaultValue));
}
}
/**
* Converts cygwin style paths to windows style paths, but with a forward slash.
* This method is safe to call from any platform, and will only do work if
* called on Windows (in all other cases it simply returns the supplied path.
* In the future I would like to modify this so that it only does work if
* cygwin is installed, as I hope one day to remove the requirement to build
* with cygwin, but at present (due to GStreamer / Webkit) cygwin is needed
* anyway.
*
* @param path the path to convert
* @return the path converted to windows style, if on windows, otherwise it
* is the supplied path.
*/
String cygpath(String path) {
if (!IS_WINDOWS) return path;
if (path == null || "".equals(path)) return path;
ByteArrayOutputStream out = new ByteArrayOutputStream();
logger.info("Converting path '$path' via cygpath")
exec {
standardOutput = out
commandLine "cmd", "/c", "cygpath", "-m", path
}
return out.toString().trim();
}
void loadProperties(String sourceFileName) {
def config = new Properties()
def propFile = new File(sourceFileName)
if (propFile.canRead()) {
config.load(new FileInputStream(propFile))
for (java.util.Map.Entry property in config) {
def keySplit = property.key.split("\\.");
def key = keySplit[0];
for (int i = 1; i < keySplit.length; i++) {
key = key + keySplit[i].capitalize();
}
ext[key] = property.value;
}
}
}
/**
* Struct used to contain some information passed to the closure
* passed to compileTargets.
*/
class CompileTarget {
String name;
String upper;
String capital;
}
/**
* Iterates over each of the compile targets, passing the given closure
* a CompileTarget instance.
*
* @param c The closure to call
*/
void compileTargets(Closure c) {
if (COMPILE_TARGETS == "") {
return
}
COMPILE_TARGETS.split(",").each { target ->
CompileTarget ct = new CompileTarget();
ct.name = target;
ct.upper = target.trim().toUpperCase(Locale.ROOT)
ct.capital = target.trim().capitalize()
c(ct)
}
}
/**
* Manages the execution of some closure which is responsible for producing
* content for a properties file built at build time and stored in the
* root project's $buildDir, and then loading that properties file and
* passing it to the processor closure.
*
* This is used on windows to produce a properties file containing all the
* windows visual studio paths and environment variables, and on Linux
* for storing the results of pkg-config calls.
*
* @param name the name of the file to produce
* @param loader a closure which is invoked, given the properties file. This
* closure is invoked only if the properties file needs to be created
* and is responsible for populating the properties file.
* @param processor a closure which is invoked every time this method is
* called and which will be given a Properties object, fully populated.
* The processor is then responsible for doing whatever it is that it
* must do with those properties (such as setting up environment
* variables used in subsequent native builds, or whatnot).
*/
void setupTools(String name, Closure loader, Closure processor) {
// Check to see whether $buildDir/$name.properties file exists. If not,
// then generate it. Once generated, we need to read the properties file to
// help us define the defaults for this block of properties
File propFile = file("$buildDir/${name}.properties");
if (!propFile.exists()) {
// Create the properties file
propFile.getParentFile().mkdirs();
propFile.createNewFile();
loader(propFile);
}
// Try reading the properties in order to define the properties. If the property file cannot
// be located, then we will throw an exception because we cannot guess these values
InputStream propStream = null;
try {
Properties properties = new Properties();
propStream = new FileInputStream(propFile);
properties.load(propStream);
processor(properties);
} finally {
try { propStream.close() } catch (Exception e) { }
}
}
/**
* Fails the build with the specified error message
*
* @param msg the reason for the failure
*/
void fail(String msg) {
throw new GradleException("FAIL: " + msg);
}
/******************************************************************************
* *
* Definition of project properties *
* *
* All properties defined using ext. are immediately available throughout *
* the script as variables that can be used. These variables are attached *
* to the root project (whereas if they were defined as def variables then *
* they would only be available within the root project scope). *
* *
* All properties defined using the "defineProperty" method can be replaced *
* on the command line by using the -P flag. For example, to override the *
* location of the binary plug, you would specify -PBINARY_PLUG=some/where *
* *
*****************************************************************************/
// If the ../rt-closed directory exists, then we are doing a closed build.
// In this case, build and property files will be read from
// ../rt-closed/closed-build.gradle and ../rt-closed/closed-properties.gradle
// respectively
def closedDir = file("../rt-closed")
def buildClosed = closedDir.isDirectory()
ext.BUILD_CLOSED = buildClosed
// These variables indicate what platform is running the build. Is
// this build running on a Mac, Windows, or Linux machine? 32 or 64 bit?
ext.OS_NAME = System.getProperty("os.name").toLowerCase()
ext.OS_ARCH = System.getProperty("os.arch")
ext.IS_64 = OS_ARCH.toLowerCase().contains("64")
ext.IS_MAC = OS_NAME.contains("mac") || OS_NAME.contains("darwin")
ext.IS_WINDOWS = OS_NAME.contains("windows")
ext.IS_LINUX = OS_NAME.contains("linux")
// Get the JDK_HOME automatically based on the version of Java used to execute gradle. Or, if specified,
// use a user supplied JDK_HOME, STUB_RUNTIME, JAVAC, and/or JAVAH, all of which may be specified
// independently (or we'll try to get the right one based on other supplied info). Sometimes the
// JRE might be the thing that is being used instead of the JRE embedded in the JDK, such as:
// c:\Program Files (x86)\Java\jdk1.8.0\jre
// c:\Program Files (x86)\Java\jre8\
// Because of this, you may sometimes get the jdk's JRE (in which case the logic we used to have here
// was correct and consistent with all other platforms), or it might be the standalone JRE (for the love!).
def envJavaHome = cygpath(System.getenv("JDK_HOME"))
if (envJavaHome == null || envJavaHome.equals("")) envJavaHome = cygpath(System.getenv("JAVA_HOME"))
def javaHome = envJavaHome == null || envJavaHome.equals("") ? System.getProperty("java.home") : envJavaHome
def javaHomeFile = file(javaHome)
defineProperty("JDK_HOME",
javaHomeFile.name == "jre" ?
javaHomeFile.getParent().toString() :
javaHomeFile.name.startsWith("jre") ?
new File(javaHomeFile.getParent(), "jdk1.${javaHomeFile.name.substring(3)}.0").toString() :
javaHome) // we have to bail and set it to something and this is as good as any!
ext.JAVA_HOME = JDK_HOME
defineProperty("JAVA", cygpath("$JDK_HOME/bin/java${IS_WINDOWS ? '.exe' : ''}"))
defineProperty("JAVAC", cygpath("$JDK_HOME/bin/javac${IS_WINDOWS ? '.exe' : ''}"))
defineProperty("JAVAH", cygpath("$JDK_HOME/bin/javah${IS_WINDOWS ? '.exe' : ''}"))
defineProperty("JAVADOC", cygpath("$JDK_HOME/bin/javadoc${IS_WINDOWS ? '.exe' : ''}"))
defineProperty("JDK_DOCS", "https://docs.oracle.com/javase/8/docs/api/")
defineProperty("javaRuntimeVersion", System.getProperty("java.runtime.version"))
defineProperty("javaVersion", javaRuntimeVersion.split("-")[0])
defineProperty("javaBuildNumber", javaRuntimeVersion.substring(javaRuntimeVersion.lastIndexOf("-b") + 2))
loadProperties("$projectDir/build.properties")
def String closedCacheStubRuntime = cygpath("$projectDir") + "/../caches/sdk/rt"
defineProperty("STUB_RUNTIME", BUILD_CLOSED ? closedCacheStubRuntime : cygpath("$JDK_HOME/jre"))
defineProperty("LIBRARY_STUB", IS_MAC ? "$STUB_RUNTIME/lib" :
IS_WINDOWS ? "$STUB_RUNTIME/bin" :
"$STUB_RUNTIME/lib/$OS_ARCH")
defineProperty("UPDATE_STUB_CACHE", (STUB_RUNTIME.equals(closedCacheStubRuntime) ? 'true' : 'false'))
def supplementalPreBuildFile = file("$closedDir/closed-pre-build.gradle");
def supplementalBuildFile = file("$closedDir/closed-build.gradle");
if (BUILD_CLOSED) {
apply from: supplementalPreBuildFile
}
// GRADLE_VERSION_CHECK specifies whether to fail the build if the
// gradle version check fails
defineProperty("GRADLE_VERSION_CHECK", "true")
ext.IS_GRADLE_VERSION_CHECK = Boolean.parseBoolean(GRADLE_VERSION_CHECK)
// COMPILE_WEBKIT specifies whether to build all of webkit.
defineProperty("COMPILE_WEBKIT", "false")
ext.IS_COMPILE_WEBKIT = Boolean.parseBoolean(COMPILE_WEBKIT)
// COMPILE_MEDIA specifies whether to build all of media.
defineProperty("COMPILE_MEDIA", "false")
ext.IS_COMPILE_MEDIA = Boolean.parseBoolean(COMPILE_MEDIA)
// COMPILE_PANGO specifies whether to build javafx_font_pango.
defineProperty("COMPILE_PANGO", "${IS_LINUX}")
ext.IS_COMPILE_PANGO = Boolean.parseBoolean(COMPILE_PANGO)
// COMPILE_HARFBUZZ specifies whether to use Harfbuzz.
defineProperty("COMPILE_HARFBUZZ", "false")
ext.IS_COMPILE_HARFBUZZ = Boolean.parseBoolean(COMPILE_HARFBUZZ)
// COMPILE_PARFAIT specifies whether to build parfait
defineProperty("COMPILE_PARFAIT", "false")
ext.IS_COMPILE_PARFAIT = Boolean.parseBoolean(COMPILE_PARFAIT)
// COMPILE_JFR specifies whether to build code that logs to JRockit Flight Recorder
defineProperty("COMPILE_JFR", Boolean.toString(file("$JDK_HOME/jre/lib/jfr.jar").exists()))
ext.IS_COMPILE_JFR = Boolean.parseBoolean(COMPILE_JFR)
// RETAIN_PACKAGER_TESTS specifies whether the tests in fxpackager should
// keep generated files instead of attempting to automatically delete them
defineProperty("RETAIN_PACKAGER_TESTS", "false")
ext.IS_RETAIN_PACKAGER_TESTS = Boolean.parseBoolean(RETAIN_PACKAGER_TESTS)
// TEST_PACKAGER_DMG whether tests that create DMG files via hdiutil
// should be run. On OSX 10.7 this tends to hang automated builds
defineProperty("TEST_PACKAGER_DMG", "false")
ext.IS_TEST_PACKAGER_DMG = Boolean.parseBoolean(TEST_PACKAGER_DMG)
// Define the SWT.jar that we are going to have to download during the build process based
// on what platform we are compiling from (not based on our target).
ext.SWT_FILE_NAME = IS_MAC ? "org.eclipse.swt.cocoa.macosx.x86_64_3.7.2.v3740f" :
IS_WINDOWS && IS_64 ? "org.eclipse.swt.win32.win32.x86_64_3.7.2.v3740f" :
IS_WINDOWS && !IS_64 ? "org.eclipse.swt.win32.win32.x86_3.7.2.v3740f" :
IS_LINUX && IS_64 ? "org.eclipse.swt.gtk.linux.x86_64_3.7.2.v3740f" :
IS_LINUX && !IS_64 ? "org.eclipse.swt.gtk.linux.x86_3.7.2.v3740f" : ""
// Build javadocs only if BUILD_JAVADOC=true
defineProperty("BUILD_JAVADOC", "false")
ext.IS_BUILD_JAVADOC = Boolean.parseBoolean(BUILD_JAVADOC)
// Specifies whether to build the javafx-src bundle
defineProperty("BUILD_SRC_ZIP", "false")
ext.IS_BUILD_SRC_ZIP = Boolean.parseBoolean(BUILD_SRC_ZIP)
// Specifies whether to run full tests (true) or smoke tests (false)
defineProperty("FULL_TEST", "false")
ext.IS_FULL_TEST = Boolean.parseBoolean(FULL_TEST);
// Specifies whether to run robot-based visual tests (only used when FULL_TEST is also enabled)
defineProperty("USE_ROBOT", "false")
ext.IS_USE_ROBOT = Boolean.parseBoolean(USE_ROBOT);
// Specified whether to run tests in headless mode
defineProperty("HEADLESS_TEST", "false")
ext.IS_HEADLESS_TEST = Boolean.parseBoolean(HEADLESS_TEST);
// Specifies whether to run system tests that depend on AWT (only used when FULL_TEST is also enabled)
defineProperty("AWT_TEST", "true")
ext.IS_AWT_TEST = Boolean.parseBoolean(AWT_TEST);
// Specify the build configuration (Release, Debug, or DebugNative)
defineProperty("CONF", "Debug")
ext.IS_DEBUG_JAVA = CONF == "Debug" || CONF == "DebugNative"
ext.IS_DEBUG_NATIVE = CONF == "DebugNative"
// Defines the compiler warning levels to use. If empty, then no warnings are generated. If
// not empty, then the expected syntax is as a space or comma separated list of names, such
// as defined in the javac documentation.
defineProperty("LINT", "none")
ext.IS_LINT = LINT != "none"
defineProperty("DOC_LINT", "none")
ext.IS_DOC_LINT = DOC_LINT != "none"
// Specifies whether to use the "useDepend" option when compiling Java sources
defineProperty("USE_DEPEND", "true")
ext.IS_USE_DEPEND = Boolean.parseBoolean(USE_DEPEND)
// Specifies whether to use the "incremental" option when compiling Java sources
defineProperty("INCREMENTAL", "false")
ext.IS_INCREMENTAL = Boolean.parseBoolean(INCREMENTAL)
// Specifies whether to generate code coverage statistics when running tests
defineProperty("JCOV", "false")
ext.DO_JCOV = Boolean.parseBoolean(JCOV)
// Define the number of threads to use when compiling (specifically for native compilation)
// On Mac we limit it to 1 by default due to problems running gcc in parallel
if (IS_MAC) {
defineProperty("NUM_COMPILE_THREADS", "1")
} else {
defineProperty("NUM_COMPILE_THREADS", "${Runtime.runtime.availableProcessors()}")
}
//
// The next three sections of properties are used to generate the
// VersionInfo class, and the Windows DLL manifest.
//
// The following properties should be left alone by developers and set only from Hudson.
defineProperty("HUDSON_JOB_NAME", "not_hudson")
defineProperty("HUDSON_BUILD_NUMBER","0000")
defineProperty("PROMOTED_BUILD_NUMBER", "00")
defineProperty("MILESTONE_FCS", "false")
ext.IS_MILESTONE_FCS = Boolean.parseBoolean(MILESTONE_FCS)
if (IS_MILESTONE_FCS) {
// Override properties
ext.jfxReleaseMilestone = "fcs"
ext.jfxReleaseSuffix = ""
}
// The following properties define the product name for Oracle JDK and OpenJDK
// for VersionInfo and the DLL manifest.
if (BUILD_CLOSED) {
defineProperty("PRODUCT_NAME", "Java(TM)")
defineProperty("COMPANY_NAME", "Oracle Corporation")
defineProperty("PLATFORM_NAME", "Platform SE")
} else {
defineProperty("PRODUCT_NAME", "OpenJFX")
defineProperty("COMPANY_NAME", "N/A")
defineProperty("PLATFORM_NAME", "Platform")
}
// The following properties are set based on properties defined in
// build.properties. The release number or milestone number should be updated
// in that file.
def jfxReleaseVersion = "${jfxReleaseMajorVersion}.${jfxReleaseMinorVersion}.${jfxReleaseMicroVersion}"
defineProperty("RAW_VERSION", jfxReleaseVersion)
defineProperty("RELEASE_NAME", jfxReleaseName)
defineProperty("RELEASE_MILESTONE", jfxReleaseMilestone)
// Check whether the COMPILE_TARGETS property has been specified (if so, it was done by
// the user and not by this script). If it has not been defined then default
// to building the normal desktop build for this machine
project.ext.set("defaultHostTarget", IS_MAC ? "mac" : IS_WINDOWS ? "win" : IS_LINUX ? "linux" : "");
defineProperty("COMPILE_TARGETS", "$defaultHostTarget")
// Flag indicating whether to import cross compile tools
def importCrossTools = BUILD_CLOSED ? true : false;
if (!importCrossTools && hasProperty("IMPORT_CROSS_TOOLS")) {
importCrossTools = Boolean.parseBoolean(IMPORT_CROSS_TOOLS);
}
ext.IS_IMPORT_CROSS_TOOLS = importCrossTools
// Location of the cross compile tools
def crossToolsDir = "../crosslibs"
if (hasProperty("CROSS_TOOLS_DIR")) {
crossToolsDir = CROSS_TOOLS_DIR
}
ext.CROSS_TOOLS_DIR = file(crossToolsDir)
// Specifies whether to run tests with the present jfxrt.jar instead of compiling the new one
defineProperty("BUILD_SDK_FOR_TEST", "true")
ext.DO_BUILD_SDK_FOR_TEST = Boolean.parseBoolean(BUILD_SDK_FOR_TEST)
// Specifies the location to point at SDK build when DO_BUILD_SDK_FOR_TEST set to false
// Used to get location of jfxrt.jar, ant-javafx.jar and javafx-mx.jar
defineProperty("TEST_SDK", JDK_HOME)
ext.TEST_SDK_DIR = file(TEST_SDK)
def rtDir = new File(TEST_SDK_DIR, "rt")
if (!rtDir.directory) {
rtDir = new File(TEST_SDK_DIR, "jre")
}
ext.jfxrtJarFromSdk = new File(rtDir, "lib/ext/jfxrt.jar").absolutePath
if (!DO_BUILD_SDK_FOR_TEST && !file(jfxrtJarFromSdk).exists()) {
fail ("BUILD_SDK_FOR_TEST is set to false, but there\'s no jfxrt.jar at the expected paths in TEST_SDK($TEST_SDK_DIR)\n"
+ "TEST_SDK should point at either JavaFX SDK location or JDK location\n"
+ "Please, set the correct TEST_SDK")
}
// These tasks would be disabled when running with DO_BUILD_SDK_FOR_TEST=false as they're unneeded for running tests
def disabledTasks = DO_BUILD_SDK_FOR_TEST ? [] : ["compileJava", "processResources", "classes", // all projects
"generateDecoraShaders", "generatePrismShaders",
"compilePrismCompilers", "compilePrismJavaShaders", "compileDecoraCompilers", // :graphics
"processDecoraShaders", "processPrismShaders"]
/**
* Fetch/Check that external tools are present for the build. This method
* will conditionally download the packages from project defined ivy repositories
* and unpack them into the specified destdir
*
* @param configName A unique name to distinguish the configuration (ie "ARMSFV6")
* @param packages A list of required packages (with extensions .tgz, .zip)
* @param destdir where the packages should be unpacked
* @param doFetch if true, the named packages will be download
*/
void fetchExternalTools(String configName, List packages, File destdir, boolean doFetch) {
if (doFetch) {
// create a unique configuration for this fetch
def String fetchToolsConfig = "fetchTools$configName"
rootProject.configurations.create(fetchToolsConfig)
def List<String> fetchedPackages = []
def int fetchCount = 0
packages.each { pkgname->
def int dotdex = pkgname.lastIndexOf('.')
def int dashdex = pkgname.lastIndexOf('-')
def String basename = pkgname.substring(0,dashdex)
def String ver = pkgname.substring(dashdex+1,dotdex)
def String ext = pkgname.substring(dotdex+1)
def File pkgdir = file("$destdir/$basename-$ver")
if (!pkgdir.isDirectory()) {
rootProject.dependencies.add(fetchToolsConfig, "javafx:$basename:$ver", {
artifact {
name = basename
version = ver
type = ext
}
})
println "adding $pkgname as a downloadable item did not find $pkgdir"
fetchedPackages.add(pkgname)
fetchCount++
}
}
//fetch all the missing packages
if (fetchedPackages.size > 0) {
destdir.mkdirs()
logger.quiet "fetching missing packages $fetchedPackages"
copy {
from rootProject.configurations[fetchToolsConfig]
into destdir
}
// unpack the fetched packages
fetchedPackages.each { pkgname->
logger.quiet "expanding the package $pkgname"
def srcball = file("${destdir}/${pkgname}")
if (!srcball.exists()) {
throw new GradleException("Failed to fetch $pkgname");
}
def String basename = pkgname.substring(0,pkgname.lastIndexOf("."))
def File pkgdir = file("$destdir/$basename")
if (pkgname.endsWith(".tgz")) {
if (IS_LINUX || IS_MAC) {
// use native tar to support symlinks
pkgdir.mkdirs()
exec {
workingDir pkgdir
commandLine "tar", "zxf", "${srcball}"
}
} else {
copy {
from tarTree(resources.gzip("${srcball}"))
into pkgdir
}
}
} else if (pkgname.endsWith(".zip")) {
copy {
from zipTree("${srcball}")
into pkgdir
}
} else {
throw new GradleException("Unhandled package type for compile package ${pkgname}")
}
srcball.deleteOnExit();
}
} else {
logger.quiet "all tool packages are present $packages"
}
} else { // !doFetch - so just check they are present
// check that all the dirs are really there
def List<String> errors = []
packages.each { pkgname->
def String basename = pkgname.substring(0,pkgname.lastIndexOf("."))
def File pkgdir = file("$destdir/$basename")
if (!pkgdir.isDirectory()) {
errors.add(pkgname)
}
}
if (errors.size > 0) {
throw new GradleException("Error: missing tool packages: $errors")
} else {
logger.quiet "all tool packages are present $packages"
}
}
}
// Now we need to define the native compilation tasks. The set of parameters to
// native compilation depends on the target platform (and also to some extent what platform
// you are compiling on). These settings are contained in various gradle files
// such as mac.gradle and linux.gradle and armhf.gradle. Additionally, the developer
// can specify COMPILE_FLAGS_FILE to be a URL or path to a different gradle file
// that will contain the appropriate flags.
defineProperty("COMPILE_FLAGS_FILES", COMPILE_TARGETS.split(",").collect {"buildSrc/${it.trim()}.gradle"}.join(","))
if (COMPILE_TARGETS == "all") {
def tmp = []
File buildSrcDir = file("buildSrc")
buildSrcDir.listFiles().each { File f ->
if (f.isFile() && f.name.endsWith(".gradle") && !f.name.equals("build.gradle")) {
def target = f.name.substring(0, f.name.lastIndexOf('.gradle')).toUpperCase(Locale.ROOT)
apply from: f
if (project.ext["${target}"].canBuild) {
tmp.add(target)
}
}
}
COMPILE_FLAGS_FILES = tmp.collect { "buildSrc/${it}.gradle"}.join(",")
COMPILE_TARGETS = tmp.collect { "${it.toLowerCase()}"}.join(",")
} else {
COMPILE_FLAGS_FILES.split(",").each {
logger.info("Applying COMPILE_FLAGS_FILE '$it'")
apply from: it
}
}
if (COMPILE_TARGETS != "") {
def tmp = []
COMPILE_TARGETS.split(",").each {target ->
if (project.ext["${target.toUpperCase(Locale.ROOT)}"].canBuild) {
tmp.add(target)
}
}
COMPILE_TARGETS = tmp.collect { "${it.toLowerCase()}"}.join(",")
}
// Sanity check the expected properties all exist
compileTargets { t ->
// Every platform must define these variables
if (!project.hasProperty(t.upper)) throw new Exception("ERROR: Incorrectly configured compile flags file, missing ${t.name} property")
def props = project.ext[t.upper];
["compileSwing", "compileSWT", "compileFXPackager", "libDest"].each { prop ->
if (!props.containsKey(prop)) throw new Exception("ERROR: Incorrectly configured compile flags file, missing ${prop} property on ${t.name}")
}
}
// Various build flags may be set by the different target files, such as
// whether to build Swing, SWT, FXPackager, etc. We iterate over all
// compile targets and look for these settings in our properties. Note that
// these properties cannot be set from the command line, but are set by
// the target build files such as armv6hf.gradle or mac.gradle.
ext.COMPILE_SWING = false;
ext.COMPILE_SWT = false;
ext.COMPILE_FXPACKAGER = false;
compileTargets { t ->
def targetProperties = project.rootProject.ext[t.upper]
if (targetProperties.compileSwing) COMPILE_SWING = true
if (targetProperties.compileSWT) COMPILE_SWT = true
if (targetProperties.compileFXPackager) COMPILE_FXPACKAGER = true
if (!targetProperties.containsKey('compileWebnodeNative')) {
// unless specified otherwise, we will compile native Webnode if IS_COMPILE_WEBKIT
targetProperties.compileWebnodeNative = true
}
if (!targetProperties.containsKey('compileMediaNative')) {
// unless specified otherwise, we will compile native Media if IS_COMPILE_MEDIA
targetProperties.compileMediaNative = true
}
if (!targetProperties.containsKey('includeSWT')) targetProperties.includeSWT = true
if (!targetProperties.containsKey('includeSwing')) targetProperties.includeSwing = true
if (!targetProperties.containsKey('includeNull3d')) targetProperties.includeNull3d = true
if (!targetProperties.containsKey('includeLens')) targetProperties.includeLens = false
if (!targetProperties.containsKey('includeMonocle')) targetProperties.includeMonocle = false
if (!targetProperties.containsKey('includeEGL')) targetProperties.includeEGL = false
if (!targetProperties.containsKey('includeGTK')) targetProperties.includeGTK = IS_LINUX
// This value is used to under ./build/${sdkDirName} to allow for
// a common name for the hosted build (for use when building apps)
// and a unique name for cross builds.
if (rootProject.defaultHostTarget.equals(t.name)) {
// use a simple common default for the "host" build
targetProperties.sdkDirName="sdk"
targetProperties.exportDirName="export"
targetProperties.bundleDirName="bundles"
} else {
// and a more complex one for cross builds
targetProperties.sdkDirName="${t.name}-sdk"
targetProperties.exportDirName="${t.name}-export"
targetProperties.bundleDirName="${t.name}-bundles"
}
}
/******************************************************************************
* *
* Build Setup Sanity Checks *
* *
* Here we do a variety of checks so that if the version of Java you are *
* building with is misconfigured, or you are using the wrong version of *
* gradle, etc you will get some kind of helpful error / warning message *
* *
*****************************************************************************/
// Verify that the architecture & OS are supported configurations. Note that
// at present building on PI is not supported, but we would only need to make
// some changes on assumptions on what should be built (like SWT / Swing) and
// such and we could probably make it work.
if (!IS_MAC && !IS_WINDOWS && !IS_LINUX) logger.error("Unsupported build OS ${OS_NAME}")
if (IS_WINDOWS && OS_ARCH != "x86" && OS_ARCH != "amd64") {
throw new Exception("Unknown and unsupported build architecture: $OS_ARCH")
} else if (IS_MAC && OS_ARCH != "x86_64") {
throw new Exception("Unknown and unsupported build architecture: $OS_ARCH")
} else if (IS_LINUX && OS_ARCH != "i386" && OS_ARCH != "amd64") {
throw new Exception("Unknown and unsupported build architecture: $OS_ARCH")
}
// Sanity check that we actually have a list of compile targets to execute
if (COMPILE_TARGETS == null || COMPILE_TARGETS == "") {
throw new Exception("Unable to determine compilation platform, must specify valid COMPILE_TARGETS!")
}
// Make sure JDK_HOME/bin/java exists
if (!file(JAVA).exists()) throw new Exception("Missing or incorrect path to 'java': '$JAVA'. Perhaps bad JDK_HOME? $JDK_HOME")
if (!file(JAVAC).exists()) throw new Exception("Missing or incorrect path to 'javac': '$JAVAC'. Perhaps bad JDK_HOME? $JDK_HOME")
if (!file(JAVAH).exists()) throw new Exception("Missing or incorrect path to 'javah': '$JAVAH'. Perhaps bad JDK_HOME? $JDK_HOME")
if (!file(JAVADOC).exists()) throw new Exception("Missing or incorrect path to 'javadoc': '$JAVADOC'. Perhaps bad JDK_HOME? $JDK_HOME")
// Determine the verion of Java in JDK_HOME. It looks like this:
//
// $ java -version
// java version "1.7.0_45"
// Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
// Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
//
// We need to parse the second line
def inStream = new java.io.BufferedReader(new java.io.InputStreamReader(new java.lang.ProcessBuilder(JAVA, "-version").start().getErrorStream()));
try {
if (inStream.readLine() != null) {
String v = inStream.readLine();
if (v != null) {
int ib = v.indexOf(" (build ");
if (ib != -1) {
String ver = v.substring(ib + 8, v.size() - 1);
defineProperty("jdkRuntimeVersion", ver)
defineProperty("jdkVersion", jdkRuntimeVersion.split("-")[0])
defineProperty("jdkBuildNumber", jdkRuntimeVersion.substring(jdkRuntimeVersion.lastIndexOf("-b") + 2))
}
}
}
} finally {
inStream.close();
}
if (!project.hasProperty("jdkRuntimeVersion")) throw new Exception("Unable to determine the version of Java in JDK_HOME at $JDK_HOME");
// Verify that CONF is something useful
if (CONF != "Release" && CONF != "Debug" && CONF != "DebugNative") {
logger.warn("Unknown configuration CONF='$CONF'. Treating as 'Release'")
}
// If the number of compile threads is less than 1 then we have a problem!
if (Integer.parseInt(NUM_COMPILE_THREADS.toString()) < 1) {
logger.warn("NUM_COMPILE_THREADS was specified as '$NUM_COMPILE_THREADS' which is less than the minimum value of 1. " +
"Building with a value of 1 instead.")
NUM_COMPILE_THREADS = 1
}
// Check for Gradle 4.8, error if < 4.8.
if (gradle.gradleVersion != "4.8") {
def ver = gradle.gradleVersion.split("[\\.]");
def gradleMajor = Integer.parseInt(ver[0]);
def gradleMinor = Integer.parseInt(ver[1].split("[^0-9]")[0]);
def err = "";
if (gradleMajor < 4 || (gradleMajor == 4 && gradleMinor < 8)) {
err = "Gradle version too old: ${gradle.gradleVersion}; must be at least 4.8"
}
if (IS_GRADLE_VERSION_CHECK && err != "") {
fail(err);
}
logger.warn("*****************************************************************");
logger.warn("Unsupported gradle version $gradle.gradleVersion in use.");
logger.warn("Only version 4.8 is supported. Use this version at your own risk");
if ( err != "") logger.warn(err);
logger.warn("*****************************************************************");
}
/******************************************************************************
* *
* Logging of Properties and Settings *
* *
* Log some of the settings we've determined. We could log more here, it *
* doesn't really hurt. *
* *
*****************************************************************************/
logger.quiet("gradle.gradleVersion: $gradle.gradleVersion")
logger.quiet("OS_NAME: $OS_NAME")
logger.quiet("OS_ARCH: $OS_ARCH")
logger.quiet("JAVA_HOME: $JAVA_HOME")
logger.quiet("JDK_HOME: $JDK_HOME")
logger.quiet("java.runtime.version: ${javaRuntimeVersion}")
logger.quiet("java version: ${javaVersion}")
logger.quiet("java build number: ${javaBuildNumber}")
logger.quiet("jdk.runtime.version: ${jdkRuntimeVersion}")
logger.quiet("jdk version: ${jdkVersion}")
logger.quiet("jdk build number: ${jdkBuildNumber}")
logger.quiet("minimum java build number: ${jfxBuildJdkBuildnumMin}")
logger.quiet("CONF: $CONF")
logger.quiet("NUM_COMPILE_THREADS: $NUM_COMPILE_THREADS")
logger.quiet("COMPILE_TARGETS: $COMPILE_TARGETS")
logger.quiet("COMPILE_FLAGS_FILES: $COMPILE_FLAGS_FILES")
logger.quiet("HUDSON_JOB_NAME: $HUDSON_JOB_NAME")
logger.quiet("HUDSON_BUILD_NUMBER: $HUDSON_BUILD_NUMBER")
logger.quiet("PROMOTED_BUILD_NUMBER: $PROMOTED_BUILD_NUMBER")
logger.quiet("PRODUCT_NAME: $PRODUCT_NAME")
logger.quiet("RAW_VERSION: $RAW_VERSION")
logger.quiet("RELEASE_NAME: $RELEASE_NAME")
logger.quiet("RELEASE_MILESTONE: $RELEASE_MILESTONE")
if (UPDATE_STUB_CACHE) {
logger.quiet("UPDATE_STUB_CACHE: $UPDATE_STUB_CACHE")
}
/******************************************************************************
* *
* Definition of Native Code Compilation Tasks *
* *
* - JavaHeaderTask is used to run javah. The JAVAH property will point at *
* the version of javah to be used (i.e.: a path to javah) *
* - CCTask compiles native code. Specifically it will compile .m, .c, *
* .cpp, or .cc files. It uses the headers provided by the *
* JavaHeaderTask plus additional platform specific headers. It will *
* compile into .obj files. *
* - LinkTask will perform native linking and create the .dll / .so / *
* .dylib as necessary. *
* *
*****************************************************************************/
// Save a reference to the buildSrc.jar file because we need it for actually
// compiling things, not just for the sake of this build script
// (such as generating the builders, JSL files, etc)
ext.BUILD_SRC = rootProject.files("buildSrc/build/libs/buildSrc.jar")
/**
* Convenience method for creating javah, cc, link, and "native" tasks in the given project. These
* tasks are parameterized by name, so that we can produce, for example, javahGlass, ccGlass, etc
* named tasks.
*
* @param project The project to add tasks to
* @param name The name of the project, such as "prism-common". This name is used
* in the name of the generated task, such as ccPrismCommon, and also
* in the name of the final library, such as libprism-common.dylib.
*/
void addNative(Project project, String name) {
// TODO if we want to handle 32/64 bit windows in the same build,
// Then we will need to modify the win compile target to be win32 or win64
def capitalName = name.split("-").collect{it.capitalize()}.join()
def nativeTask = project.task("native$capitalName", group: "Build") {
description = "Generates JNI headers, compiles, and builds native dynamic library for $name for all compile targets"
}
def cleanTask = project.task("cleanNative$capitalName", type: Delete, group: "Build") {
description = "Clean native objects for $name"
}
if (project.hasProperty("nativeAllTask")) project.nativeAllTask.dependsOn nativeTask
project.assemble.dependsOn(nativeTask)
if (project.hasProperty("cleanNativeAllTask")) project.cleanNativeAllTask.dependsOn cleanTask
// Each of the different compile targets will be placed in a sub directory
// of these root dirs, with the name of the dir being the name of the target
def headerRootDir = project.file("$project.buildDir/generated-src/headers/$name")
def nativeRootDir = project.file("$project.buildDir/native/$name")
def libRootDir = project.file("$project.buildDir/libs/$name")
// For each compile target, create a javah / cc / link triplet
compileTargets { t ->
def targetProperties = project.rootProject.ext[t.upper]
def library = targetProperties.library
def properties = targetProperties.get(name)
def nativeDir = file("$nativeRootDir/${t.name}")
def headerDir = file("$headerRootDir/${t.name}")
// If there is not a library clause in the properties, assume it is not wanted
if (!targetProperties.containsKey(name)) {
println("Ignoring native library ${name}. Not defined in ${t.name} project properties");
return
}
// check for the property disable${name} = true
def String disableKey = "disable${name}"
def boolean disabled = targetProperties.containsKey(disableKey) ? targetProperties.get(disableKey) : false
if (disabled) {
println("Native library ${name} disabled in ${t.name} project properties");
return
}
def javahTask = project.task("javah${t.capital}${capitalName}", type: JavaHeaderTask, dependsOn: project.classes, group: "Build") {
description = "Generates JNI Headers for ${name} for ${t.name}"
if (properties.javahSource == null) {
source(project.sourceSets.main.java.outputDir)
} else {
source(properties.javahSource)
}
if (properties.javahClasspath == null) {
classpath = project.files(project.sourceSets.main.java.outputDir)
classpath += project.sourceSets.main.compileClasspath
} else {
classpath = project.files(properties.javahClasspath)
}
output = headerDir
include(properties.javahInclude)
cleanTask.delete headerDir
}
def variants = properties.containsKey("variants") ? properties.variants : [""];
variants.each { variant ->
def variantProperties = variant == "" ? properties : properties.get(variant)
def capitalVariant = variant.capitalize()
def ccOutput = variant == "" ? nativeDir : file("$nativeDir/$variant")
def ccTask = project.task("cc${t.capital}$capitalName$capitalVariant", type: CCTask, dependsOn: javahTask, group: "Build") {
description = "Compiles native sources for ${name} for ${t.name}${capitalVariant != '' ? ' for variant ' + capitalVariant : ''}"
matches = ".*\\.c|.*\\.cpp|.*\\.m|.*\\.cc"
headers = headerDir
output(ccOutput)
params.addAll(variantProperties.ccFlags)
compiler = variantProperties.compiler
source(variantProperties.nativeSource)
cleanTask.delete ccOutput
}
def linkTask = project.task("link${t.capital}$capitalName$capitalVariant", type: LinkTask, dependsOn: ccTask, group: "Build") {
description = "Creates native dynamic library for $name for ${t.name}${capitalVariant != '' ? ' for variant ' + capitalVariant : ''}"
objectDir = ccOutput
linkParams.addAll(variantProperties.linkFlags)
lib = file("$libRootDir/${t.name}/${variant == '' ? library(properties.lib) : library(variantProperties.lib)}")
linker = variantProperties.linker
cleanTask.delete "$libRootDir/${t.name}"
}
nativeTask.dependsOn(linkTask)
if (IS_WINDOWS && t.name == "win") {
def rcTask = project.task("rc$capitalName$capitalVariant", type: CompileResourceTask, dependsOn: javahTask, group: "Build") {
description = "Compiles native sources for $name"
matches = ".*\\.rc"
compiler = variantProperties.rcCompiler
source(variantProperties.rcSource)
if (variantProperties.rcFlags) {
rcParams.addAll(variantProperties.rcFlags)
}
output(ccOutput)
}
linkTask.dependsOn rcTask;
}
}
def useLipo = targetProperties.containsKey('useLipo') ? targetProperties.useLipo : false
if (useLipo) {
def lipoTask = project.task("lipo${t.capital}$capitalName", type: LipoTask, dependsOn: javahTask, group: "Build") {
description = "Creates native fat library for $name for ${t.name}"
libDir = file("$libRootDir/${t.name}")
lib = file("$libRootDir/${t.name}/${library(properties.lib)}")
}
nativeTask.dependsOn(lipoTask)
}
}
}
void addJSL(Project project, String name, String pkg, Closure compile) {
def lowerName = name.toLowerCase()
def compileCompilers = project.task("compile${name}Compilers", type: JavaCompile, dependsOn: project.compileJava) {
description = "Compile the $name JSL Compilers"
classpath = project.files(project.sourceSets.main.java.outputDir) +
rootProject.BUILD_SRC +
project.configurations.antlr3
source = [project.file("src/main/jsl-$lowerName")]
destinationDir = project.file("$project.buildDir/classes/jsl-compilers/$lowerName")
}
def generateShaders = project.task("generate${name}Shaders", dependsOn: compileCompilers) {
description = "Generate $name shaders from JSL"
def sourceDir = project.file("src/main/jsl-$lowerName")
def destinationDir = project.file("$project.buildDir/generated-src/jsl-$lowerName")
inputs.dir sourceDir
outputs.dir destinationDir
doLast {
compile(sourceDir, destinationDir)
}
}
project.task("compile${name}JavaShaders", type: JavaCompile, dependsOn: generateShaders) {
description = "Compile the Java $name JSL shaders"
classpath = project.files(project.sourceSets.main.java.outputDir) + rootProject.BUILD_SRC
source = [project.file("$project.buildDir/generated-src/jsl-$lowerName")]
destinationDir = project.file("$project.buildDir/classes/jsl-$lowerName")
}
def compileHLSLShaders = project.task("compile${name}HLSLShaders", dependsOn: generateShaders, type: CompileHLSLTask) {