-
Notifications
You must be signed in to change notification settings - Fork 274
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
Support running KSP via KotlinCompilerRunner #1119
base: main
Are you sure you want to change the base?
Changes from all commits
b8cab8b
50c93b2
dd52324
c99bcb5
6566ca1
a2a7d15
e73051e
45354a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Workflow to run tests | ||
|
||
name: standalone compiler runner | ||
|
||
on: | ||
# runs on 2:00 AM PST or 3:00 AM PDT | ||
schedule: | ||
- cron: '0 10 * * *' | ||
|
||
jobs: | ||
build-and-test: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, macos-latest] | ||
branch: [ main, 1.0.7-release ] | ||
|
||
# The type of runner that the job will run on | ||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Setup Java 9 | ||
uses: actions/[email protected] | ||
with: | ||
java-version: '9' | ||
java-package: jdk | ||
architecture: x64 | ||
- name: set JDK_9 environment variable for kotlin compiler | ||
shell: bash | ||
env: | ||
ACTIONS_ALLOW_UNSECURE_COMMANDS: true | ||
run: echo ::set-env name=JDK_9::$(echo $JAVA_HOME) | ||
- name: Setup Java 11 | ||
uses: actions/[email protected] | ||
with: | ||
java-version: '11' | ||
java-package: jdk | ||
architecture: x64 | ||
|
||
# Checkout | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ matrix.branch }} | ||
|
||
# Build cache | ||
- name: Cache Gradle Cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.gradle/caches | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}-${{ hashFiles('**/gradle.properties') }} | ||
# An ordered list of keys to use for restoring the cache if no cache hit occurred for key | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Cache gradle wrapper | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} | ||
|
||
# Run tests | ||
- name: test | ||
shell: bash | ||
run: ./gradlew -Pksp.compiler.runner=standalone --stacktrace --info :integration-tests:test :gradle-plugin:test | ||
- name: Upload test results | ||
if: always() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: test-reports-standalone-${{ matrix.os }}-${{ matrix.branch }} | ||
path: | | ||
compiler-plugin/build/reports | ||
integration-tests/build/reports | ||
gradle-plugin/build/reports | ||
common-util/build/reports |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") | ||
|
||
package com.google.devtools.ksp.gradle | ||
|
||
import org.gradle.api.model.ObjectFactory | ||
import org.jetbrains.kotlin.gradle.dsl.CompilerCommonOptions | ||
import org.jetbrains.kotlin.gradle.dsl.CompilerCommonOptionsDefault | ||
import org.jetbrains.kotlin.gradle.dsl.CompilerJsOptions | ||
import org.jetbrains.kotlin.gradle.dsl.CompilerJsOptionsDefault | ||
import org.jetbrains.kotlin.gradle.dsl.CompilerJvmOptions | ||
import org.jetbrains.kotlin.gradle.dsl.CompilerJvmOptionsDefault | ||
import org.jetbrains.kotlin.gradle.utils.newInstance | ||
|
||
// TODO: to be replaced by KotlinJvmFactory, etc. | ||
class CompilerOptionsFactory { | ||
companion object { | ||
fun createCompilerJvmOptions(objectFactory: ObjectFactory): CompilerJvmOptions = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are targeting Kotlin 1.8.0 - you could already use |
||
objectFactory.newInstance<CompilerJvmOptionsDefault>() | ||
|
||
fun createCompilerJsOptions(objectFactory: ObjectFactory): CompilerJsOptions = | ||
objectFactory.newInstance<CompilerJsOptionsDefault>() | ||
|
||
fun createCompilerCommonOptions(objectFactory: ObjectFactory): CompilerCommonOptions = | ||
objectFactory.newInstance<CompilerCommonOptionsDefault>() | ||
Comment on lines
+37
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you need same way to create for soon-to-added |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") | ||
|
||
package com.google.devtools.ksp.gradle | ||
|
||
import org.gradle.api.Task | ||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.model.ObjectFactory | ||
import org.gradle.api.provider.ListProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Classpath | ||
import org.gradle.api.tasks.Internal | ||
import org.jetbrains.kotlin.gradle.dsl.CompilerCommonOptions | ||
import org.jetbrains.kotlin.gradle.dsl.CompilerJsOptions | ||
import org.jetbrains.kotlin.gradle.dsl.CompilerJvmOptions | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilerExecutionStrategy | ||
import org.jetbrains.kotlin.gradle.utils.newInstance | ||
import java.io.File | ||
|
||
interface KotlinCompilerRunner { | ||
ting-yuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// TODO: Remove those properties when getting into KGP. | ||
// They should be configured by KGP. For now, they allow KSP to copy the settings from compilation task. | ||
|
||
@get:Internal | ||
val compilerExecutionStrategy: Property<KotlinCompilerExecutionStrategy> | ||
|
||
@get:Internal | ||
val useDaemonFallbackStrategy: Property<Boolean> | ||
|
||
@get:Internal | ||
val kotlinDaemonJvmArguments: ListProperty<String> | ||
|
||
@get:Classpath | ||
val compilerClasspath: ConfigurableFileCollection | ||
} | ||
|
||
interface KotlinJvmCompilerRunner : KotlinCompilerRunner { | ||
fun runJvmCompilerAsync( | ||
options: CompilerJvmOptions, | ||
freeArgs: List<String>, | ||
sources: List<File>, | ||
commonSources: List<File>, | ||
friendPaths: List<File>, | ||
libraries: List<File>, | ||
destination: File | ||
) | ||
} | ||
|
||
interface KotlinJsCompilerRunner : KotlinCompilerRunner { | ||
fun runJsCompilerAsync( | ||
options: CompilerJsOptions, | ||
freeArgs: List<String>, | ||
sources: List<File>, | ||
commonSources: List<File>, | ||
friendPaths: List<File>, | ||
libraries: List<File>, | ||
destination: File | ||
) | ||
} | ||
|
||
interface KotlinMetadataCompilerRunner : KotlinCompilerRunner { | ||
fun runMetadataCompilerAsync( | ||
options: CompilerCommonOptions, | ||
freeArgs: List<String>, | ||
sources: List<File>, | ||
commonSources: List<File>, | ||
friendPaths: List<File>, | ||
libraries: List<File>, | ||
destination: File | ||
) | ||
} | ||
|
||
interface KotlinNativeCompilerRunner : KotlinCompilerRunner { | ||
fun runNativeCompilerAsync( | ||
options: CompilerCommonOptions, | ||
freeArgs: List<String>, | ||
sources: List<File>, | ||
commonSources: List<File>, | ||
friendPaths: List<File>, | ||
libraries: List<File>, | ||
destination: File, | ||
target: String | ||
) | ||
} | ||
|
||
// TODO: Maybe move those functions into proper KGP class when getting into KGP. | ||
|
||
// TODO: Remove objectFactory when getting into KGP. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think KGP or some Kotlin library should provide method to create compiler runners for specific platforms. It could be useful for other build tools as well. Would be nice to open an issue. |
||
fun createKotlinJvmCompilerRunner( | ||
task: Task, | ||
objectFactory: ObjectFactory, | ||
): KotlinJvmCompilerRunner { | ||
return objectFactory.newInstance<KotlinJvmCompilerRunnerImpl>(task) | ||
} | ||
|
||
// TODO: Remove objectFactory when getting into KGP. | ||
fun createKotlinJsCompilerRunner( | ||
task: Task, | ||
objectFactory: ObjectFactory, | ||
ting-yuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
): KotlinJsCompilerRunner { | ||
return objectFactory.newInstance<KotlinJsCompilerRunnerImpl>(task) | ||
} | ||
|
||
// TODO: Remove objectFactory when getting into KGP. | ||
fun createKotlinMetadataCompilerRunner( | ||
task: Task, | ||
objectFactory: ObjectFactory, | ||
): KotlinMetadataCompilerRunner { | ||
return objectFactory.newInstance<KotlinMetadataCompilerRunnerImpl>(task) | ||
} | ||
|
||
// TODO: Remove objectFactory when getting into KGP. | ||
fun createKotlinNativeCompilerRunner( | ||
task: Task, | ||
objectFactory: ObjectFactory, | ||
): KotlinNativeCompilerRunner { | ||
return objectFactory.newInstance<KotlinNativeCompilerRunnerImpl>(task) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KGP has
compileOnly
dependency on this library as all classes should come fromkotlin-compiler-embeddable
on runtime. Probably you should do the same