Skip to content

Commit

Permalink
[feature] Add the mobileInstall request
Browse files Browse the repository at this point in the history
Merge-request: BAZEL-MR-869
Merged-by: Lev Leontev <lev.leontev@jetbrains.com>
  • Loading branch information
gottagofaster236 authored and qodana-bot committed Feb 29, 2024
1 parent 10bab42 commit a4dc63c
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ class BazelRunnerCommandBuilder internal constructor(private val bazelRunner: Ba
fun cquery() = BazelRunnerBuilder(bazelRunner, listOf("cquery"))

fun build() = BazelRunnerBuildBuilder(bazelRunner, listOf("build")).withUseBuildFlags()
fun mobileInstall() = BazelRunnerBuildBuilder(bazelRunner, listOf("mobile-install")).withUseBuildFlags()
fun test() = BazelRunnerBuildBuilder(bazelRunner, listOf("test")).withUseBuildFlags()
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ object BazelFlag {
@JvmStatic fun experimentalGoogleLegacyApi(): String =
flag("experimental_google_legacy_api")

@JvmStatic fun device(device: String): String =
arg("device", device)

@JvmStatic fun start(startType: String): String =
arg("start", startType)

private fun arg(name: String, value: String) =
String.format("--%s=%s", name, value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ public interface BazelBuildServer {

@JsonRequest("buildTarget/runWithDebug")
public fun buildTargetRunWithDebug(params: RunWithDebugParams): CompletableFuture<RunResult>

@JsonRequest("buildTarget/mobileInstall")
public fun buildTargetMobileInstall(params: MobileInstallParams): CompletableFuture<MobileInstallResult>
}
29 changes: 29 additions & 0 deletions protocol/src/main/kotlin/org/jetbrains/bsp/MobileInstall.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.jetbrains.bsp

import ch.epfl.scala.bsp4j.BuildTargetIdentifier
import ch.epfl.scala.bsp4j.StatusCode
import com.google.gson.annotations.JsonAdapter
import org.eclipse.lsp4j.jsonrpc.json.adapters.EnumTypeAdapter

/**
* See [mobile-install docs](https://bazel.build/docs/user-manual#start)
*/
@JsonAdapter(EnumTypeAdapter.Factory::class)
public enum class MobileInstallStartType(public val value: Int) {
NO(1),
COLD(2),
WARM(3),
DEBUG(4),
}

public data class MobileInstallParams(
val target: BuildTargetIdentifier,
val originId: String,
val targetDeviceSerialNumber: String,
val startType: MobileInstallStartType,
)

public data class MobileInstallResult(
val statusCode: StatusCode,
var originId: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import ch.epfl.scala.bsp4j.TestResult
import ch.epfl.scala.bsp4j.WorkspaceBuildTargetsResult
import org.eclipse.lsp4j.jsonrpc.CancelChecker
import org.jetbrains.bsp.BazelBuildServer
import org.jetbrains.bsp.MobileInstallParams
import org.jetbrains.bsp.MobileInstallResult
import org.jetbrains.bsp.RunWithDebugParams
import org.jetbrains.bsp.WorkspaceDirectoriesResult
import org.jetbrains.bsp.WorkspaceInvalidTargetsResult
Expand Down Expand Up @@ -215,6 +217,18 @@ class BspServerApi(private val bazelServicesBuilder: (BuildClient) -> BazelServi
)
}

override fun buildTargetMobileInstall(params: MobileInstallParams): CompletableFuture<MobileInstallResult> {
return runner.handleRequest(
"buildTargetMobileInstall",
{ cancelChecker: CancelChecker, params: MobileInstallParams ->
executeService.mobileInstall(
cancelChecker, params,
)
},
params,
)
}

override fun buildTargetCleanCache(params: CleanCacheParams): CompletableFuture<CleanCacheResult> {
return runner.handleRequest("buildTargetCleanCache", { cancelChecker: CancelChecker, params: CleanCacheParams ->
executeService.clean(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import org.eclipse.lsp4j.jsonrpc.CancelChecker
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError
import org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode
import org.jetbrains.bsp.MobileInstallParams
import org.jetbrains.bsp.MobileInstallResult
import org.jetbrains.bsp.MobileInstallStartType
import org.jetbrains.bsp.RunWithDebugParams
import org.jetbrains.bsp.bazel.bazelrunner.BazelProcessResult
import org.jetbrains.bsp.bazel.bazelrunner.BazelRunner
Expand Down Expand Up @@ -132,6 +135,28 @@ class ExecuteService(
return debugRunner.runWithDebug(cancelChecker, params, singleModule)
}

fun mobileInstall(cancelChecker: CancelChecker, params: MobileInstallParams): MobileInstallResult {
val targets = selectTargets(cancelChecker, listOf(params.target))
val bspId = targets.singleOrResponseError(params.target)

val startType = when (params.startType) {
MobileInstallStartType.NO -> "no"
MobileInstallStartType.COLD -> "cold"
MobileInstallStartType.WARM -> "warm"
MobileInstallStartType.DEBUG -> "debug"
}

val bazelProcessResult = bazelRunner.commandBuilder()
.mobileInstall()
.withArgument(BspMappings.toBspUri(bspId))
.withArgument(BazelFlag.device(params.targetDeviceSerialNumber))
.withArgument(BazelFlag.start(startType))
.withFlag(BazelFlag.color(true))
.executeBazelCommand(params.originId)
.waitAndGetResult(cancelChecker)
return MobileInstallResult(bazelProcessResult.statusCode, params.originId)
}

@Suppress("UNUSED_PARAMETER") // params is used by BspRequestsRunner.handleRequest
fun clean(cancelChecker: CancelChecker, params: CleanCacheParams?): CleanCacheResult {
withBepServer { bepReader ->
Expand Down

0 comments on commit a4dc63c

Please sign in to comment.