diff --git a/bin/mac/restarter b/bin/mac/restarter deleted file mode 100755 index 692f52fce60c..000000000000 Binary files a/bin/mac/restarter and /dev/null differ diff --git a/build/dependencies/dependencies.properties b/build/dependencies/dependencies.properties index 95f51be87e72..fe65938817fa 100644 --- a/build/dependencies/dependencies.properties +++ b/build/dependencies/dependencies.properties @@ -5,4 +5,5 @@ gradleApiVersion=8.2 jdkBuild=17.0.8.1b1063.1 launcherBuild=233.7666 nsisBuild=1 +restarterBuild=233.8717 runtimeBuild=17.0.8.1b1063.1 diff --git a/platform/build-scripts/src/org/jetbrains/intellij/build/JvmArchitecture.kt b/platform/build-scripts/src/org/jetbrains/intellij/build/JvmArchitecture.kt index bac775f4259a..9dde9bac9cd9 100644 --- a/platform/build-scripts/src/org/jetbrains/intellij/build/JvmArchitecture.kt +++ b/platform/build-scripts/src/org/jetbrains/intellij/build/JvmArchitecture.kt @@ -1,17 +1,15 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -@file:Suppress("ReplaceJavaStaticMethodWithKotlinAnalog") - +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.intellij.build import com.intellij.util.system.CpuArch @Suppress("EnumEntryName") -enum class JvmArchitecture(@JvmField val fileSuffix: String, @JvmField val dirName: String) { - x64("64", "amd64"), aarch64("aarch64", "aarch64"); +enum class JvmArchitecture(@JvmField val archName: String, @JvmField val fileSuffix: String, @JvmField val dirName: String) { + x64("X86_64", "64", "amd64"), aarch64("AArch64", "aarch64", "aarch64"); companion object { @JvmField - val ALL: List = java.util.List.of(*values()) + val ALL: List = entries.toList() @JvmField val currentJvmArch: JvmArchitecture = when { diff --git a/platform/build-scripts/src/org/jetbrains/intellij/build/NativeBinaryDownloader.kt b/platform/build-scripts/src/org/jetbrains/intellij/build/NativeBinaryDownloader.kt new file mode 100644 index 000000000000..cc5c0b2d4495 --- /dev/null +++ b/platform/build-scripts/src/org/jetbrains/intellij/build/NativeBinaryDownloader.kt @@ -0,0 +1,36 @@ +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.intellij.build + +import org.jetbrains.intellij.build.dependencies.BuildDependenciesConstants.INTELLIJ_DEPENDENCIES_URL +import org.jetbrains.intellij.build.dependencies.BuildDependenciesDownloader +import java.nio.file.Path +import kotlin.io.path.isDirectory +import kotlin.io.path.isRegularFile + +object NativeBinaryDownloader { + private const val GROUP_ID = "org.jetbrains.intellij.deps" + private const val RESTARTER_ID = "restarter" + private const val PACKAGING = "tar.gz" + + /** + * Downloads and unpacks the restarter tarball and returns a path to an executable for the given platform. + */ + suspend fun downloadRestarter(context: BuildContext, os: OsFamily, arch: JvmArchitecture): Path { + val communityRoot = context.paths.communityHomeDirRoot + + val version = context.dependenciesProperties.property("restarterBuild") + val uri = BuildDependenciesDownloader.getUriForMavenArtifact(INTELLIJ_DEPENDENCIES_URL, GROUP_ID, RESTARTER_ID, version, PACKAGING) + val archiveFile = downloadFileToCacheLocation(uri.toString(), communityRoot) + val unpackedDir = BuildDependenciesDownloader.extractFileToCacheLocation(communityRoot, archiveFile) + + val platformDirName = "${os.osName}-${arch.archName}" + val platformDir = unpackedDir.resolve(platformDirName) + check(platformDir.isDirectory()) { "'${platformDir}' not found in '${archiveFile.fileName}'" } + + val executableName = if (os == OsFamily.WINDOWS) "restarter.exe" else "restarter" + val executableFile = platformDir.resolve(executableName) + check(executableFile.isRegularFile()) { "Executable '${executableName}' not found in '${platformDir}'" } + + return executableFile + } +} diff --git a/platform/build-scripts/src/org/jetbrains/intellij/build/impl/MacDistributionBuilder.kt b/platform/build-scripts/src/org/jetbrains/intellij/build/impl/MacDistributionBuilder.kt index 8d07b6707c64..28eb8246b616 100644 --- a/platform/build-scripts/src/org/jetbrains/intellij/build/impl/MacDistributionBuilder.kt +++ b/platform/build-scripts/src/org/jetbrains/intellij/build/impl/MacDistributionBuilder.kt @@ -16,10 +16,7 @@ import org.jetbrains.intellij.build.* import org.jetbrains.intellij.build.TraceManager.spanBuilder import org.jetbrains.intellij.build.impl.OsSpecificDistributionBuilder.Companion.suffix import org.jetbrains.intellij.build.impl.productInfo.* -import org.jetbrains.intellij.build.io.copyDir -import org.jetbrains.intellij.build.io.copyFile -import org.jetbrains.intellij.build.io.substituteTemplatePlaceholders -import org.jetbrains.intellij.build.io.writeNewFile +import org.jetbrains.intellij.build.io.* import java.io.File import java.nio.file.Files import java.nio.file.Path @@ -217,6 +214,7 @@ class MacDistributionBuilder(override val context: BuildContext, arch: JvmArchitecture) { val macCustomizer = customizer copyDirWithFileFilter(context.paths.communityHomeDir.resolve("bin/mac"), macDistDir.resolve("bin"), customizer.binFilesFilter) + copyFileToDir(NativeBinaryDownloader.downloadRestarter(context, OsFamily.MACOS, arch), macDistDir.resolve("bin")) copyDir(context.paths.communityHomeDir.resolve("platform/build-scripts/resources/mac/Contents"), macDistDir) val executable = context.productProperties.baseFileName diff --git a/platform/platform-impl/src/com/intellij/util/Restarter.java b/platform/platform-impl/src/com/intellij/util/Restarter.java index d2cfdc00bc58..dd1105fd2464 100644 --- a/platform/platform-impl/src/com/intellij/util/Restarter.java +++ b/platform/platform-impl/src/com/intellij/util/Restarter.java @@ -122,6 +122,7 @@ public final class Restarter { return restarter != null && Files.isExecutable(restarter) ? null : "not an executable file: " + restarter; } + @ApiStatus.Internal public static void scheduleRestart(boolean elevate, String @NotNull ... beforeRestart) throws IOException { var exitCodeVariable = EnvironmentUtil.getValue(SPECIAL_EXIT_CODE_FOR_RESTART_ENV_VAR); if (exitCodeVariable != null) { @@ -158,13 +159,7 @@ public final class Restarter { if (starter == null) throw new IOException("Starter executable not found in " + PathManager.getBinPath()); var restarter = PathManager.findBinFileWithException("restarter.exe"); - var command = new ArrayList(); - command.add(copyWhenNeeded(restarter, beforeRestart).toString()); - command.add(String.valueOf(ProcessHandle.current().pid())); - if (beforeRestart.length > 0) { - command.add(String.valueOf(beforeRestart.length)); - Collections.addAll(command, beforeRestart); - } + var command = prepareCommand(restarter, beforeRestart); if (elevate) { command.add("2"); command.add(PathManager.findBinFileWithException("launcher.exe").toString()); @@ -181,10 +176,10 @@ public final class Restarter { if (appDir == null) throw new IOException("Application bundle not found: " + PathManager.getHomePath()); var restarter = Path.of(PathManager.getBinPath(), "restarter"); - var command = new ArrayList(); - command.add(copyWhenNeeded(restarter, beforeRestart).toString()); + var command = prepareCommand(restarter, beforeRestart); + command.add("2"); + command.add("/usr/bin/open"); command.add(appDir.toString()); - Collections.addAll(command, beforeRestart); runRestarter(command); } @@ -210,6 +205,17 @@ public final class Restarter { System.setProperty(DO_NOT_LOCK_INSTALL_FOLDER_PROPERTY, "true"); } + private static List prepareCommand(Path restarter, String[] beforeRestart) throws IOException { + var command = new ArrayList(); + command.add(copyWhenNeeded(restarter, beforeRestart).toString()); + command.add(String.valueOf(ProcessHandle.current().pid())); + if (beforeRestart.length > 0) { + command.add(String.valueOf(beforeRestart.length)); + Collections.addAll(command, beforeRestart); + } + return command; + } + private static Path copyWhenNeeded(Path binFile, String[] args) throws IOException { if (SystemProperties.getBooleanProperty(DO_NOT_LOCK_INSTALL_FOLDER_PROPERTY, false) || ArrayUtil.contains(UpdateInstaller.UPDATER_MAIN_CLASS, args)) { var tempDir = Files.createDirectories(PathManager.getSystemDir().resolve("restart")); @@ -223,8 +229,9 @@ public final class Restarter { private static void runRestarter(List command) throws IOException { Logger.getInstance(Restarter.class).info("run restarter: " + command); - var processBuilder = new ProcessBuilder(command) - .directory(Path.of(SystemProperties.getUserHome()).toFile()); + var processBuilder = new ProcessBuilder(command); + processBuilder.directory(Path.of(SystemProperties.getUserHome()).toFile()); + processBuilder.environment().put("IJ_RESTARTER_LOG", PathManager.getLogDir().resolve("restarter.log").toString()); if (SystemInfo.isXWindow) setDesktopStartupId(processBuilder);