blob: 03039c0ab08deb419b0db785d2886cca20a967ad [file] [log] [blame]
Morten Krogh-Jespersen5a37de82023-03-02 01:42:28 +01001// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
Morten Krogh-Jespersend1a11852023-06-14 14:48:44 +02005// TODO(b/270105162): Move this file out the repository root when old gradle is removed.
Morten Krogh-Jespersen5a37de82023-03-02 01:42:28 +01006
Rico Wind782d7682023-09-22 12:24:25 +02007import java.nio.file.Files
8import java.nio.file.attribute.FileTime
Rico Wind327a5d22023-09-20 09:46:18 +02009import org.gradle.internal.os.OperatingSystem
10
Morten Krogh-Jespersen5a37de82023-03-02 01:42:28 +010011rootProject.name = "d8-r8"
12
Søren Gjesse44faa872023-05-23 12:21:22 +020013// Bootstrap building by downloading dependencies.
Rico Wind5e1580a2024-07-01 08:32:39 +000014val dependencies_bucket = "r8-deps"
Morten Krogh-Jespersen35c65e72023-06-16 12:52:38 +020015val root = rootProject.projectDir
16
17fun getRepoRoot() : File {
18 var current = root
19 while (!current.getName().equals("d8_r8")) {
20 current = current.getParentFile()
21 }
22 return current.getParentFile()
Søren Gjesse44faa872023-05-23 12:21:22 +020023}
24
Rico Windf61b39d2023-08-31 13:00:41 +020025fun downloadFromGoogleStorage(outputDir : File) {
26 val targz = File(outputDir.toString() + ".tar.gz")
27 val sha1File = File(targz.toString() + ".sha1")
28 if (outputDir.exists()
29 && outputDir.isDirectory
30 && targz.exists()
31 && sha1File.lastModified() <= targz.lastModified()) {
32 // We already downloaded, no need to recheck the hash
33 return
34 }
35
Rico Wind327a5d22023-09-20 09:46:18 +020036 var downloadScript = "download_from_google_storage.py"
37 if (OperatingSystem.current().isWindows()) {
38 downloadScript = "download_from_google_storage.bat"
39 }
Morten Krogh-Jespersen35c65e72023-06-16 12:52:38 +020040 val cmd = listOf(
Rico Wind327a5d22023-09-20 09:46:18 +020041 downloadScript,
Morten Krogh-Jespersen35c65e72023-06-16 12:52:38 +020042 "--extract",
43 "--bucket",
Morten Krogh-Jespersen95671e12023-06-26 22:04:33 +020044 dependencies_bucket,
Morten Krogh-Jespersen35c65e72023-06-16 12:52:38 +020045 "--sha1_file",
46 "${sha1File}"
47 )
Rico Windf61b39d2023-08-31 13:00:41 +020048
Morten Krogh-Jespersen35c65e72023-06-16 12:52:38 +020049 println("Executing command: ${cmd.joinToString(" ")}")
Morten Krogh-Jespersen95671e12023-06-26 22:04:33 +020050 val process = ProcessBuilder().command(cmd).start()
Morten Krogh-Jespersen91584d72023-06-21 13:45:07 +020051 process.waitFor()
Morten Krogh-Jespersen35c65e72023-06-16 12:52:38 +020052 if (process.exitValue() != 0) {
53 throw GradleException(
Søren Gjesse4569e472023-10-25 15:15:17 +020054 "Bootstrapping ${outputDir} download failed:\n"
Morten Krogh-Jespersen35c65e72023-06-16 12:52:38 +020055 + "${String(process.getErrorStream().readAllBytes(),
56 java.nio.charset.StandardCharsets.UTF_8)}\n"
Morten Krogh-Jespersen95671e12023-06-26 22:04:33 +020057 + String(process.getInputStream().readAllBytes(),
58 java.nio.charset.StandardCharsets.UTF_8))
Rico Wind782d7682023-09-22 12:24:25 +020059 } else {
60 // Ensure that the gz file is more recent than the .sha1 file
61 // People that upload a new version will generally have an older .sha1 file
62 println("Updating timestamp on " + targz)
63 val now = FileTime.fromMillis(System.currentTimeMillis())
64 Files.setLastModifiedTime(targz.toPath(), now)
Morten Krogh-Jespersen35c65e72023-06-16 12:52:38 +020065 }
66}
67
68val thirdParty = getRepoRoot().resolve("third_party")
Rico Windf61b39d2023-08-31 13:00:41 +020069downloadFromGoogleStorage(thirdParty.resolve("dependencies"))
Søren Gjesse4569e472023-10-25 15:15:17 +020070downloadFromGoogleStorage(thirdParty.resolve("dependencies_plugin"))
Morten Krogh-Jespersend1a11852023-06-14 14:48:44 +020071
Morten Krogh-Jespersen95671e12023-06-26 22:04:33 +020072pluginManagement {
Morten Krogh-Jespersen51026a42023-08-28 13:34:56 +020073 repositories {
74 maven {
Søren Gjesse80ae2c72023-10-26 12:04:01 +020075 url = uri("file:../third_party/dependencies_plugin")
Morten Krogh-Jespersen51026a42023-08-28 13:34:56 +020076 }
77 maven {
Søren Gjesse80ae2c72023-10-26 12:04:01 +020078 url = uri("file:../third_party/dependencies")
Morten Krogh-Jespersen51026a42023-08-28 13:34:56 +020079 }
80 }
Morten Krogh-Jespersen95671e12023-06-26 22:04:33 +020081 includeBuild(rootProject.projectDir.resolve("commonBuildSrc"))
82}
Morten Krogh-Jespersen51026a42023-08-28 13:34:56 +020083
84dependencyResolutionManagement {
85 repositories {
86 maven {
87 url = uri("file:../third_party/dependencies")
88 }
Morten Krogh-Jespersen51026a42023-08-28 13:34:56 +020089 }
90}
91
Morten Krogh-Jespersenad74d682023-09-14 15:55:18 +020092includeBuild(root.resolve("shared"))
Morten Krogh-Jespersend1a11852023-06-14 14:48:44 +020093includeBuild(root.resolve("keepanno"))
Rico Winda6e4efc2023-08-03 07:51:44 +020094includeBuild(root.resolve("resourceshrinker"))
Morten Krogh-Jespersen5a37de82023-03-02 01:42:28 +010095
96// We need to include src/main as a composite-build otherwise our test-modules
97// will compete with the test to compile the source files.
Morten Krogh-Jespersend1a11852023-06-14 14:48:44 +020098includeBuild(root.resolve("main"))
Morten Krogh-Jespersen920fe7a2023-06-29 15:08:19 +020099includeBuild(root.resolve("library_desugar"))
Morten Krogh-Jespersend1a11852023-06-14 14:48:44 +0200100includeBuild(root.resolve("test"))