-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
2274 lines (2138 loc) · 87.3 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) 2016, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.ltgt.gradle.errorprone.CheckSeverity
import org.gradle.internal.os.OperatingSystem
import tasks.DownloadDependency
import tasks.GetJarsFromConfiguration
import utils.Utils
buildscript {
repositories {
maven {
url 'http://storage.googleapis.com/r8-deps/maven_mirror/'
}
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.2'
}
}
plugins {
id "net.ltgt.errorprone" version "0.7"
}
apply plugin: 'java'
apply plugin: 'idea'
ext {
androidSupportVersion = '25.4.0'
asmVersion = '7.1'
espressoVersion = '3.0.0'
fastutilVersion = '7.2.0'
guavaVersion = '23.0'
joptSimpleVersion = '4.6'
gsonVersion = '2.7'
junitVersion = '4.13-beta-2'
mockitoVersion = '2.10.0'
kotlinVersion = '1.3.11'
kotlinExtMetadataJVMVersion = '0.1.0'
smaliVersion = '2.2b4'
errorproneVersion = '2.3.2'
testngVersion = '6.10'
}
apply from: 'copyAdditionalJctfCommonFiles.gradle'
repositories {
maven {
url 'http://storage.googleapis.com/r8-deps/maven_mirror/'
}
maven { url 'https://maven.google.com' }
mavenCentral()
maven { url 'https://kotlin.bintray.com/kotlinx' }
}
if (project.hasProperty('with_code_coverage')) {
apply plugin: 'jacoco'
}
// Custom source set for example tests and generated tests.
sourceSets {
test {
java {
srcDirs = [
'src/test/java',
'build/generated/test/java',
]
}
}
apiUsageSample {
java {
srcDirs = ['src/test/apiUsageSample', 'src/main/java']
include 'com/android/tools/apiusagesample/*.java'
include 'com/android/tools/r8/BaseCompilerCommandParser.java'
include 'com/android/tools/r8/D8CommandParser.java'
include 'com/android/tools/r8/R8CommandParser.java'
include 'com/android/tools/r8/utils/FlagFile.java'
}
}
cfSegments {
java {
srcDirs = ['third_party/classlib/java', 'src/cf_segments/java']
}
output.resourcesDir = 'build/classes/cfSegments'
}
debugTestResources {
java {
srcDirs = ['src/test/debugTestResources']
}
output.resourcesDir = 'build/classes/debugTestResources'
}
debugTestResourcesJava8 {
java {
srcDirs = ['src/test/debugTestResourcesJava8']
}
output.resourcesDir = 'build/classes/debugTestResourcesJava8'
}
debugTestResourcesKotlin {
java {
srcDirs = ['src/test/debugTestResourcesKotlin']
}
output.resourcesDir = 'build/classes/debugTestResourcesKotlin'
}
examples {
java {
srcDirs = ['src/test/examples']
}
output.resourcesDir = 'build/classes/examples'
}
examplesJava9 {
java {
srcDirs = ['src/test/examplesJava9']
}
}
examplesJava11 {
java {
srcDirs = ['src/test/examplesJava11']
}
}
jdk11TimeTests {
java {
srcDirs = [
'third_party/openjdk/jdk-11-test/java/time/tck',
'third_party/openjdk/jdk-11-test/java/time/test'
]
exclude '**/TestZoneTextPrinterParser.java'
}
}
examplesTestNGRunner {
java {
srcDirs = ['src/test/testngrunner']
}
}
examplesKotlin {
java {
srcDirs = ['src/test/examplesKotlin']
}
output.resourcesDir = 'build/classes/examplesKotlin'
}
examplesAndroidN {
java {
srcDirs = ['src/test/examplesAndroidN']
}
output.resourcesDir = 'build/classes/examplesAndroidN'
}
examplesAndroidO {
java {
srcDirs = ['src/test/examplesAndroidO']
}
output.resourcesDir = 'build/classes/examplesAndroidO'
}
examplesAndroidP {
java {
srcDirs = ['src/test/examplesAndroidP']
}
output.resourcesDir = 'build/classes/examplesAndroidP'
}
examplesProto {
java {
srcDirs = ['src/test/examplesProto']
}
compileClasspath = files("third_party/protobuf-lite/libprotobuf_lite.jar")
compileClasspath += fileTree(dir: "build/generated/test/proto", include: "*.jar")
output.resourcesDir = 'build/classes/examplesProto'
}
jctfCommon {
java {
srcDirs = [
'third_party/jctf/Harness/src',
'third_party/jctf/LibTests/src/com/google/jctf/test/categories',
'third_party/jctf/LibTests/src/com/google/jctf/test/helper',
'third_party/jctf/LibTests/src/com/google/jctf/testHelpers',
'third_party/jctf/LibTests/src/org',
'build/additionalJctfCommonFiles'
]
}
resources {
srcDirs = ['third_party/jctf/LibTests/resources']
}
}
jctfTests {
java {
srcDirs = [
'third_party/jctf/LibTests/src/com/google/jctf/test/lib',
// 'third_party/jctf/VMTests/src',
]
}
}
kotlinR8TestResources {
java {
srcDirs = ['src/test/kotlinR8TestResources']
}
output.resourcesDir = 'build/classes/kotlinR8TestResources'
}
}
// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
// for context.
idea {
sourceSets.all { SourceSet sources ->
module {
if (sources.name == "main") {
sourceDirs += sources.java.srcDirs
outputDir sources.output.classesDirs[0]
} else {
testSourceDirs += sources.java.srcDirs
testOutputDir sources.output.classesDirs[0]
}
}
}
}
configurations {
supportLibs
}
dependencies {
implementation "net.sf.jopt-simple:jopt-simple:$joptSimpleVersion"
implementation "com.google.code.gson:gson:$gsonVersion"
// Include all of guava when compiling the code, but exclude annotations that we don't
// need from the packaging.
compileOnly("com.google.guava:guava:$guavaVersion")
implementation("com.google.guava:guava:$guavaVersion", {
exclude group: 'com.google.errorprone'
exclude group: 'com.google.code.findbugs'
exclude group: 'com.google.j2objc'
exclude group: 'org.codehaus.mojo'
})
implementation group: 'it.unimi.dsi', name: 'fastutil', version: fastutilVersion
implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:$kotlinExtMetadataJVMVersion"
implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion
implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion
implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion
implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion
implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion
jdk11TimeTestsCompile group: 'org.testng', name: 'testng', version: testngVersion
examplesTestNGRunnerCompile group: 'org.testng', name: 'testng', version: testngVersion
testCompile sourceSets.examples.output
testCompile "junit:junit:$junitVersion"
testCompile group: 'org.smali', name: 'smali', version: smaliVersion
testCompile files('third_party/jasmin/jasmin-2.4.jar')
testCompile files('third_party/jdwp-tests/apache-harmony-jdwp-tests-host.jar')
testCompile files('third_party/ddmlib/ddmlib.jar')
jctfCommonCompile "junit:junit:$junitVersion"
jctfTestsCompile "junit:junit:$junitVersion"
jctfTestsCompile sourceSets.jctfCommon.output
examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: asmVersion
// Import Guava for @Nullable annotation
examplesCompile "com.google.guava:guava:$guavaVersion"
examplesCompile "junit:junit:$junitVersion"
examplesCompile "org.mockito:mockito-core:$mockitoVersion"
supportLibs "com.android.support:support-v4:$androidSupportVersion"
supportLibs "junit:junit:$junitVersion"
supportLibs "com.android.support.test.espresso:espresso-core:$espressoVersion"
apiUsageSampleCompile sourceSets.main.output
apiUsageSampleCompile "com.google.guava:guava:$guavaVersion"
debugTestResourcesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
examplesKotlinCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
kotlinR8TestResourcesCompileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
}
def r8LibPath = "$buildDir/libs/r8lib.jar"
def r8LibExludeDepsPath = "$buildDir/libs/r8lib-exclude-deps.jar"
def r8LibGeneratedKeepRulesPath = "$buildDir/generated/keep.txt"
def r8LibGeneratedKeepRulesExcludeDepsPath = "$buildDir/generated/keep-exclude-deps.txt"
def r8LibTestPath = "$buildDir/classes/r8libtest"
def java11ClassFiles = "build/classes/java/mainJava11"
def osString = OperatingSystem.current().isLinux() ? "linux" :
OperatingSystem.current().isMacOsX() ? "mac" : "windows"
def cloudDependencies = [
"tests" : [
"2017-10-04/art",
"2016-12-19/art"
],
"third_party": [
"android_cts_baseline",
"android_jar/lib-v14",
"android_jar/lib-v15",
"android_jar/lib-v19",
"android_jar/lib-v21",
"android_jar/lib-v22",
"android_jar/lib-v23",
"android_jar/lib-v24",
"android_jar/lib-v25",
"android_jar/lib-v26",
"android_jar/lib-v27",
"android_jar/lib-v28",
"core-lambda-stubs",
"dart-sdk",
"ddmlib",
"gradle/gradle",
"jacoco",
"jasmin",
"jctf",
"junit",
"jdwp-tests",
"kotlin",
"kotlin-compiler-1.3.41",
"openjdk/openjdk-rt-1.8",
"openjdk/desugar_jdk_libs",
"openjdk/jdk-11-test",
"proguard/proguard5.2.1",
"proguard/proguard6.0.1",
"r8",
],
// All dex-vms have a fixed OS of Linux, as they are only supported on Linux, and will be run in a Docker
// container on other platforms where supported.
"tools" : [
"linux/art",
"linux/art-5.1.1",
"linux/art-6.0.1",
"linux/art-7.0.0",
"linux/art-8.1.0",
"linux/art-9.0.0",
"linux/dalvik",
"linux/dalvik-4.0.4",
"${osString}/dx",
]
]
def cloudSystemDependencies = [
linux: [
"third_party": ["openjdk/openjdk-9.0.4/linux",
"openjdk/jdk8/linux-x86",
"openjdk/jdk-11/Linux"],
],
osx: [
"third_party": ["openjdk/openjdk-9.0.4/osx",
"openjdk/jdk8/darwin-x86",
"openjdk/jdk-11/Mac"],
],
windows: [
"third_party": ["openjdk/openjdk-9.0.4/windows",
"openjdk/jdk-11/Windows"],
],
]
if (OperatingSystem.current().isWindows()) {
cloudSystemDependencies.windows.each { entry ->
cloudDependencies.get(entry.key).addAll(entry.value)
}
} else if (OperatingSystem.current().isLinux()) {
cloudSystemDependencies.linux.each { entry ->
cloudDependencies.get(entry.key).addAll(entry.value)
}
} else if (OperatingSystem.current().isMacOsX()) {
cloudSystemDependencies.osx.each { entry ->
cloudDependencies.get(entry.key).addAll(entry.value)
}
} else {
println "WARNING: Unsupported system: " + OperatingSystem.current()
}
def getDownloadDepsTaskName(entryKey, entryFile) {
return "download_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
}
def getFetchDepsTaskName(entryKey, entryFile) {
return "fetch_deps_${entryKey}_${entryFile.replace('/', '_').replace('\\', '_')}"
}
cloudDependencies.each { entry ->
entry.value.each { entryFile ->
task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
type DownloadDependency.Type.GOOGLE_STORAGE
dependency "${entry.key}/${entryFile}"
}
}
}
def x20Dependencies = [
"third_party": [
"benchmarks/kotlin-benches",
"chrome/chrome_180917_ffbaa8",
"classlib",
"cf_segments",
"desugar/desugar_20180308",
"internal/issue-127524985",
"framework",
"gmail/gmail_android_170604.16",
"gmail/gmail_android_180826.15",
"gmscore/gmscore_v10",
"gmscore/gmscore_v9",
"gmscore/latest",
"gmscore/v4",
"gmscore/v5",
"gmscore/v6",
"gmscore/v7",
"gmscore/v8",
"nest/nest_20180926_7c6cfb",
"photos/2017-06-06",
"proguard/proguard_internal_159423826",
"proguardsettings",
"proto",
"protobuf-lite",
"youtube/youtube.android_12.10",
"youtube/youtube.android_12.17",
"youtube/youtube.android_12.22",
"youtube/youtube.android_13.37",
"youtube/youtube.android_14.19"
],
]
x20Dependencies.each { entry ->
entry.value.each { entryFile ->
task "${getDownloadDepsTaskName(entry.key, entryFile)}"(type: DownloadDependency) {
type DownloadDependency.Type.X20
dependency "${entry.key}/${entryFile}"
}
}
}
task downloadProguard {
cloudDependencies.each { entry ->
entry.value.each { entryFile ->
if (entryFile.contains("proguard")) {
dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
}
}
}
}
task downloadOpenJDKrt {
cloudDependencies.each { entry ->
entry.value.each { entryFile ->
if (entryFile.contains("openjdk-rt")) {
dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
}
}
}
}
task downloadDx {
cloudDependencies.each { entry ->
entry.value.each { entryFile ->
if (entryFile.endsWith("/dx")) {
dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
}
}
}
}
task downloadAndroidCts {
cloudDependencies.each { entry ->
entry.value.each { entryFile ->
if (entryFile.contains("android_cts_baseline")) {
dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
}
}
}
}
task downloadDeps {
cloudDependencies.each { entry ->
entry.value.each { entryFile ->
dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
}
}
if (!project.hasProperty('no_internal')) {
x20Dependencies.each { entry ->
entry.value.each { entryFile ->
dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
}
}
}
}
allprojects {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
// TODO(ricow): Remove debug prints
println("NOTE: Current operating system: " + OperatingSystem.current())
println("NOTE: Current operating system isWindows: " + OperatingSystem.current().isWindows())
// Check if running with the JDK location from tools/jdk.py.
if (OperatingSystem.current().isWindows()) {
println "NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome
} else {
def javaHomeOut = new StringBuilder()
def javaHomeErr = new StringBuilder()
def javaHomeProc = './tools/jdk.py'.execute()
javaHomeProc.waitForProcessOutput(javaHomeOut, javaHomeErr)
def jdkHome = new File(javaHomeOut.toString().trim())
if (!jdkHome.exists()) {
println "WARNING: Failed to find the ./tools/jdk.py specified JDK: " + jdkHome
} else if (jdkHome != org.gradle.internal.jvm.Jvm.current().javaHome) {
println("WARNING: Gradle is running in a non-pinned Java"
+ ". Gradle Java Home: " + org.gradle.internal.jvm.Jvm.current().javaHome
+ ". Expected: " + jdkHome)
} else {
println("NOTE: Running with jdk from tools/jdk.py: " + jdkHome)
}
}
sourceSets.configureEach { sourceSet ->
tasks.named(sourceSet.compileJavaTaskName).configure {
// Default disable errorprone (enabled and setup below).
options.errorprone.enabled = false
options.compilerArgs << '-Xlint:unchecked'
// Run all compilation tasks in a forked subprocess.
options.fork = true
// Javac often runs out of stack space when compiling the tests.
// Increase the stack size for the javac process.
options.forkOptions.jvmArgs << "-Xss4m"
// Test compilation is sometimes hitting the default limit at 1g, increase it.
options.forkOptions.jvmArgs << "-Xmx2g"
// Set the bootclass path so compilation is consistent with 1.8 target compatibility.
options.forkOptions.jvmArgs << "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar"
}
}
tasks.named(sourceSets.examplesJava9.compileJavaTaskName).get().configure {
def jdkDir = 'third_party/openjdk/openjdk-9.0.4/'
options.fork = true
options.forkOptions.jvmArgs = []
if (OperatingSystem.current().isLinux()) {
options.forkOptions.javaHome = file(jdkDir + 'linux')
} else if (OperatingSystem.current().isMacOsX()) {
options.forkOptions.javaHome = file(jdkDir + 'osx')
} else {
options.forkOptions.javaHome = file(jdkDir + 'windows')
}
sourceCompatibility = JavaVersion.VERSION_1_9
targetCompatibility = JavaVersion.VERSION_1_9
}
def setJava11Compilation(sourceSet) {
tasks.named(sourceSet).get().configure {
def jdkDir = 'third_party/openjdk/jdk-11/'
options.fork = true
options.forkOptions.jvmArgs = []
if (OperatingSystem.current().isLinux()) {
options.forkOptions.javaHome = file(jdkDir + 'Linux')
} else if (OperatingSystem.current().isMacOsX()) {
options.forkOptions.javaHome = file(jdkDir + 'Mac/Contents/Home')
} else {
options.forkOptions.javaHome = file(jdkDir + 'Windows')
}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}
setJava11Compilation(sourceSets.examplesJava11.compileJavaTaskName)
setJava11Compilation(sourceSets.examplesTestNGRunner.compileJavaTaskName)
setJava11Compilation(sourceSets.jdk11TimeTests.compileJavaTaskName)
task compileMainWithJava11 (type: JavaCompile) {
def jdkDir = 'third_party/openjdk/jdk-11/'
options.fork = true
options.forkOptions.jvmArgs = []
if (OperatingSystem.current().isLinux()) {
options.forkOptions.javaHome = file(jdkDir + 'Linux')
} else if (OperatingSystem.current().isMacOsX()) {
options.forkOptions.javaHome = file(jdkDir + 'Mac/Contents/Home')
} else {
options.forkOptions.javaHome = file(jdkDir + 'Windows')
}
source = sourceSets.main.allSource
destinationDir = file(java11ClassFiles)
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
classpath = sourceSets.main.compileClasspath
}
if (!project.hasProperty('without_error_prone') &&
// Don't enable error prone on Java 8 as the plugin setup does not support it.
!org.gradle.internal.jvm.Jvm.current().javaVersion.java8) {
compileJava {
// Enable error prone for D8/R8 sources.
options.errorprone.enabled = true
options.errorprone.disableAllChecks = true
options.errorprone.check('ClassCanBeStatic', CheckSeverity.ERROR)
options.errorprone.check('OperatorPrecedence', CheckSeverity.ERROR)
options.errorprone.check('RemoveUnusedImports', CheckSeverity.ERROR)
options.errorprone.check('MissingOverride', CheckSeverity.ERROR)
options.errorprone.check('IntLongMath', CheckSeverity.ERROR)
options.errorprone.check('EqualsHashCode', CheckSeverity.ERROR)
options.errorprone.check('InconsistentOverloads', CheckSeverity.ERROR)
options.errorprone.check('ArrayHashCode', CheckSeverity.ERROR)
options.errorprone.check('EqualsIncompatibleType', CheckSeverity.ERROR)
options.errorprone.check('NonOverridingEquals', CheckSeverity.ERROR)
options.errorprone.check('FallThrough', CheckSeverity.ERROR)
options.errorprone.check('MissingCasesInEnumSwitch', CheckSeverity.ERROR)
options.errorprone.check('MissingDefault', CheckSeverity.ERROR)
options.errorprone.check('MultipleTopLevelClasses', CheckSeverity.ERROR)
options.errorprone.check('NarrowingCompoundAssignment', CheckSeverity.ERROR)
options.errorprone.check('BoxedPrimitiveConstructor', CheckSeverity.ERROR)
options.errorprone.check('LogicalAssignment', CheckSeverity.ERROR)
options.errorprone.check('FloatCast', CheckSeverity.ERROR)
options.errorprone.check('ReturnValueIgnored', CheckSeverity.ERROR)
}
}
compileJctfCommonJava {
dependsOn 'copyAdditionalJctfCommonFiles'
options.compilerArgs = ['-Xlint:none']
}
compileJctfTestsJava {
dependsOn 'jctfCommonClasses'
options.compilerArgs = ['-Xlint:none']
}
task consolidatedLicense {
def license = new File(new File(buildDir, 'generatedLicense'), 'LICENSE')
inputs.files files('LICENSE', 'LIBRARY-LICENSE') + fileTree(dir: 'library-licensing')
def runtimeClasspath = configurations.findByName("runtimeClasspath")
inputs.files { runtimeClasspath.getResolvedConfiguration().files }
outputs.files license
doLast {
def dependencies = []
runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each {
def identifier = (ModuleComponentIdentifier) it.id.componentIdentifier
dependencies.add("${identifier.group}:${identifier.module}")
}
def libraryLicenses = file('LIBRARY-LICENSE').text
dependencies.each {
if (!libraryLicenses.contains("- artifact: $it")) {
throw new GradleException("No license for $it in LIBRARY_LICENSE")
}
}
license.getParentFile().mkdirs()
license.createNewFile()
license.text = "This file lists all licenses for code distributed.\n"
license.text += "All non-library code has the following 3-Clause BSD license.\n"
license.text += "\n"
license.text += "\n"
license.text += file('LICENSE').text
license.text += "\n"
license.text += "\n"
license.text += "Summary of distributed libraries:\n"
license.text += "\n"
license.text += libraryLicenses
license.text += "\n"
license.text += "\n"
license.text += "Licenses details:\n"
fileTree(dir: 'library-licensing').getFiles().stream().sorted().forEach { file ->
license.text += "\n"
license.text += "\n"
license.text += file.text
}
}
}
static mergeServiceFiles(ShadowJar task) {
// Everything under META-INF is not included by default.
// Should include before 'relocate' so that the service file path and its content
// are properly relocated as well.
task.mergeServiceFiles {
include 'META-INF/services/*'
}
}
static configureRelocations(ShadowJar task) {
task.relocate('com.google.common', 'com.android.tools.r8.com.google.common')
task.relocate('com.google.gson', 'com.android.tools.r8.com.google.gson')
task.relocate('com.google.thirdparty', 'com.android.tools.r8.com.google.thirdparty')
task.relocate('joptsimple', 'com.android.tools.r8.joptsimple')
task.relocate('org.objectweb.asm', 'com.android.tools.r8.org.objectweb.asm')
task.relocate('it.unimi.dsi.fastutil', 'com.android.tools.r8.it.unimi.dsi.fastutil')
task.relocate('kotlin', 'com.android.tools.r8.jetbrains.kotlin')
task.relocate('kotlinx', 'com.android.tools.r8.jetbrains.kotlinx')
task.relocate('org.jetbrains', 'com.android.tools.r8.org.jetbrains')
task.relocate('org.intellij', 'com.android.tools.r8.org.intellij')
}
task repackageDepsNoRelocate(type: ShadowJar) {
configurations = [project.configurations.runtimeClasspath]
mergeServiceFiles(it)
exclude { it.getRelativePath().getPathString() == "module-info.class" }
exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
baseName 'deps-not-relocated'
}
task repackageDeps(type: ShadowJar) {
configurations = [project.configurations.runtimeClasspath]
mergeServiceFiles(it)
if (!project.hasProperty('lib_no_relocate')) {
configureRelocations(it)
}
exclude { it.getRelativePath().getPathString() == "module-info.class" }
exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
baseName 'deps'
}
task repackageSources(type: ShadowJar) {
from sourceSets.main.output
mergeServiceFiles(it)
if (!project.hasProperty('lib_no_relocate')) {
configureRelocations(it)
}
baseName 'sources'
}
task repackageSources11(type: ShadowJar) {
dependsOn compileMainWithJava11
from file(java11ClassFiles)
mergeServiceFiles(it)
if (!project.hasProperty('lib_no_relocate')) {
configureRelocations(it)
}
baseName 'sources11'
}
task r8WithRelocatedDeps(type: ShadowJar) {
from consolidatedLicense.outputs.files
baseName 'r8_with_relocated_deps'
classifier = null
version = null
manifest {
attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
}
from repackageSources.outputs.files
from repackageDeps.outputs.files
configureRelocations(it)
exclude "META-INF/*.kotlin_module"
exclude "**/*.kotlin_metadata"
}
task r8WithRelocatedDeps11(type: ShadowJar) {
from consolidatedLicense.outputs.files
baseName 'r8_with_relocated_deps_11'
classifier = null
version = null
manifest {
attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
}
from repackageSources11.outputs.files
from repackageDeps.outputs.files
configureRelocations(it)
exclude "META-INF/*.kotlin_module"
exclude "**/*.kotlin_metadata"
}
task r8WithoutDeps(type: ShadowJar) {
from consolidatedLicense.outputs.files
baseName 'r8_without_deps'
classifier = null
version = null
manifest {
attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
}
from sourceSets.main.output
}
task R8(type: ShadowJar) {
from consolidatedLicense.outputs.files
baseName 'r8'
classifier = null
version = null
manifest {
attributes 'Main-Class': 'com.android.tools.r8.SwissArmyKnife'
}
// In order to build without dependencies, pass the exclude_deps property using:
// gradle -Pexclude_deps R8
if (!project.hasProperty('exclude_deps')) {
from repackageSources.outputs.files
from repackageDeps.outputs.files
} else {
from sourceSets.main.output
}
exclude "META-INF/*.kotlin_module"
exclude "**/*.kotlin_metadata"
}
task R8NoManifestNoDeps(type: ShadowJar) {
from consolidatedLicense.outputs.files
baseName 'r8nomanifest-exclude-deps'
classifier = null
version = null
from sourceSets.main.output
}
task R8NoManifest(type: ShadowJar) {
from consolidatedLicense.outputs.files
baseName 'r8nomanifest'
classifier = null
version = null
// In order to build without dependencies, pass the exclude_deps property using:
// gradle -Pexclude_deps R8
if (!project.hasProperty('exclude_deps')) {
from repackageSources.outputs.files
from repackageDeps.outputs.files
} else {
from sourceSets.main.output
}
exclude "META-INF/*.kotlin_module"
exclude "**/*.kotlin_metadata"
}
task D8(type: ShadowJar) {
from R8.outputs.files
baseName 'd8'
manifest {
attributes 'Main-Class': 'com.android.tools.r8.D8'
}
}
task CompatDx(type: ShadowJar) {
from R8.outputs.files
baseName 'compatdx'
manifest {
attributes 'Main-Class': 'com.android.tools.r8.compatdx.CompatDx'
}
}
task CompatProguard(type: ShadowJar) {
from R8.outputs.files
baseName 'compatproguard'
manifest {
attributes 'Main-Class': 'com.android.tools.r8.compatproguard.CompatProguard'
}
}
def baseR8CommandLine(args = []) {
// Execute r8 commands against a stable r8 with relocated dependencies.
return [org.gradle.internal.jvm.Jvm.current().getJavaExecutable(),
"-ea", "-jar", r8WithRelocatedDeps.outputs.files[0]] + args
}
def r8CfCommandLine(input, output, pgconf, args = [], libs = []) {
return baseR8CommandLine([
"--classfile", "--release",
input,
"--output", output,
"--pg-conf", pgconf,
"--pg-map-output", output + ".map",
"--lib", "third_party/openjdk/openjdk-rt-1.8/rt.jar"
] + args + libs.collectMany { ["--lib", it] })
}
def r8LibCreateTask(name, pgConf, r8Task, output, args = [], libs = []) {
return tasks.create("r8Lib${name}", Exec) {
inputs.files ([pgConf, r8WithRelocatedDeps.outputs, r8Task.outputs])
outputs.file output
dependsOn downloadOpenJDKrt
dependsOn r8WithRelocatedDeps
dependsOn r8Task
commandLine r8CfCommandLine(r8Task.outputs.files[0], output, pgConf, args, libs)
workingDir = projectDir
}
}
task testJar(type: ShadowJar, dependsOn: testClasses) {
baseName = "r8tests"
from sourceSets.test.output
}
task testJarNoDeps(type: ShadowJar, dependsOn: testClasses) {
baseName = "r8tests-exclude-deps"
from sourceSets.test.output
}
def generateR8LibKeepRules(name, r8Source, testSource, output) {
return tasks.create("generateR8LibKeepRules_" + name, Exec) {
doFirst {
standardOutput new FileOutputStream(output)
}
dependsOn r8WithRelocatedDeps
dependsOn r8Source
dependsOn testSource
dependsOn downloadOpenJDKrt
inputs.files ([r8WithRelocatedDeps.outputs, r8Source.outputs, testSource.outputs])
outputs.file output
commandLine baseR8CommandLine([
"printuses",
"--keeprules",
"third_party/openjdk/openjdk-rt-1.8/rt.jar",
r8Source.outputs.files[0],
testSource.outputs.files[0]])
workingDir = projectDir
}
}
task R8LibApiOnly {
dependsOn r8LibCreateTask("Api", "src/main/keep.txt", R8NoManifest, r8LibPath)
outputs.file r8LibPath
}
task R8Lib {
def genRulesTask = generateR8LibKeepRules(
"Main",
R8NoManifest,
testJar,
r8LibGeneratedKeepRulesPath)
dependsOn r8LibCreateTask(
"Main",
"src/main/keep.txt",
R8NoManifest,
r8LibPath,
["--pg-conf", genRulesTask.outputs.files[0]]
).dependsOn(genRulesTask)
outputs.file r8LibPath
}
task R8LibNoDeps {
def genRulesTask = generateR8LibKeepRules(
"NoDeps",
R8NoManifestNoDeps,
testJarNoDeps,
r8LibGeneratedKeepRulesExcludeDepsPath
)
dependsOn r8LibCreateTask(
"NoDeps",
"src/main/keep.txt",
R8NoManifestNoDeps,
r8LibExludeDepsPath,
["--pg-conf", genRulesTask.outputs.files[0]],
repackageDepsNoRelocate.outputs.files
).dependsOn(repackageDepsNoRelocate, genRulesTask)
outputs.file r8LibExludeDepsPath
}
task CompatDxLib {
dependsOn r8LibCreateTask(
"CompatDx", "src/main/keep-compatdx.txt", CompatDx, "build/libs/compatdxlib.jar")
}
task CompatProguardLib {
dependsOn r8LibCreateTask(
"CompatPg",
"src/main/keep-compatproguard.txt",
CompatProguard,
"build/libs/compatproguardlib.jar")
}
task sourceJar(type: Jar, dependsOn: classes) {
classifier = 'src'
from sourceSets.main.allSource
}
task jctfCommonJar(type: Jar) {
from sourceSets.jctfCommon.output
baseName 'jctfCommon'
}
artifacts {
archives sourceJar
}
task createArtTests(type: Exec) {
def outputDir = "build/generated/test/java/com/android/tools/r8/art"
def createArtTestsScript = "tools/create_art_tests.py"
inputs.files files("tests/2017-10-04/art.tar.gz", createArtTestsScript)
outputs.dir outputDir
dependsOn downloadDeps
commandLine "python", createArtTestsScript
workingDir = projectDir
}
task createJctfTests(type: Exec) {
def outputDir = "build/generated/test/java/com/android/tools/r8/jctf"
def script = "tools/create_jctf_tests.py"
inputs.file script
outputs.dir outputDir
dependsOn downloadDeps
commandLine "python", script
workingDir = projectDir
}
compileTestJava {
dependsOn createArtTests
dependsOn createJctfTests
}
task buildCfSegments(type: Jar, dependsOn: downloadDeps) {
from sourceSets.cfSegments.output
baseName 'cf_segments'
destinationDir file('build/libs')
}
task buildD8ApiUsageSample(type: Jar) {
from sourceSets.apiUsageSample.output
baseName 'd8_api_usage_sample'
destinationDir file('tests')
}
task buildR8ApiUsageSample(type: Jar) {
from sourceSets.apiUsageSample.output
baseName 'r8_api_usage_sample'