Skip to content

Commit e034fea

Browse files
committed
addressed review comments
1 parent aa8c9b0 commit e034fea

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

base/src/com/google/idea/blaze/base/sync/aspects/storage/AspectModuleWriter.kt

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,62 @@ def %s(ctx, target):
3232

3333
private const val MODULES_DIRECTORY = "modules"
3434

35+
/**
36+
* Write for one aspect module.
37+
*
38+
* A aspect module is a collection of functions used by the aspect that can
39+
* declare different dependencies. Only if all dependencies are fulfilled
40+
* will the aspect module be written, otherwise only stubs will be generated.
41+
*/
3542
abstract class AspectModuleWriter : AspectWriter {
3643

44+
/**
45+
* A dependency that must be fulfilled for the aspect module to be written.
46+
* Evaluated over the current sync state of the project.
47+
*/
3748
protected fun interface Dependency {
49+
3850
fun isFulfilled(state: SyncProjectState): Boolean
3951
}
4052

53+
/**
54+
* Dependency on a specific rule set (e.g. rules_cc). Requires bazel 7+ and
55+
* only supports bazelmod projects.
56+
*/
4157
protected fun ruleSetDependency(name: String) = Dependency { state ->
4258
state.externalWorkspaceData?.getByRepoName(name) != null
4359
}
4460

61+
/**
62+
* Dependency on a specific registry key.
63+
*/
4564
protected fun registryKeyDependency(key: String) = Dependency {
4665
Registry.`is`(key)
4766
}
4867

68+
/**
69+
* Dependency on a specific bazel version.
70+
*/
4971
protected fun bazelDependency(minVersion: Int) = Dependency { state ->
5072
state.blazeVersionData.bazelIsAtLeastVersion(minVersion, 0, 0)
5173
}
5274

75+
/**
76+
* All dependencies that must be fulfilled for the aspect module to be written.
77+
*/
5378
protected abstract fun dependencies(): ImmutableList<Dependency>
5479

80+
/**
81+
* A public function exposed by the module.
82+
*
83+
* If any dependency is not fulfilled, the provided default value will be used
84+
* to generate a stub for the function.
85+
*/
5586
protected data class Function(val name: String, val defaultValue: String)
5687

88+
/**
89+
* All functions exposed by the module.
90+
*/
5791
protected abstract fun functions(): ImmutableList<Function>
5892

5993
@Throws(IOException::class)
@@ -95,7 +129,7 @@ abstract class AspectModuleWriter : AspectWriter {
95129
}
96130

97131
@Throws(SyncFailedException::class)
98-
override fun writeDumb(dst: Path, project: Project) {
132+
final override fun writeDumb(dst: Path, project: Project) {
99133
try {
100134
generateDefault(dst)
101135
} catch (e: IOException) {
@@ -104,7 +138,7 @@ abstract class AspectModuleWriter : AspectWriter {
104138
}
105139

106140
@Throws(SyncFailedException::class)
107-
override fun write(dst: Path, project: Project, state: SyncProjectState) {
141+
final override fun write(dst: Path, project: Project, state: SyncProjectState) {
108142
if (dependencies().any { !it.isFulfilled(state) }) {
109143
writeDumb(dst, project)
110144
return

0 commit comments

Comments
 (0)