Skip to content

Commit

Permalink
Support latest rule definitions from bazel-common (#113)
Browse files Browse the repository at this point in the history
Fixes #113
  • Loading branch information
arunkumar9t2 committed Oct 25, 2023
1 parent a0cc71b commit 709cb7e
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 77 deletions.
1 change: 1 addition & 0 deletions .bazel/.default.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ build --define=android_dexmerger_tool=d8_dexmerger

build --persistent_multiplex_android_tools
build --strategy=AndroidAssetMerger=sandboxed
build --strategy=AndroidLint=sandboxed
build --strategy=DatabindingStubs=worker
build --worker_max_instances=Javac=1
build --worker_max_instances=KotlinCompile=1
Expand Down
14 changes: 7 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "grab_bazel_common",
commit = "7415aab81c8cfec7ea05bb9bcb2b16d595bbc88e",
commit = "421f7a883add946c6a59e356e8e51800c44fb7a1",
remote = "https://github.com/grab/grab-bazel-common.git",
)

load("@grab_bazel_common//android:repositories.bzl", "bazel_common_dependencies")
load("@grab_bazel_common//rules:repositories.bzl", "bazel_common_dependencies")

bazel_common_dependencies()

load("@grab_bazel_common//android:initialize.bzl", "bazel_common_initialize")
load("@grab_bazel_common//rules:setup.bzl", "bazel_common_setup")

bazel_common_initialize(
buildifier_version = "v6.1.2",
bazel_common_setup(
buildifier_version = "6.3.3",
patched_android_tools = True,
)

load("@grab_bazel_common//android:maven.bzl", "pin_bazel_common_artifacts")
load("@grab_bazel_common//rules:maven.bzl", "pin_bazel_common_dependencies")

pin_bazel_common_artifacts()
pin_bazel_common_dependencies()

DAGGER_TAG = "2.47"

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ grazel {
}
bazelCommon {
gitRepository {
commit = "7415aab81c8cfec7ea05bb9bcb2b16d595bbc88e"
commit = "421f7a883add946c6a59e356e8e51800c44fb7a1"
remote = "https://github.com/grab/grab-bazel-common.git"
}
toolchains {
buildifier {
releaseVersion = "v6.1.2"
releaseVersion = "6.3.3"
supportedOs = ["linux", "darwin"]
supportedArch = ["amd64", "arm64"]
}
Expand Down
7 changes: 3 additions & 4 deletions flavor-libs/sample-library-flavor1/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
load("@grab_bazel_common//tools/test:test.bzl", "grab_kt_jvm_test")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")
load("@grab_bazel_common//rules:defs.bzl", "kotlin_library", "kotlin_test")

kt_jvm_library(
kotlin_library(
name = "sample-library-flavor1",
srcs = glob([
"src/main/java/com/grab/grazel/android/flavor/ModuleName.kt",
Expand All @@ -11,7 +10,7 @@ kt_jvm_library(
],
)

grab_kt_jvm_test(
kotlin_test(
name = "sample-library-flavor1-test",
srcs = glob([
"src/test/java/com/grab/grazel/flavor1/ModuleNameTest.kt",
Expand Down
7 changes: 3 additions & 4 deletions flavor-libs/sample-library-flavor2/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
load("@grab_bazel_common//tools/test:test.bzl", "grab_kt_jvm_test")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")
load("@grab_bazel_common//rules:defs.bzl", "kotlin_library", "kotlin_test")

kt_jvm_library(
kotlin_library(
name = "sample-library-flavor2",
srcs = glob([
"src/main/java/com/grab/grazel/android/flavor/ModuleName.kt",
Expand All @@ -11,7 +10,7 @@ kt_jvm_library(
],
)

grab_kt_jvm_test(
kotlin_test(
name = "sample-library-flavor2-test",
srcs = glob([
"src/test/java/com/grab/grazel/flavor2/ModuleNameTest.kt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.grab.grazel.bazel.rules

import com.android.builder.model.Version
import com.grab.grazel.bazel.starlark.Assignee
import com.grab.grazel.bazel.starlark.BazelDependency
import com.grab.grazel.bazel.starlark.StatementsBuilder
Expand All @@ -26,7 +25,6 @@ import com.grab.grazel.bazel.starlark.glob
import com.grab.grazel.bazel.starlark.load
import com.grab.grazel.bazel.starlark.quote
import com.grab.grazel.bazel.starlark.toObject
import com.grab.grazel.gradle.dependencies.MavenArtifact
import com.grab.grazel.migrate.android.BuildConfigData
import com.grab.grazel.migrate.android.ResValuesData

Expand Down Expand Up @@ -246,17 +244,6 @@ internal fun StatementsBuilder.androidLibrary(
internal const val DATABINDING_GROUP = "androidx.databinding"
internal const val ANDROIDX_GROUP = "androidx.annotation"
internal const val ANNOTATION_ARTIFACT = "annotation"
internal val DATABINDING_ARTIFACTS by lazy {
val version = Version.ANDROID_GRADLE_PLUGIN_VERSION
listOf(
MavenArtifact(DATABINDING_GROUP, "databinding-adapters", version),
MavenArtifact(DATABINDING_GROUP, "databinding-compiler", version),
MavenArtifact(DATABINDING_GROUP, "databinding-common", version),
MavenArtifact(DATABINDING_GROUP, "databinding-runtime", version),
MavenArtifact(DATABINDING_GROUP, "viewbinding", version),
MavenArtifact(ANDROIDX_GROUP, ANNOTATION_ARTIFACT, "1.1.0")
)
}

fun StatementsBuilder.loadCustomRes() {
load("@$GRAB_BAZEL_COMMON//tools/custom_res:custom_res.bzl", "custom_res")
Expand All @@ -274,7 +261,7 @@ fun customRes(
}
}

fun StatementsBuilder.grabAndroidLocalTest(
fun StatementsBuilder.androidUnitTest(
name: String,
customPackage: String,
srcs: List<String> = emptyList(),
Expand All @@ -287,9 +274,9 @@ fun StatementsBuilder.grabAndroidLocalTest(
tags: List<String> = emptyList(),
resourcesGlob: List<String> = emptyList(),
) {
load("@$GRAB_BAZEL_COMMON//tools/test:test.bzl", "grab_android_local_test")
load("@$GRAB_BAZEL_COMMON//rules:defs.bzl", "android_unit_test")

rule("grab_android_local_test") {
rule("android_unit_test") {
"name" `=` name.quote
"custom_package" `=` customPackage.quote
srcs.notEmpty {
Expand Down Expand Up @@ -336,7 +323,7 @@ fun StatementsBuilder.androidInstrumentationBinary(
testInstrumentationRunner: String? = null,
) {
load(
"@$GRAB_BAZEL_COMMON//android/test:instrumentation.bzl",
"@$GRAB_BAZEL_COMMON//rules:defs.bzl",
"android_instrumentation_binary"
)
rule("android_instrumentation_binary") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ fun StatementsBuilder.bazelCommonRepository(
}

fun StatementsBuilder.pinBazelCommonArtifacts(bazelCommonRepoName: String) {
load("@$bazelCommonRepoName//android:maven.bzl", "pin_bazel_common_artifacts")
function("pin_bazel_common_artifacts")
load("@$bazelCommonRepoName//rules:maven.bzl", "pin_bazel_common_dependencies")
function("pin_bazel_common_dependencies")
}

fun StatementsBuilder.bazelCommonDependencies(bazelCommonRepoName: String) {
load("@${bazelCommonRepoName}//android:repositories.bzl", "bazel_common_dependencies")
load("@${bazelCommonRepoName}//rules:repositories.bzl", "bazel_common_dependencies")
function("bazel_common_dependencies")
}

fun StatementsBuilder.bazelCommonInitialize(
bazelCommonRepoName: String,
buildifierVersion: String,
) {
load("@${bazelCommonRepoName}//android:initialize.bzl", "bazel_common_initialize")
function("bazel_common_initialize") {
load("@${bazelCommonRepoName}//rules:setup.bzl", "bazel_common_setup")
function("bazel_common_setup") {
"patched_android_tools" `=` "True"
"buildifier_version" `=` buildifierVersion.quote
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ fun StatementsBuilder.ktLibrary(
assetsDir: String? = null,
tags: List<String> = emptyList()
) {
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")
load("@$GRAB_BAZEL_COMMON//rules:defs.bzl", "kotlin_library")

rule("kt_jvm_library") {
rule("kotlin_library") {
"name" `=` name.quote
srcs.notEmpty {
"srcs" `=` srcs.map(String::quote)
Expand Down Expand Up @@ -188,7 +188,7 @@ fun StatementsBuilder.ktLibrary(
}


fun StatementsBuilder.grabKtJvmTest(
fun StatementsBuilder.kotlinTest(
name: String,
srcs: List<String> = emptyList(),
additionalSrcSets: List<String> = emptyList(),
Expand All @@ -199,9 +199,9 @@ fun StatementsBuilder.grabKtJvmTest(
plugins: List<BazelDependency> = emptyList(),
tags: List<String> = emptyList()
) {
load("@$GRAB_BAZEL_COMMON//tools/test:test.bzl", "grab_kt_jvm_test")
load("@$GRAB_BAZEL_COMMON//rules:defs.bzl", "kotlin_test")

rule("grab_kt_jvm_test") {
rule("kotlin_test") {
"name" `=` name.quote
srcs.notEmpty {
"srcs" `=` srcs.map(String::quote)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.grab.grazel.extension

data class BuildifierExtension(
var releaseVersion: String = "5.1.0",
var releaseVersion: String = "6.3.3",
var supportedOs: List<String>? = null,
var supportedArch: List<String>? = null,
var targetName: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.grab.grazel.migrate.android

import com.grab.grazel.bazel.rules.Visibility
import com.grab.grazel.bazel.rules.grabAndroidLocalTest
import com.grab.grazel.bazel.rules.androidUnitTest
import com.grab.grazel.bazel.starlark.BazelDependency
import com.grab.grazel.bazel.starlark.StatementsBuilder
import com.grab.grazel.migrate.BazelBuildTarget
Expand All @@ -36,7 +36,7 @@ internal data class AndroidUnitTestTarget(
) : BazelBuildTarget {
override fun statements(builder: StatementsBuilder) = builder {
if (srcs.isNotEmpty()) {
grabAndroidLocalTest(
androidUnitTest(
name = name,
deps = deps,
visibility = visibility,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.grab.grazel.migrate.common

import com.grab.grazel.bazel.starlark.BazelDependency
import com.grab.grazel.bazel.starlark.BazelDependency.ProjectDependency
import com.grab.grazel.gradle.hasDatabinding
import com.grab.grazel.bazel.starlark.BazelDependency.StringDependency
import com.grab.grazel.gradle.isAndroid
import com.grab.grazel.gradle.isKotlin
import org.gradle.api.Project
Expand All @@ -33,14 +33,10 @@ import org.gradle.api.Project
*/
internal fun calculateTestAssociate(project: Project, suffix: String = ""): BazelDependency? {
return when {
project.isKotlin && project.hasDatabinding -> {
return BazelDependency.StringDependency(
"""${ProjectDependency(project, suffix)}-kotlin"""
)
}
project.isKotlin && project.isAndroid -> return BazelDependency.StringDependency(
project.isKotlin && project.isAndroid -> return StringDependency(
"""${ProjectDependency(project, suffix)}_kt"""
)

project.isKotlin -> return ProjectDependency(project, suffix)
else -> null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.grab.grazel.migrate.kotlin

import com.grab.grazel.bazel.rules.Visibility
import com.grab.grazel.bazel.rules.grabKtJvmTest
import com.grab.grazel.bazel.rules.kotlinTest
import com.grab.grazel.bazel.starlark.BazelDependency
import com.grab.grazel.bazel.starlark.StatementsBuilder
import com.grab.grazel.migrate.BazelBuildTarget
Expand All @@ -34,7 +34,7 @@ internal data class UnitTestTarget(
) : BazelBuildTarget {
override fun statements(builder: StatementsBuilder) = builder {
if (srcs.isNotEmpty()) {
grabKtJvmTest(
kotlinTest(
name = name,
srcsGlob = srcs,
additionalSrcSets = additionalSrcSets,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.grab.grazel.tasks.internal

import com.grab.grazel.bazel.exec.bazelCommand
import com.grab.grazel.bazel.rules.GRAB_BAZEL_COMMON
import com.grab.grazel.di.GradleServices
import com.grab.grazel.di.GrazelComponent
import com.grab.grazel.di.qualifiers.RootProject
Expand Down Expand Up @@ -62,7 +63,7 @@ constructor(
val execResult = gradleServices.execOperations.bazelCommand(
logger = logger,
"run",
"@grab_bazel_common//:buildifier",
"@$GRAB_BAZEL_COMMON//:buildifier",
"--script_path=${buildifierScript.get().asFile.absolutePath}",
errorOutputStream = outputStream,
ignoreExit = true
Expand Down
6 changes: 4 additions & 2 deletions maven_install.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"dependency_tree": {
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
"__INPUT_ARTIFACTS_HASH": 1101136169,
"__INPUT_ARTIFACTS_HASH": 684997308,
"__RESOLVED_ARTIFACTS_HASH": 781580720,
"conflict_resolution": {},
"conflict_resolution": {
"androidx.annotation:annotation:1.5.0": "androidx.annotation:annotation:1.7.0-alpha03"
},
"dependencies": [
{
"coord": "android.arch.core:common:1.1.0",
Expand Down
4 changes: 2 additions & 2 deletions sample-android-flavor/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.grab.grazel.android.flavor">
package="com.grab.grazel.android.flavor">

<application>
<activity
android:name=".FlavorActivity"
android:exported="true" />
android:exported="true"/>
</application>
</manifest>
Loading

0 comments on commit 709cb7e

Please sign in to comment.