Skip to content

Commit

Permalink
Added more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vaslabs committed Jan 29, 2025
1 parent 8f4f749 commit b62c217
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Adopted from AGP screenshot test template, a sample can be found in-->
<!-- https://github.com/vaslabs-ltd/android-screenshot-test-sample/blob/main/app/src/main/AndroidManifest.xml-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.screenshottest">

Expand Down
20 changes: 10 additions & 10 deletions kotlinlib/src/mill/kotlinlib/android/AndroidAppKotlinModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ trait AndroidAppKotlinModule extends AndroidAppModule with KotlinModule { outer
}

final def layoutLibRuntimePath: T[PathRef] = Task {
val extractDestination = T.dest / "layoutLib"
val extractDestination = Task.dest / "layoutLib"
val layoutLibJar = layoutLibRuntime().head
os.unzip(layoutLibJar.path, extractDestination)
val frameworkResPath = extractDestination / "data/framework_res.jar"
Expand Down Expand Up @@ -184,19 +184,19 @@ trait AndroidAppKotlinModule extends AndroidAppModule with KotlinModule { outer
/** The location to store the generated preview summary */
def androidScreenshotGeneratedResults: T[PathRef] =
Task {
PathRef(T.dest / "results.json")
PathRef(Task.dest / "results.json")
}

/**
* The location that the renderer results summary is, in the test engine's expected format
* i.e. by renaming the screenshotResults key to screenshots
*/
def androidScreenshotResults: T[PathRef] = Task {
PathRef(T.dest / "results.json")
PathRef(Task.dest / "results.json")
}

private def screenshotResults: Task[PathRef] = Task {
val dir = T.dest / "generated-screenshots"
val dir = Task.dest / "generated-screenshots"
os.makeDir(dir)
PathRef(dir)
}
Expand All @@ -209,8 +209,8 @@ trait AndroidAppKotlinModule extends AndroidAppModule with KotlinModule { outer
*/
def composePreviewArgs: T[PathRef] = Task {
val output = screenshotResults().path
val metadataFolder = T.dest / "meta-data"
val cliArgsFile = T.dest / "cli_arguments.json"
val metadataFolder = Task.dest / "meta-data"
val cliArgsFile = Task.dest / "cli_arguments.json"
val resultsFilePath = androidScreenshotGeneratedResults().path

val cliArgs = ComposeRenderer.Args(
Expand Down Expand Up @@ -253,7 +253,7 @@ trait AndroidAppKotlinModule extends AndroidAppModule with KotlinModule { outer
mainArgs = Seq(composePreviewArgs().path.toString())
).out.lines()

T.log.info(previewGenOut.mkString("\n"))
Task.log.info(previewGenOut.mkString("\n"))

Agg.from(os.walk(screenshotResults().path).filter(_.ext == "png").map(PathRef(_)))
}
Expand All @@ -279,7 +279,7 @@ trait AndroidAppKotlinModule extends AndroidAppModule with KotlinModule { outer
/* TODO enhance with hash (sha-1) and auto-detection/generation of methodFQN */
def androidDiscoveredPreviews: T[(PathRef, Seq[ComposeRenderer.Screenshot])] = Task {

val androidDiscoveredPreviewsPath = T.dest / "previews_discovered.json"
val androidDiscoveredPreviewsPath = Task.dest / "previews_discovered.json"

val screenshotConfigurations = for {
(methodFQN, methodParams) <- androidScreenshotTestMethods
Expand All @@ -299,7 +299,7 @@ trait AndroidAppKotlinModule extends AndroidAppModule with KotlinModule { outer
}

private def diffImageDirPath: Task[PathRef] = Task {
val diffImageDir = T.dest / "diff-images"
val diffImageDir = Task.dest / "diff-images"
PathRef(diffImageDir)
}

Expand All @@ -316,7 +316,7 @@ trait AndroidAppKotlinModule extends AndroidAppModule with KotlinModule { outer
}

def androidScreenshotTestResultDir: T[PathRef] = Task {
PathRef(T.dest)
PathRef(Task.dest)
}

/** Threshold of how strict the image diff should be */
Expand Down
10 changes: 10 additions & 0 deletions kotlinlib/src/mill/kotlinlib/android/ComposeRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import mill.api.internal

private[android] object ComposeRenderer {


/*
* Model as in
* [[https://android.googlesource.com/platform/tools/base/+/61923408e5f7dc20f0840844597f9dde17453a0f/preview/screenshot/screenshot-test-gradle-plugin/src/main/java/com/android/compose/screenshot/PreviewFinder.kt#58]]
*/
@internal case class Args(
fontsPath: String,
layoutlibPath: String,
Expand Down Expand Up @@ -47,6 +52,11 @@ private[android] object ComposeRenderer {
device: String,
uiMode: String
)

/*
* Model as in
* [[https://android.googlesource.com/platform/tools/base/+/61923408e5f7dc20f0840844597f9dde17453a0f/preview/screenshot/screenshot-test-gradle-plugin/src/main/java/com/android/compose/screenshot/PreviewFinder.kt#92]]
*/
case class ComposeScreenshot(
methodFQN: String,
methodParams: Seq[Map[String, String]],
Expand Down

0 comments on commit b62c217

Please sign in to comment.