in plugin-bazel/src/main/kotlin/org/jetbrains/bazel/jvm/run/ScriptPathBeforeRunTaskProvider.kt [58:99]
override fun executeTask(
context: DataContext,
configuration: RunConfiguration,
environment: ExecutionEnvironment,
task: Task,
): Boolean {
// Skip for running with coverage, in which case SCRIPT_PATH_KEY is not set
val scriptPathRef: Ref<Path>? = environment.getCopyableUserData(SCRIPT_PATH_KEY)
val runConfiguration = environment.runProfile as BazelRunConfiguration
val isDebug = environment.executor is DefaultDebugExecutor
val project = environment.project
val scriptPath = scriptPathRef?.let { createTempScriptFile() }
val status =
try {
val buildTargetTask = if (scriptPath != null) {
ScriptPathBuildTargetTask(runConfiguration, environment, scriptPath, isDebug)
} else {
/**
* scriptPath is null when running tests without debug, which indicates that we should build but not pass --script_path
* because --script_path screws up test result caching, but we still want diagnostics if the build fails
*/
DefaultBuildTargetTask
}
// runBlocking instead of runBlockingCancellable because before run tasks aren't cancellable
runBlocking {
runBuildTargetTask(
runConfiguration.targets,
project,
isDebug,
buildTargetTask,
)
}
} catch (_: CancellationException) {
return false
}
if (status == BazelStatus.SUCCESS) {
scriptPathRef?.set(scriptPath)
return true
} else {
return false
}
}