Skip to content

Commit

Permalink
KOA-6155 Fix broken screenshots generator (#1627)
Browse files Browse the repository at this point in the history
* Fixed transparent screenshots

* Removed room-compiler-processing

* Fixed KSP behaviour on AndroidTest target

* Updated the tests

* Updated the screenshots
  • Loading branch information
bvitaliyg authored Jun 12, 2023
1 parent b20be3f commit ab78664
Show file tree
Hide file tree
Showing 252 changed files with 131 additions and 116 deletions.
12 changes: 0 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,6 @@ android {
}
}

project.afterEvaluate {
tasks.configureEach { task ->
def name = task.name.toLowerCase()
def isAndroidTestFlavour = name.contains("androidtest") || name.contains("screenshots")
def isKspTask = name.startsWith("ksp")
if (isAndroidTestFlavour && isKspTask) {
// if we run the ksp for android test sources we will generate empty stories list
task.enabled = false
}
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation libs.square.picasso
Expand Down
2 changes: 1 addition & 1 deletion app/screenshots.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ android {
managedDevices.devices {
Docs(ManagedVirtualDevice) {
device = "Pixel"
apiLevel = 30
apiLevel = 31
systemImageSource = "aosp"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface StoriesRepository {
private object StoriesRepositoryImpl : StoriesRepository {

private val stories = Story
.all()
.all
.asSequence()

private val visibleStories = stories
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/java/net/skyscanner/backpack/demo/meta/Story.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package net.skyscanner.backpack.demo.meta
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import net.skyscanner.backpack.meta.StoryKind
import kotlin.reflect.full.memberFunctions

@Immutable
data class Story(
Expand All @@ -31,6 +32,16 @@ data class Story(
val content: @Composable () -> Unit,
) {

// used for code-generated extensions
companion object
companion object {

val all: List<Story> by lazy {
val kclass = try {
Class.forName("net.skyscanner.backpack.demo.meta.KspGeneratedStories").kotlin
} catch (e: ClassNotFoundException) {
null
}
val listFunction = kclass?.memberFunctions?.find { it.name == "list" }
listFunction?.call(kclass.objectInstance) as? List<Story> ?: emptyList()
}
}
}
Binary file modified docs/compose/Badge/screenshots/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Badge/screenshots/default_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/BarChart/screenshots/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/BarChart/screenshots/default_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/BottomNav/screenshots/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/BottomNav/screenshots/default_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/BottomSheet/screenshots/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/BottomSheet/screenshots/default_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Button/screenshots/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Button/screenshots/default_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Button/screenshots/drawable-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Button/screenshots/drawable-icon_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Button/screenshots/large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Button/screenshots/large_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Button/screenshots/link.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Button/screenshots/link_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Calendar2/screenshots/day-labels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Calendar2/screenshots/day-labels_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Calendar2/screenshots/pre-selected-range.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Calendar2/screenshots/pre-selected-range_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Calendar2/screenshots/selection-whole-month.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Calendar2/screenshots/selection-whole-month_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Card/screenshots/card-wrapper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Card/screenshots/card-wrapper_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Card/screenshots/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/compose/Card/screenshots/default_dm.png
Binary file modified docs/compose/Card/screenshots/divided-card.png
Binary file modified docs/compose/Card/screenshots/divided-card_dm.png
Binary file modified docs/compose/CardButton/screenshots/default.png
Binary file modified docs/compose/CardButton/screenshots/default_dm.png
Binary file modified docs/compose/CardButton/screenshots/large.png
Binary file modified docs/compose/CardButton/screenshots/large_dm.png
Binary file modified docs/compose/Carousel/screenshots/default.png
Binary file modified docs/compose/Carousel/screenshots/default_dm.png
Binary file modified docs/compose/Checkbox/screenshots/default.png
Binary file modified docs/compose/Checkbox/screenshots/default_dm.png
Binary file modified docs/compose/Chip/screenshots/default.png
Binary file modified docs/compose/Chip/screenshots/default_dm.png
Binary file modified docs/compose/Chip/screenshots/on-dark.png
Binary file modified docs/compose/Chip/screenshots/on-dark_dm.png
Binary file modified docs/compose/Chip/screenshots/on-image.png
Binary file modified docs/compose/Chip/screenshots/on-image_dm.png
Binary file modified docs/compose/Dialog/screenshots/destructive.png
Binary file modified docs/compose/Dialog/screenshots/destructive_dm.png
Binary file modified docs/compose/Dialog/screenshots/flare.png
Binary file modified docs/compose/Dialog/screenshots/flare_dm.png
Binary file modified docs/compose/Dialog/screenshots/image-end-alignment.png
Binary file modified docs/compose/Dialog/screenshots/image-end-alignment_dm.png
Binary file modified docs/compose/Dialog/screenshots/image-start-alignment.png
Binary file modified docs/compose/Dialog/screenshots/image-start-alignment_dm.png
Binary file modified docs/compose/Dialog/screenshots/success-three-buttons.png
Binary file modified docs/compose/Dialog/screenshots/success-three-buttons_dm.png
Binary file modified docs/compose/Dialog/screenshots/warning.png
Binary file modified docs/compose/Dialog/screenshots/warning_dm.png
Binary file modified docs/compose/Divider/screenshots/default.png
Binary file modified docs/compose/Divider/screenshots/default_dm.png
Binary file modified docs/compose/FieldSet/screenshots/default.png
Binary file modified docs/compose/FieldSet/screenshots/default_dm.png
Binary file modified docs/compose/FieldSet/screenshots/disabled.png
Binary file modified docs/compose/FieldSet/screenshots/disabled_dm.png
Binary file modified docs/compose/FieldSet/screenshots/error.png
Binary file modified docs/compose/FieldSet/screenshots/error_dm.png
Binary file modified docs/compose/FieldSet/screenshots/validated.png
Binary file modified docs/compose/FieldSet/screenshots/validated_dm.png
Binary file modified docs/compose/Flare/screenshots/default.png
Binary file modified docs/compose/Flare/screenshots/default_dm.png
Binary file modified docs/compose/FlightLeg/screenshots/default.png
Binary file modified docs/compose/FlightLeg/screenshots/default_dm.png
Binary file modified docs/compose/FloatingActionButton/screenshots/default.png
Binary file modified docs/compose/FloatingActionButton/screenshots/default_dm.png
Binary file modified docs/compose/FloatingNotification/screenshots/default.png
Binary file modified docs/compose/FloatingNotification/screenshots/default_dm.png
Binary file modified docs/compose/HorizontalNav/screenshots/default.png
Binary file modified docs/compose/HorizontalNav/screenshots/default_dm.png
Binary file modified docs/compose/Icon/screenshots/default.png
Binary file modified docs/compose/Icon/screenshots/default_dm.png
Binary file modified docs/compose/NavBar/screenshots/collapsible.png
Binary file modified docs/compose/NavBar/screenshots/collapsible_dm.png
Binary file modified docs/compose/NavBar/screenshots/default.png
Binary file modified docs/compose/NavBar/screenshots/default_dm.png
Binary file modified docs/compose/Nudger/screenshots/default.png
Binary file modified docs/compose/Nudger/screenshots/default_dm.png
Binary file modified docs/compose/Overlay/screenshots/default.png
Binary file modified docs/compose/Overlay/screenshots/default_dm.png
Binary file modified docs/compose/PageIndicator/screenshots/default.png
Binary file modified docs/compose/PageIndicator/screenshots/default_dm.png
Binary file modified docs/compose/Panel/screenshots/default.png
Binary file modified docs/compose/Panel/screenshots/default_dm.png
Binary file modified docs/compose/Price/screenshots/large.png
Binary file modified docs/compose/Price/screenshots/large_dm.png
Binary file modified docs/compose/Price/screenshots/small.png
Binary file modified docs/compose/Price/screenshots/small_dm.png
Binary file modified docs/compose/RadioButton/screenshots/default.png
Binary file modified docs/compose/RadioButton/screenshots/default_dm.png
Binary file modified docs/compose/Rating/screenshots/default.png
Binary file modified docs/compose/Rating/screenshots/default_dm.png
Binary file modified docs/compose/Skeleton/screenshots/default.png
Binary file modified docs/compose/Skeleton/screenshots/default_dm.png
Binary file modified docs/compose/Slider/screenshots/default.png
Binary file modified docs/compose/Slider/screenshots/default_dm.png
Binary file modified docs/compose/Spinner/screenshots/default.png
Binary file modified docs/compose/Spinner/screenshots/default_dm.png
Binary file modified docs/compose/StarRating/screenshots/default.png
Binary file modified docs/compose/StarRating/screenshots/default_dm.png
Binary file modified docs/compose/StarRatingInteractive/screenshots/default.png
Binary file modified docs/compose/StarRatingInteractive/screenshots/default_dm.png
Binary file modified docs/compose/Switch/screenshots/default.png
Binary file modified docs/compose/Switch/screenshots/default_dm.png
Binary file modified docs/compose/Text/screenshots/body.png
Binary file modified docs/compose/Text/screenshots/body_dm.png
Binary file modified docs/compose/Text/screenshots/heading.png
Binary file modified docs/compose/Text/screenshots/heading_dm.png
Binary file modified docs/compose/Text/screenshots/hero.png
Binary file modified docs/compose/Text/screenshots/hero_dm.png
Binary file modified docs/compose/TextField/screenshots/default.png
Binary file modified docs/compose/TextField/screenshots/default_dm.png
Binary file modified docs/compose/TextField/screenshots/disabled.png
Binary file modified docs/compose/TextField/screenshots/disabled_dm.png
Binary file modified docs/compose/TextField/screenshots/error.png
Binary file modified docs/compose/TextField/screenshots/error_dm.png
Binary file modified docs/compose/TextField/screenshots/validated.png
Binary file modified docs/compose/TextField/screenshots/validated_dm.png
Binary file modified docs/view/Badge/screenshots/default.png
Binary file modified docs/view/Badge/screenshots/default_dm.png
Binary file modified docs/view/BarChart/screenshots/default.png
Binary file modified docs/view/BarChart/screenshots/default_dm.png
Binary file modified docs/view/BottomNav/screenshots/default.png
Binary file modified docs/view/BottomNav/screenshots/default_dm.png
Binary file modified docs/view/BottomSheet/screenshots/default.png
Binary file modified docs/view/BottomSheet/screenshots/default_dm.png
Binary file modified docs/view/Button/screenshots/large.png
Binary file modified docs/view/Button/screenshots/large_dm.png
Binary file modified docs/view/Button/screenshots/link.png
Binary file modified docs/view/Button/screenshots/link_dm.png
Binary file modified docs/view/Button/screenshots/standard.png
Binary file modified docs/view/Button/screenshots/standard_dm.png
Binary file modified docs/view/Calendar2/screenshots/day-labels.png
Binary file modified docs/view/Calendar2/screenshots/day-labels_dm.png
Binary file modified docs/view/Calendar2/screenshots/pre-selected-range.png
Binary file modified docs/view/Calendar2/screenshots/pre-selected-range_dm.png
Binary file modified docs/view/Calendar2/screenshots/selection-whole-month.png
Binary file modified docs/view/Calendar2/screenshots/selection-whole-month_dm.png
Binary file modified docs/view/Card/screenshots/corner-style-large.png
Binary file modified docs/view/Card/screenshots/corner-style-large_dm.png
Binary file modified docs/view/Card/screenshots/default.png
Binary file modified docs/view/Card/screenshots/default_dm.png
Binary file modified docs/view/Card/screenshots/selected.png
Binary file modified docs/view/Card/screenshots/selected_dm.png
Binary file modified docs/view/Card/screenshots/with-divider-and-corner-style-large.png
Binary file modified docs/view/Card/screenshots/with-divider-arranged-vertically.png
Binary file modified docs/view/Card/screenshots/with-divider-arranged-vertically_dm.png
Binary file modified docs/view/Card/screenshots/with-divider-without-padding.png
Binary file modified docs/view/Card/screenshots/with-divider-without-padding_dm.png
Binary file modified docs/view/Card/screenshots/with-divider.png
Binary file modified docs/view/Card/screenshots/with-divider_dm.png
Binary file modified docs/view/Card/screenshots/without-padding.png
Binary file modified docs/view/Card/screenshots/without-padding_dm.png
Binary file modified docs/view/Checkbox/screenshots/default.png
Binary file modified docs/view/Checkbox/screenshots/default_dm.png
Binary file modified docs/view/Chip/screenshots/default.png
Binary file modified docs/view/Chip/screenshots/default_dm.png
Binary file modified docs/view/Chip/screenshots/on-dark.png
Binary file modified docs/view/Chip/screenshots/on-dark_dm.png
Binary file modified docs/view/Chip/screenshots/on-image.png
Binary file modified docs/view/Chip/screenshots/on-image_dm.png
Binary file modified docs/view/Dialog/screenshots/destructive.png
Binary file modified docs/view/Dialog/screenshots/destructive_dm.png
Binary file modified docs/view/Dialog/screenshots/flare.png
Binary file modified docs/view/Dialog/screenshots/flare_dm.png
Binary file modified docs/view/Dialog/screenshots/success-three-buttons.png
Binary file modified docs/view/Dialog/screenshots/success-three-buttons_dm.png
Binary file modified docs/view/Flare/screenshots/default.png
Binary file modified docs/view/Flare/screenshots/default_dm.png
Binary file modified docs/view/Flare/screenshots/inset-padding-mode.png
Binary file modified docs/view/Flare/screenshots/inset-padding-mode_dm.png
Binary file modified docs/view/Flare/screenshots/pointer-offset.png
Binary file modified docs/view/Flare/screenshots/pointer-offset_dm.png
Binary file modified docs/view/Flare/screenshots/pointing-up.png
Binary file modified docs/view/Flare/screenshots/pointing-up_dm.png
Binary file modified docs/view/Flare/screenshots/rounded.png
Binary file modified docs/view/Flare/screenshots/rounded_dm.png
Binary file modified docs/view/FloatingActionButton/screenshots/default.png
Binary file modified docs/view/FloatingActionButton/screenshots/default_dm.png
Binary file modified docs/view/HorizontalNav/screenshots/default.png
Binary file modified docs/view/HorizontalNav/screenshots/default_dm.png
Binary file modified docs/view/Icon/screenshots/default.png
Binary file modified docs/view/Icon/screenshots/default_dm.png
Binary file modified docs/view/Icon/screenshots/small.png
Binary file modified docs/view/Icon/screenshots/small_dm.png
Binary file modified docs/view/NavBar/screenshots/collapsed.png
Binary file modified docs/view/NavBar/screenshots/collapsed_dm.png
Binary file modified docs/view/NavBar/screenshots/default.png
Binary file modified docs/view/NavBar/screenshots/default_dm.png
Binary file modified docs/view/NavBar/screenshots/with-menu.png
Binary file modified docs/view/NavBar/screenshots/with-menu_dm.png
Binary file modified docs/view/Nudger/screenshots/default.png
Binary file modified docs/view/Nudger/screenshots/default_dm.png
Binary file modified docs/view/Overlay/screenshots/default.png
Binary file modified docs/view/Overlay/screenshots/default_dm.png
Binary file modified docs/view/Panel/screenshots/default.png
Binary file modified docs/view/Panel/screenshots/default_dm.png
Binary file modified docs/view/RadioButton/screenshots/default.png
Binary file modified docs/view/RadioButton/screenshots/default_dm.png
Binary file modified docs/view/Rating/screenshots/default.png
Binary file modified docs/view/Rating/screenshots/default_dm.png
Binary file modified docs/view/Rating/screenshots/horizontal.png
Binary file modified docs/view/Rating/screenshots/horizontal_dm.png
Binary file modified docs/view/Rating/screenshots/pill.png
Binary file modified docs/view/Rating/screenshots/pill_dm.png
Binary file modified docs/view/Rating/screenshots/vertical.png
Binary file modified docs/view/Rating/screenshots/vertical_dm.png
Binary file modified docs/view/Skeleton/screenshots/default.png
Binary file modified docs/view/Skeleton/screenshots/default_dm.png
Binary file modified docs/view/Slider/screenshots/default.png
Binary file modified docs/view/Slider/screenshots/default_dm.png
Binary file modified docs/view/Snackbar/screenshots/default.png
Binary file modified docs/view/Snackbar/screenshots/default_dm.png
Binary file modified docs/view/Snackbar/screenshots/icon.png
Binary file modified docs/view/Snackbar/screenshots/icon_dm.png
Binary file modified docs/view/Spinner/screenshots/default.png
Binary file modified docs/view/Spinner/screenshots/default_dm.png
Binary file modified docs/view/StarRating/screenshots/default.png
Binary file modified docs/view/StarRating/screenshots/default_dm.png
Binary file modified docs/view/StarRatingInteractive/screenshots/default.png
Binary file modified docs/view/StarRatingInteractive/screenshots/default_dm.png
Binary file modified docs/view/Switch/screenshots/default.png
Binary file modified docs/view/Switch/screenshots/default_dm.png
Binary file modified docs/view/Text/screenshots/body.png
Binary file modified docs/view/Text/screenshots/body_dm.png
Binary file modified docs/view/Text/screenshots/heading.png
Binary file modified docs/view/Text/screenshots/heading_dm.png
Binary file modified docs/view/Text/screenshots/hero.png
Binary file modified docs/view/Text/screenshots/hero_dm.png
Binary file modified docs/view/TextField/screenshots/default.png
Binary file modified docs/view/TextField/screenshots/default_dm.png
Binary file modified docs/view/TextField/screenshots/with-labels.png
Binary file modified docs/view/TextField/screenshots/with-labels_dm.png
Binary file modified docs/view/TextSpans/screenshots/default.png
Binary file modified docs/view/TextSpans/screenshots/default_dm.png
Binary file modified docs/view/Toast/screenshots/default.png
Binary file modified docs/view/Toast/screenshots/default_dm.png
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ lifecycle = "2.6.1"
threeTenAbp = "1.4.5"
androidXJunit = "1.1.5"
coroutines = "1.7.1"
kotlinPoet = "1.14.2"

[libraries]

Expand All @@ -37,8 +38,6 @@ androidx-constraintLayout = "androidx.constraintlayout:constraintlayout:2.1.4"
androidx-swiperefreshLayout = "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
androidx-coreKts = "androidx.core:core-ktx:1.10.1"

androidx-roomCompilerProcessing = "androidx.room:room-compiler-processing:2.5.1"

androidx-lifecycleKtx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycle" }
androidx-lifecycleViewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel", version.ref = "lifecycle" }
androidx-lifecycleViewmodelKtx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "lifecycle" }
Expand Down Expand Up @@ -66,7 +65,8 @@ google-kspApi = { module = "com.google.devtools.ksp:symbol-processing-api", vers
google-guava = "com.google.guava:guava:32.0.1-jre"

square-picasso = "com.squareup.picasso:picasso:2.71828"
square-kotlinPoet = "com.squareup:kotlinpoet:1.14.2"
square-kotlinPoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinPoet" }
square-kotlinPoetKsp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlinPoet" }

kotlin-reflection = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
kotlin-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" }
Expand Down
2 changes: 1 addition & 1 deletion meta/processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'kotlin'
dependencies {
implementation libs.google.kspApi
implementation libs.square.kotlinPoet
implementation libs.androidx.roomCompilerProcessing
implementation libs.square.kotlinPoetKsp
implementation project(":meta:annotations")
testImplementation libs.test.junit
testImplementation libs.kotlin.compilerTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package net.skyscanner.backpack.ksp

import androidx.room.compiler.processing.ExperimentalProcessingApi
import androidx.room.compiler.processing.XProcessingEnv
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.SymbolProcessor
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
Expand All @@ -33,7 +31,6 @@ import net.skyscanner.backpack.ksp.writer.writeListOfStories
import net.skyscanner.backpack.meta.ComponentMarker
import net.skyscanner.backpack.meta.StoryMarker

@OptIn(ExperimentalProcessingApi::class)
class BackpackSymbolProcessor(
private val environment: SymbolProcessorEnvironment,
) : SymbolProcessor {
Expand All @@ -43,8 +40,6 @@ class BackpackSymbolProcessor(
override fun process(resolver: Resolver): List<KSAnnotated> {
if (invoked) return emptyList()

val filer = XProcessingEnv.create(environment.options, resolver, environment.codeGenerator, environment.logger).filer

val components = resolver
.getSymbolsWithAnnotation(ComponentMarker::class.qualifiedName!!)
.filter { it.validate() }
Expand All @@ -65,7 +60,7 @@ class BackpackSymbolProcessor(
.mapNotNull { it.accept(StoriesVisitor(annotation), components) }
}

writeListOfStories(stories.toList(), filer)
writeListOfStories(stories.toList(), environment.codeGenerator)

invoked = true
return emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,57 @@

package net.skyscanner.backpack.ksp.writer

import androidx.room.compiler.processing.XFiler
import androidx.room.compiler.processing.writeTo
import com.google.devtools.ksp.processing.CodeGenerator
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.asClassName
import com.squareup.kotlinpoet.ksp.writeTo
import net.skyscanner.backpack.ksp.ComponentDefinition
import net.skyscanner.backpack.ksp.StoryDefinition

private const val MetaPackage = "net.skyscanner.backpack.demo.meta"
private val StoryClass = ClassName(MetaPackage, "Story")
private val StoryCompanion = ClassName(MetaPackage, "Story.Companion")
private val ComponentClass = ClassName(MetaPackage, "Component")
private val StoriesClass = List::class.asClassName().parameterizedBy(StoryClass)

fun writeListOfStories(stories: List<StoryDefinition>, output: XFiler) {
FunSpec
.builder("all")
.receiver(StoryCompanion)
.returns(StoriesClass)
.addCode(CodeBlock
.builder()
.add("return listOf(\n")
.indent()
.apply {
stories.forEach {
writeStoryCreator(it)
}
}
.unindent()
.add(")")
.build(),
fun writeListOfStories(stories: List<StoryDefinition>, output: CodeGenerator) {
if (stories.isEmpty()) return

TypeSpec
.objectBuilder("KspGeneratedStories")
.addModifiers(KModifier.INTERNAL)
.addFunction(
FunSpec
.builder("list")
.returns(StoriesClass)
.addCode(
CodeBlock
.builder()
.add("return listOf(\n")
.indent()
.apply {
stories.forEach {
writeStoryCreator(it)
}
}
.unindent()
.add(")")
.build(),
)
.build(),
)
.build()
.let {
FileSpec
.builder(MetaPackage, "GeneratedStories")
.addFunction(it)
.builder(MetaPackage, "KspGeneratedStories")
.addType(it)
.build()
.writeTo(output, mode = XFiler.Mode.Aggregating)
.writeTo(codeGenerator = output, aggregating = true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal fun testKsp(
}
val result = compilation.compile()
require(result.exitCode == KotlinCompilation.ExitCode.OK) { result.messages }
val generatedStories = compilation.kspSourcesDir.walkTopDown().first { it.name == "GeneratedStories.kt" }
val generatedStories = compilation.kspSourcesDir.walkTopDown().first { it.name == "KspGeneratedStories.kt" }
evaluate(result, generatedStories.readText())
}

Expand Down
Loading

0 comments on commit ab78664

Please sign in to comment.