-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restingbull/compiler plugin rework (#393)
* Add resources to android example Rework compiler plugins: * require ids * indicate which phase the plugin executes: stub and compile * include plugin dependencies * allow compiler plugins to be exported via the exported_compiler_plugins * allow "bash" substitutions for plugin arguments of working directories (anvil demonstrates) * Update bazel toolchains to 3.7
- Loading branch information
1 parent
b7f5832
commit 95b642f
Showing
117 changed files
with
2,122 additions
and
472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
examples/android | ||
examples/node | ||
examples/trivial | ||
examples/anvil |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="little_bat">Where you at?</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="little_bat">Where you at?</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="little_bat">Where are you?</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="little_bat">¿En dónde se encuentra?</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="little_bat">Où êtes-vous?</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="little_bat">どこにいますか?</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="little_bat">Where you at?</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
java_plugin( | ||
name = "dagger_component_plugin", | ||
generates_api = True, | ||
processor_class = "dagger.internal.codegen.ComponentProcessor", | ||
visibility = ["//visibility:private"], | ||
deps = [ | ||
"@maven//:com_google_dagger_dagger_compiler", | ||
], | ||
) | ||
|
||
java_library( | ||
name = "dagger", | ||
exported_plugins = [":dagger_component_plugin"], | ||
exports = [ | ||
"@maven//:com_google_dagger_dagger", | ||
"@maven//:javax_inject_javax_inject", | ||
], | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Forked from https://github.com/square/anvil/tree/main/sample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
RULES_JVM_EXTERNAL_TAG = "2.8" | ||
|
||
RULES_JVM_EXTERNAL_SHA = "79c9850690d7614ecdb72d68394f994fef7534b292c4867ce5e7dec0aa7bdfad" | ||
|
||
http_archive( | ||
name = "rules_jvm_external", | ||
sha256 = RULES_JVM_EXTERNAL_SHA, | ||
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, | ||
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG, | ||
) | ||
|
||
load("@rules_jvm_external//:defs.bzl", "maven_install") | ||
|
||
maven_install( | ||
artifacts = [ | ||
"com.google.dagger:dagger:2.28", | ||
"com.google.dagger:dagger-compiler:2.28", | ||
"com.google.dagger:dagger-producers:2.28", | ||
"com.squareup.anvil:compiler:2.0.1", | ||
"com.squareup.anvil:annotations:2.0.1", | ||
"androidx.activity:activity:1.0.0", | ||
"androidx.annotation:annotation:1.1.0", | ||
"androidx.appcompat:appcompat-resources:1.1.0", | ||
"androidx.appcompat:appcompat:1.1.0", | ||
"androidx.arch.core:core-common:2.1.0", | ||
"androidx.arch.core:core-runtime:2.0.0", | ||
"androidx.cardview:cardview:1.0.0", | ||
"androidx.collection:collection:1.1.0", | ||
"androidx.coordinatorlayout:coordinatorlayout:1.1.0", | ||
"androidx.core:core-ktx:1.3.0", | ||
"androidx.core:core:1.3.0", | ||
"androidx.cursoradapter:cursoradapter:1.0.0", | ||
"androidx.customview:customview:1.0.0", | ||
"androidx.drawerlayout:drawerlayout:1.0.0", | ||
"androidx.fragment:fragment:1.0.0", | ||
"androidx.fragment:fragment:1.1.0", | ||
"androidx.interpolator:interpolator:1.0.0", | ||
"androidx.lifecycle:lifecycle-common:2.1.0", | ||
"androidx.lifecycle:lifecycle-livedata-core:2.0.0", | ||
"androidx.lifecycle:lifecycle-livedata:2.0.0", | ||
"androidx.lifecycle:lifecycle-runtime:2.1.0", | ||
"androidx.lifecycle:lifecycle-viewmodel:2.1.0", | ||
"androidx.loader:loader:1.0.0", | ||
"androidx.recyclerview:recyclerview:1.1.0", | ||
"androidx.savedstate:savedstate:1.0.0", | ||
"androidx.transition:transition:1.2.0", | ||
"androidx.vectordrawable:vectordrawable-animated:1.1.0", | ||
"androidx.vectordrawable:vectordrawable:1.1.0", | ||
"androidx.versionedparcelable:versionedparcelable:1.1.0", | ||
"androidx.viewpager2:viewpager2:1.0.0", | ||
"androidx.viewpager:viewpager:1.0.0", | ||
"com.google.android.material:material:1.1.0", | ||
"javax.inject:javax.inject:1", | ||
"junit:junit:4.13", | ||
"org.jetbrains.kotlin:kotlin-test:1.3.50", | ||
"com.google.truth:truth:1.0.1", | ||
"org.jetbrains:annotations:13.0", | ||
"org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.72", | ||
], | ||
excluded_artifacts = [ | ||
"org.jetbrains.kotlin:kotlin-stdlib", | ||
"org.jetbrains.kotlin:kotlin-stdlib-jdk8", | ||
"org.jetbrains.kotlin:kotlin-stdlib-jdk7", | ||
], | ||
repositories = [ | ||
"https://jcenter.bintray.com/", | ||
"https://maven.google.com", | ||
"https://repo1.maven.org/maven2", | ||
], | ||
) | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "build_bazel_rules_android", | ||
sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806", | ||
strip_prefix = "rules_android-0.1.1", | ||
urls = ["https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"], | ||
) | ||
|
||
load( | ||
"@build_bazel_rules_android//android:rules.bzl", | ||
"android_ndk_repository", | ||
"android_sdk_repository", | ||
) | ||
|
||
android_sdk_repository(name = "androidsdk") | ||
|
||
android_ndk_repository(name = "androidndk") # Required. Name *must* be "androidndk". | ||
|
||
# Directly load the kotlin rules from the parent repo. | ||
local_repository( | ||
name = "io_bazel_rules_kotlin", | ||
path = "../..", | ||
) | ||
|
||
load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies") | ||
|
||
kt_download_local_dev_dependencies() | ||
|
||
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") | ||
|
||
kotlin_repositories() | ||
|
||
kt_register_toolchains() | ||
|
||
# Skylib, for build_test, so don't bother initializing the unit test infrastructure. | ||
http_archive( | ||
name = "bazel_skylib", | ||
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", | ||
urls = [ | ||
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", | ||
], | ||
) | ||
|
||
http_archive( | ||
name = "rules_pkg", | ||
sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a", | ||
url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
load("@build_bazel_rules_android//android:rules.bzl", "android_binary") | ||
|
||
android_binary( | ||
name = "app", | ||
custom_package = "com.squareup.anvil.sample", | ||
manifest = "src/main/AndroidManifest.xml", | ||
visibility = ["//app:__subpackages__"], | ||
deps = [ | ||
"//app/src/main/java/com/squareup/anvil/sample", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
id 'org.jetbrains.kotlin.kapt' | ||
id 'com.squareup.anvil' | ||
} | ||
|
||
android { | ||
compileSdkVersion 29 | ||
|
||
defaultConfig { | ||
applicationId "com.squareup.anvil.sample" | ||
minSdkVersion 23 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0.0" | ||
|
||
testInstrumentationRunner "com.squareup.anvil.sample.TestRunner" | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
lintOptions { | ||
warningsAsErrors true | ||
} | ||
|
||
variantFilter { variant -> | ||
//noinspection UnnecessaryQualifiedReference | ||
if (variant.buildType.name == com.android.builder.core.BuilderConstants.RELEASE) { | ||
variant.setIgnore(true) | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation project(':sample:library') | ||
implementation project(':sample:scopes') | ||
|
||
implementation deps.kotlin.stdlib | ||
implementation deps.androidx.appcompat | ||
implementation deps.androidx.core | ||
implementation deps.androidx.material | ||
implementation deps.dagger2.dagger | ||
|
||
kapt deps.dagger2.compiler | ||
|
||
testImplementation deps.junit | ||
testImplementation deps.truth | ||
|
||
androidTestImplementation deps.androidx.test.core | ||
androidTestImplementation deps.androidx.test.espresso.core | ||
androidTestImplementation deps.androidx.test.junit | ||
androidTestImplementation deps.androidx.test.rules | ||
androidTestImplementation deps.androidx.test.runner | ||
androidTestImplementation deps.junit | ||
|
||
kaptAndroidTest deps.dagger2.compiler | ||
} |
24 changes: 24 additions & 0 deletions
24
examples/anvil/app/src/androidTest/java/com/squareup/anvil/sample/AnvilSampleTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.squareup.anvil.sample | ||
|
||
import androidx.test.espresso.Espresso | ||
import androidx.test.espresso.assertion.ViewAssertions | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.rule.ActivityTestRule | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class AnvilSampleTest { | ||
|
||
@Rule | ||
@JvmField | ||
val activityRule = ActivityTestRule(MainActivity::class.java) | ||
|
||
@Test | ||
fun text_is_displayed() { | ||
Espresso.onView(ViewMatchers.withText("Hephaestus, son of (No Father) and Hera")) | ||
.check(ViewAssertions.matches(ViewMatchers.isDisplayed())) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
examples/anvil/app/src/androidTest/java/com/squareup/anvil/sample/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# TODO: Implement tests when android_test works on more than linux. |
8 changes: 8 additions & 0 deletions
8
examples/anvil/app/src/androidTest/java/com/squareup/anvil/sample/FakeFatherProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.squareup.anvil.sample | ||
|
||
import com.squareup.anvil.sample.father.FatherProvider | ||
import javax.inject.Inject | ||
|
||
class FakeFatherProvider @Inject constructor() : FatherProvider { | ||
override fun father(god: God): String = "(No Father)" | ||
} |
18 changes: 18 additions & 0 deletions
18
...ples/anvil/app/src/androidTest/java/com/squareup/anvil/sample/FakeFatherProviderModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.squareup.anvil.sample | ||
|
||
import com.squareup.anvil.annotations.ContributesTo | ||
import com.squareup.anvil.sample.father.FatherProvider | ||
import com.squareup.anvil.sample.father.FatherProviderModule | ||
import com.squareup.scopes.AppScope | ||
import dagger.Binds | ||
import dagger.Module | ||
|
||
@Module | ||
@ContributesTo( | ||
scope = AppScope::class, | ||
replaces = [FatherProviderModule::class] | ||
) | ||
abstract class FakeFatherProviderModule { | ||
@Binds | ||
abstract fun bindFatherProvider(provider: FakeFatherProvider): FatherProvider | ||
} |
13 changes: 13 additions & 0 deletions
13
examples/anvil/app/src/androidTest/java/com/squareup/anvil/sample/TestApp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.squareup.anvil.sample | ||
|
||
import android.app.Application | ||
import com.squareup.scopes.ComponentHolder | ||
|
||
class TestApp : Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
ComponentHolder.components += DaggerTestAppComponent.create() | ||
} | ||
} |
Oops, something went wrong.