Skip to content
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

Add compose support for android_instrumentation_binary #126

Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "grab_bazel_common",
commit = "092435fb286705c4dcd845c93c9d84e94a4088d9",
commit = "7ce14f2063b19b1e700bb9fa51cc944626545450",
remote = "https://github.com/grab/grab-bazel-common.git",
)

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ grazel {
rules {
bazelCommon {
gitRepository {
commit = "092435fb286705c4dcd845c93c9d84e94a4088d9"
commit = "7ce14f2063b19b1e700bb9fa51cc944626545450"
remote = "https://github.com/grab/grab-bazel-common.git"
}
toolchains {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ fun StatementsBuilder.androidInstrumentationBinary(
resourceStripPrefix: String? = null,
resourceFiles: List<Assignee> = emptyList(),
testInstrumentationRunner: String? = null,
enableCompose: Boolean = false,
) {
load(
"@$GRAB_BAZEL_COMMON//rules:defs.bzl",
Expand Down Expand Up @@ -377,5 +378,9 @@ fun StatementsBuilder.androidInstrumentationBinary(
testInstrumentationRunner?.let {
"test_instrumentation_runner" `=` it.quote
}

if (enableCompose) {
"enable_compose" `=` enableCompose.toString().capitalize()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ internal data class AndroidInstrumentationBinaryData(
val resourceStripPrefix: String? = null,
val srcs: List<String>,
val testInstrumentationRunner: String? = null,
val compose: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ internal data class AndroidInstrumentationBinaryTarget(
val resourceStripPrefix: String? = null,
val resourceFiles: List<String>,
val testInstrumentationRunner: String? = null,
val compose: Boolean,
) : BazelBuildTarget {

override fun statements(builder: StatementsBuilder) = builder {
Expand All @@ -56,6 +57,7 @@ internal data class AndroidInstrumentationBinaryTarget(
resourceStripPrefix = resourceStripPrefix,
resourceFiles = buildResFiles(resourceFiles),
testInstrumentationRunner = testInstrumentationRunner,
enableCompose = compose,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.grab.grazel.migrate.target

import com.grab.grazel.gradle.ConfigurationScope.ANDROID_TEST
import com.grab.grazel.gradle.hasCompose
import com.grab.grazel.gradle.hasTestInstrumentationRunner
import com.grab.grazel.gradle.isAndroidApplication
import com.grab.grazel.gradle.variant.VariantMatcher
Expand Down Expand Up @@ -61,14 +62,16 @@ internal class AndroidInstrumentationBinaryTargetBuilder
matchedVariant = matchedVariant,
sourceSetType = SourceSetType.JAVA_KOTLIN,
)
add(androidInstrumentationBinData.toTarget())
add(androidInstrumentationBinData.toTarget(project))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this to extractor instead of directly mapping the value here?

Later we can make extractors cacheable and source of truth for migration data.

So androidInstrumentationBinData itself will contain compose field

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it to extractor 🙇🏻‍♂️

}
}

override fun canHandle(project: Project): Boolean = project.isAndroidApplication
&& project.hasTestInstrumentationRunner

private fun AndroidInstrumentationBinaryData.toTarget() = AndroidInstrumentationBinaryTarget(
private fun AndroidInstrumentationBinaryData.toTarget(
project: Project
) = AndroidInstrumentationBinaryTarget(
name = name,
associates = associates,
customPackage = customPackage,
Expand All @@ -82,6 +85,7 @@ internal class AndroidInstrumentationBinaryTargetBuilder
resourceFiles = resourceFiles,
srcs = srcs,
testInstrumentationRunner = testInstrumentationRunner,
compose = project.hasCompose,
)
}

Expand Down
4 changes: 4 additions & 0 deletions sample-android/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ android_instrumentation_binary(
],
custom_package = "com.grab.grazel.android.sample",
debug_key = "//buildsystem:debug-keystore",
enable_compose = True,
instruments = ":sample-android-flavor1-free-debug",
manifest_values = {
"versionCode": "1",
Expand Down Expand Up @@ -472,6 +473,7 @@ android_instrumentation_binary(
],
custom_package = "com.grab.grazel.android.sample",
debug_key = "//buildsystem:debug-keystore",
enable_compose = True,
instruments = ":sample-android-flavor1-paid-debug",
manifest_values = {
"versionCode": "1",
Expand Down Expand Up @@ -527,6 +529,7 @@ android_instrumentation_binary(
],
custom_package = "com.grab.grazel.android.sample",
debug_key = "//buildsystem:debug-keystore",
enable_compose = True,
instruments = ":sample-android-flavor2-free-debug",
manifest_values = {
"versionCode": "1",
Expand Down Expand Up @@ -582,6 +585,7 @@ android_instrumentation_binary(
],
custom_package = "com.grab.grazel.android.sample",
debug_key = "//buildsystem:debug-keystore",
enable_compose = True,
instruments = ":sample-android-flavor2-paid-debug",
manifest_values = {
"versionCode": "1",
Expand Down
Loading