Skip to content

Import tests from the main apollo-kotlin project #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
import org.jetbrains.kotlin.samWithReceiver.gradle.SamWithReceiverExtension
import org.jetbrains.kotlin.samWithReceiver.gradle.SamWithReceiverGradleSubplugin

plugins {
`embedded-kotlin`
id("java-gradle-plugin")
}

plugins.apply(SamWithReceiverGradleSubplugin::class.java)
extensions.configure(SamWithReceiverExtension::class.java) {
annotations(HasImplicitReceiver::class.qualifiedName!!)
}

group = "com.apollographql.cache.build"

dependencies {
compileOnly(gradleApi())
compileOnly(libs.kotlin.plugin)
}

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}

tasks.withType<JavaCompile>().configureEach {
options.release.set(17)
}

tasks.withType(KotlinJvmCompile::class.java).configureEach {
kotlinOptions.jvmTarget = "17"
}

gradlePlugin {
plugins {
register("build.logic") {
id = "build.logic"
// This plugin is only used for loading the jar using the Marker but never applied
// We don't need it.
implementationClass = "build.logic.Unused"
}
}
}
11 changes: 11 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
rootProject.name = "build-logic"

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}

apply(from = "../gradle/repositories.gradle.kts")
99 changes: 99 additions & 0 deletions build-logic/src/main/kotlin/Kmp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

enum class AppleTargets {
All,
Host,
}

fun KotlinMultiplatformExtension.configureKmp(
withJs: Boolean,
withWasm: Boolean,
withAndroid: Boolean,
withApple: AppleTargets = AppleTargets.All,
) {
jvm()
when (withApple) {
AppleTargets.All -> {
macosX64()
macosArm64()
iosArm64()
iosX64()
iosSimulatorArm64()
watchosArm32()
watchosArm64()
watchosSimulatorArm64()
tvosArm64()
tvosX64()
tvosSimulatorArm64()
}

AppleTargets.Host -> {
if (System.getProperty("os.arch") == "aarch64") {
macosArm64()
} else {
macosX64()
}
}
}
if (withJs) {
js(IR) {
nodejs {
testTask {
useMocha {
// Override default 2s timeout
timeout = "120s"
}
}
}
}
}
if (withWasm) {
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
nodejs()
}
}
if (withAndroid) {
androidTarget {
publishAllLibraryVariants()
}
}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
applyDefaultHierarchyTemplate {
group("common") {
group("concurrent") {
group("native") {
group("apple")
}
group("jvmCommon") {
withJvm()
if (withAndroid) {
withAndroidTarget()
}
}
}
if (withJs || withWasm) {
group("jsCommon") {
if (withJs) {
group("js") {
withJs()
}
}
if (withWasm) {
group("wasmJs") {
withWasmJs()
}
}
}
}
}
}

sourceSets.configureEach {
languageSettings.optIn("com.apollographql.apollo.annotations.ApolloExperimental")
languageSettings.optIn("com.apollographql.apollo.annotations.ApolloInternal")
}
}
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import com.gradleup.librarian.gradle.librarianRoot

plugins {
id("build.logic") apply false

alias(libs.plugins.kotlin.multiplatform).apply(false)
alias(libs.plugins.kotlin.jvm).apply(false)
alias(libs.plugins.android).apply(false)
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ androidx-sqlite = { group = "androidx.sqlite", name = "sqlite", version.ref = "a
androidx-sqlite-framework = { group = "androidx.sqlite", name = "sqlite-framework", version.ref = "androidx-sqlite" }
androidx-startup-runtime = "androidx.startup:startup-runtime:1.1.1"
kotlin-poet = { group = "com.squareup", name = "kotlinpoet", version = "1.18.1" }
kotlin-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin-plugin" }

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin-plugin" }
Expand Down
10 changes: 10 additions & 0 deletions gradle/repositories.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
listOf(pluginManagement.repositories, dependencyResolutionManagement.repositories).forEach {
it.apply {
maven {
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
mavenCentral()
google()
gradlePluginPortal()
}
}
49 changes: 5 additions & 44 deletions normalized-cache-incubating/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import com.gradleup.librarian.gradle.librarianModule
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
alias(libs.plugins.kotlin.multiplatform)
Expand All @@ -10,43 +8,11 @@ plugins {
librarianModule(true)

kotlin {
jvm()
macosX64()
macosArm64()
iosArm64()
iosX64()
iosSimulatorArm64()
watchosArm32()
watchosArm64()
watchosSimulatorArm64()
tvosArm64()
tvosX64()
tvosSimulatorArm64()
js(IR) {
nodejs()
}
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
nodejs()
}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
applyDefaultHierarchyTemplate {
group("common") {
group("concurrent") {
group("apple")
withJvm()
}
group("jsCommon") {
group("js") {
withJs()
}
group("wasmJs") {
withWasmJs()
}
}
}
}
configureKmp(
withJs = true,
withWasm = true,
withAndroid = false,
)

sourceSets {
getByName("commonMain") {
Expand All @@ -65,10 +31,5 @@ kotlin {
implementation(libs.apollo.testing.support)
}
}

configureEach {
languageSettings.optIn("com.apollographql.apollo.annotations.ApolloExperimental")
languageSettings.optIn("com.apollographql.apollo.annotations.ApolloInternal")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ internal class Normalizer(
if (compiledFields.isEmpty()) {
// If we come here, `obj` contains more data than the CompiledSelections can understand
// This happened previously (see https://github.com/apollographql/apollo-kotlin/pull/3636)
// This should not happen anymore but in case it does, we're logging some info here
throw RuntimeException("Cannot find a CompiledField for entry: {${entry.key}: ${entry.value}}, __typename = $typename, key = $key")
// It also happens if there's an always false @include directive (see https://github.com/apollographql/apollo-kotlin/issues/4772)
// For all cache purposes, this is not part of the response and we therefore do not include this in the response
return@mapNotNull null
}
val includedFields = compiledFields.filter {
!it.shouldSkip(variableValues = variables.valueMap)
Expand Down
41 changes: 5 additions & 36 deletions normalized-cache-sqlite-incubating/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import com.gradleup.librarian.gradle.librarianModule
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi

plugins {
alias(libs.plugins.kotlin.multiplatform)
Expand All @@ -10,36 +9,11 @@ plugins {
librarianModule(true)

kotlin {
jvm()
macosX64()
macosArm64()
iosArm64()
iosX64()
iosSimulatorArm64()
watchosArm32()
watchosArm64()
watchosSimulatorArm64()
tvosArm64()
tvosX64()
tvosSimulatorArm64()
androidTarget {
publishAllLibraryVariants()
}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
applyDefaultHierarchyTemplate {
group("common") {
group("concurrent") {
group("native") {
group("apple")
}
group("jvmCommon") {
withJvm()
withAndroidTarget()
}
}
}
}
configureKmp(
withJs = false,
withWasm = false,
withAndroid = true,
)
}

android {
Expand Down Expand Up @@ -126,11 +100,6 @@ kotlin {
implementation(libs.apollo.testing.support)
}
}

configureEach {
languageSettings.optIn("com.apollographql.apollo.annotations.ApolloExperimental")
languageSettings.optIn("com.apollographql.apollo.annotations.ApolloInternal")
}
}
}

Expand Down
12 changes: 3 additions & 9 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
pluginManagement {
listOf(repositories, dependencyResolutionManagement.repositories).forEach {
it.apply {
maven {
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
mavenCentral()
google()
}
}
includeBuild("build-logic")
}

apply(from = "gradle/repositories.gradle.kts")

include(
"normalized-cache-incubating",
"normalized-cache-sqlite-incubating",
Expand Down
12 changes: 2 additions & 10 deletions tests/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
buildscript {
repositories {
maven {
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
mavenCentral()
google()
}
}

plugins {
id("build.logic") apply false

alias(libs.plugins.kotlin.multiplatform).apply(false)
alias(libs.plugins.apollo).apply(false)
alias(libs.plugins.apollo.external).apply(false)
Expand Down
Loading