-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More accurate core library desugaring support
The main idea is to use a custom wrapper around Animal Sniffer (instead of the Gradle plugin) so that we can * change class names in signatures, e.g. `DesugarDate` -> `Date` * relax the superclass validation when merging signatures (i.e. we don't care whether `Long8` extends `Object` or `Number` but Animal Sniffer normally does) Additional changes include: * Treat android sdk as a Gradle artifact. This involves setting up an Ivy repo to match the custom layout of the Google SDK repository and a Gradle artifact transform that can extract android.jar from the SDK archive and seamlessly expose it as a dependency. This ensures SDKs are cached between `gradle clean`s and removes a whole bunch of custom download / unzip logic (at the expense of a bunch of Gradle artifact handling code). * Rename some modules to better describe their purpose (maybe?).
- Loading branch information
Showing
47 changed files
with
591 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Standard Desugared APIs | ||
|
||
Contains stubs for APIs desugared by vanilla D8 in AGP 3.x+ without core library desugaring. | ||
|
||
Currently must be compiled with java 8. |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
sugar/src/main/java/java/lang/Boolean.java → ...ugar/src/main/java/java/lang/Boolean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
sugar/src/main/java/java/lang/Byte.java → ...c-sugar/src/main/java/java/lang/Byte.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
sugar/src/main/java/java/lang/Character.java → ...ar/src/main/java/java/lang/Character.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
sugar/src/main/java/java/lang/Double.java → ...sugar/src/main/java/java/lang/Double.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
sugar/src/main/java/java/lang/Float.java → ...-sugar/src/main/java/java/lang/Float.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
sugar/src/main/java/java/lang/Integer.java → ...ugar/src/main/java/java/lang/Integer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
sugar/src/main/java/java/lang/Long.java → ...c-sugar/src/main/java/java/lang/Long.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
sugar/src/main/java/java/lang/Short.java → ...-sugar/src/main/java/java/lang/Short.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ allprojects { | |
repositories { | ||
google() | ||
jcenter() | ||
|
||
androidSdk() | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2020. Toast Inc. | ||
* | ||
* 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. | ||
*/ | ||
|
||
object Scopes { | ||
const val generator = "generator" | ||
const val sdk = "sdk" | ||
const val standardSugar = "sugar" | ||
const val exerciseStandardSugar = "exerciseStandardSugar" | ||
const val coreLibSugar = "coreLibSugar" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (c) 2020. Toast Inc. | ||
* | ||
* 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. | ||
*/ | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.dsl.RepositoryHandler | ||
import org.gradle.api.artifacts.transform.InputArtifact | ||
import org.gradle.api.artifacts.transform.TransformAction | ||
import org.gradle.api.artifacts.transform.TransformOutputs | ||
import org.gradle.api.artifacts.transform.TransformParameters | ||
import org.gradle.api.attributes.Attribute | ||
import org.gradle.api.file.FileSystemLocation | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.gradle.kotlin.dsl.registerTransform | ||
import java.util.zip.ZipFile | ||
|
||
const val SDK_GROUP = "com.google.android.sdk" | ||
|
||
private const val ANDROID_JAR = "android.jar" | ||
private val ARTIFACT_TYPE_ATTRIBUTE = Attribute.of("artifactType", String::class.java) | ||
private val UNPACKED_SDK_ATTRIBUTE = Attribute.of("unpackedSdk", Boolean::class.javaObjectType) | ||
|
||
/** | ||
* This [artifact transform](https://docs.gradle.org/current/userguide/artifact_transforms.html) | ||
* extracts android.jar from the Android SDK Platform zip archive. | ||
*/ | ||
abstract class ExtractSdkTransform : TransformAction<TransformParameters.None> { | ||
@get:InputArtifact | ||
abstract val inputArtifact: Provider<FileSystemLocation> | ||
|
||
override fun transform(outputs: TransformOutputs) { | ||
val sdkArchive = ZipFile(inputArtifact.get().asFile) | ||
|
||
val androidJarEntry = sdkArchive.entries().asSequence().find { it.name.endsWith(ANDROID_JAR) } | ||
|
||
sdkArchive.getInputStream(androidJarEntry).use { i -> | ||
outputs.file(ANDROID_JAR).outputStream().use { o -> | ||
i.copyTo(o) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun Project.extractSdk() { | ||
configurations.named("sdk") { | ||
attributes.attribute(UNPACKED_SDK_ATTRIBUTE, true) | ||
} | ||
|
||
dependencies { | ||
attributesSchema { | ||
attribute(UNPACKED_SDK_ATTRIBUTE) | ||
} | ||
|
||
artifactTypes.create("zip") { | ||
attributes.attribute(UNPACKED_SDK_ATTRIBUTE, false) | ||
} | ||
|
||
registerTransform(ExtractSdkTransform::class) { | ||
from.attribute(UNPACKED_SDK_ATTRIBUTE, false).attribute(ARTIFACT_TYPE_ATTRIBUTE, "zip") | ||
to.attribute(UNPACKED_SDK_ATTRIBUTE, true).attribute(ARTIFACT_TYPE_ATTRIBUTE, "jar") | ||
} | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Enables Gradle to download artifacts from the Android SDK (non-Maven) repository. | ||
*/ | ||
fun RepositoryHandler.androidSdk() { | ||
ivy { | ||
setUrl("https://dl.google.com/android/repository") | ||
|
||
content { | ||
includeGroup(SDK_GROUP) | ||
} | ||
|
||
patternLayout { | ||
artifact("/[module]_[revision].[ext]") | ||
} | ||
|
||
metadataSources { | ||
artifact() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.