From d9dc08c67365eb20be0813459eb5a14b52eb3ab1 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 28 Sep 2023 22:23:34 +0200 Subject: [PATCH] [platform] using new restarter on macOS (IDEA-327235 prerequisite) GitOrigin-RevId: 1c669198cd2d7a95358de8b79c7fb4256f2b8d1c --- bin/mac/restarter | Bin 115912 -> 0 bytes build/dependencies/dependencies.properties | 1 + .../intellij/build/JvmArchitecture.kt | 10 ++--- .../intellij/build/NativeBinaryDownloader.kt | 36 ++++++++++++++++++ .../build/impl/MacDistributionBuilder.kt | 6 +-- .../src/com/intellij/util/Restarter.java | 31 +++++++++------ 6 files changed, 62 insertions(+), 22 deletions(-) delete mode 100755 bin/mac/restarter create mode 100644 platform/build-scripts/src/org/jetbrains/intellij/build/NativeBinaryDownloader.kt diff --git a/bin/mac/restarter b/bin/mac/restarter deleted file mode 100755 index 692f52fce60c50686037b1e0f2f3fa0637576701..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 115912 zcmeI5ZIBeldB=Nq59tsm*fTFaM&2DQTNDZuzevHx zh*)f%XQtV8*B%dTaunW~^(+b3N;_aX%9u6(aUyVAQ%Rk(VxpckvUNp(TJsOrB$#k0@cXRKv> zmF%7oS<>x7Su5!+dN(V*gGzvXzcp!7gOs)Mexsa|MtQX2_|5C_h|=RVXJbF8;kLL> zUe{|WK*|lt;iRu6p{|Xf+_6B;`;F5qw{lThW2J1RD66*lo_g($7(Ehhf6rwd|2U=0 zSA5%~MX#Ou^A?FJ0rq)3p0S?am$Il`Y8z_!((*blMUdaM z30KdXFZ=%ac{*OM^enw->Z7!sgL*eAy)~)>`~LCK*gO-{LA`>~i#gFk zuL$I}-;sgM+qd>_*zElV)C2p3e6~q7SzaUcuk6$>7ovV6m+C?=n|8{lDfjF| zU5FStrzqz*mg%AtyGMvCD1U|WW0cRMG(^d79LvdL?r-zT)6}2WGH84;N{kZ!PQ+`L z87~^ycy6qiBcJUmN<5D4Ghf;E_uu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tS;5xA|oZ!q#<}5)2rqNWQD6DZ zcDMfT=7pmi_vWT2rZ}f_?@m0O=j?i$c=FP6`7D(`tjcGoOk)w2Z5rkLF2gSD9NxIb z{WyBBunL-~=Vm{DUes#kkpdlbEE*%uX~bTknWi=-v|Mg5yGI|fdxaaL=lDzNtT*8F z8Pe=RuV&_JCB1B0y<)#+*gMO%QS3ip*z|rr=SdtL^XGg7kk549OgX0)Y0=rZ%x6J6 zsAtsaP2aU|K1wVS)D8my5C8!X009sH0T2KI5C8!X009sH0T2KI5C8!X009sH0T2KI z5C8!X009sH0T2KI5C8!X009sH0T2KI5C8!X009sH0T2KI5C8!X009sH0T2KI5C8!X z009vA-4j@(zW2UbzWkJ_?de@XRqbyd2DKH}Hcd2-<@OAR%&l93r7a~Mu4qFh4 z($n>qIKB||b*_K4TOZ+ewzZU~Uz_95V<_P3uFtZL-Azx5=T|xQAU(;Mqg?Tj>(8`* zDd1mDemkYPl&+xU_sJD8A>W08bQlDexM>Z8jcV0`)y_f%D`)r0%+fV4nzvjndrwNI zs%jc{Xg0I*?EFg|)3h306f@0H%1~mvQi$WnVqwwYx|ez;ynxUR z`Wk)h$3EI!soCP>;-1I;`gH8Yo7!Ja6jyzsZ}&A%JTl$&%g*a-Klt(d&z=3+*Y5t? zZ)7U}bb55U?fGY)-5Vav%xQe)kZRJ}hY$Vvli!c5`hyEkY|1RX z(wM3)eettzb^YPP%TC{U{hIaX@(b?x&;RNu4}Edn@lC(_?oU47^XmD>f04d!?pLq6 zY1iY6zWCIo^xtoL>B!gb{cNsl!vn8B^RubH{J|Z=;fIg+y!7dF&qu#|_V={K2j8#$ rrTQn|+5N4jk8~b9*!R80s;@+LJTvj>ZTE~`zasr~{x>^f3y=Oc(R#4~ 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);