From dcad2cb789a2be475cc0a959ea07a375f27977ab Mon Sep 17 00:00:00 2001 From: Mikhail Filippov Date: Mon, 1 Apr 2024 19:57:54 +0400 Subject: [PATCH] RIDER-110364 Do not dump all json-based IDEA process output into build logs. GitOrigin-RevId: e4e5eae4d8314f7fc7f70456c82da44ed451cf66 --- .../jetbrains/intellij/build/io/process.kt | 31 ++++++++----------- .../intellij/build/impl/BuildHelper.kt | 2 +- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/build/tasks/src/org/jetbrains/intellij/build/io/process.kt b/build/tasks/src/org/jetbrains/intellij/build/io/process.kt index cf11c863e6b3..b849ff122b90 100644 --- a/build/tasks/src/org/jetbrains/intellij/build/io/process.kt +++ b/build/tasks/src/org/jetbrains/intellij/build/io/process.kt @@ -33,13 +33,13 @@ suspend fun runJava(mainClass: String, workingDir: Path? = null, customOutputFile: Path? = null, onError: (() -> Unit)? = null) { - val jvmArgsWithJson = jvmArgs + "-Dintellij.log.to.json.stdout=true" @Suppress("NAME_SHADOWING") val workingDir = workingDir ?: Path.of(System.getProperty("user.dir")) + val useJsonOutput = jvmArgs.any { arg -> arg == "-Dintellij.log.to.json.stdout=true" } == true spanBuilder("runJava") .setAttribute("mainClass", mainClass) .setAttribute(AttributeKey.stringArrayKey("args"), args) - .setAttribute(AttributeKey.stringArrayKey("jvmArgs"), jvmArgsWithJson) + .setAttribute(AttributeKey.stringArrayKey("jvmArgs"), jvmArgs) .setAttribute("workingDir", "$workingDir") .setAttribute("timeoutMillis", timeout.toString()) .useWithScope(Dispatchers.IO) { span -> @@ -50,7 +50,7 @@ suspend fun runJava(mainClass: String, val classpathFile = Files.createTempFile("classpath-", ".txt").also(toDelete::add) val classPathStringBuilder = createClassPathFile(classPath, classpathFile) val processArgs = createProcessArgs(javaExe = javaExe, - jvmArgs = jvmArgsWithJson, + jvmArgs = jvmArgs, classpathFile = classpathFile, mainClass = mainClass, args = args) @@ -73,14 +73,16 @@ suspend fun runJava(mainClass: String, span.setAttribute("output", runCatching { Files.readString(outputFile) }.getOrNull() ?: "output file doesn't exist") val errorOutput = runCatching { Files.readString(errorOutputFile) }.getOrNull() val output = runCatching { Files.readString(outputFile) }.getOrNull() + val errorMessage = StringBuilder("Cannot execute $mainClass: $reason\n${processArgs.joinToString(separator = " ")}" + + "\n--- error output ---\n" + + "$errorOutput") + if (!useJsonOutput) { + errorMessage.append("\n--- output ---\n$output\n") + } + errorMessage.append("\n--- ---") span.setAttribute("errorOutput", errorOutput ?: "error output file doesn't exist") onError?.invoke() - throw RuntimeException("Cannot execute $mainClass: $reason\n${processArgs.joinToString(separator = " ")}" + - "\n--- error output ---\n" + - "$errorOutput" + - "\n--- output ---" + - "$output\n" + - "\n--- ---") + throw RuntimeException(errorMessage.toString()) } try { @@ -107,7 +109,7 @@ suspend fun runJava(mainClass: String, javaRunFailed("exitCode=$exitCode") } - if (customOutputFile == null) { + if (useJsonOutput) { checkOutput(outputFile = outputFile, span = span, errorConsumer = ::javaRunFailed) } } @@ -128,7 +130,7 @@ private fun checkOutput(outputFile: Path, span: Span, errorConsumer: (String) -> Files.readString(outputFile, Charsets.ISO_8859_1) } } - catch (e: NoSuchFieldException) { + catch (_: NoSuchFieldException) { span.setAttribute("output", "output file doesn't exist") return } @@ -269,13 +271,6 @@ suspend fun runProcess(args: List, errorOccurred() throw RuntimeException("Process $pid finished with exitCode $exitCode)") } - - if (!inheritOut) { - checkOutput(outputFile!!, span) { - errorOccurred() - throw RuntimeException(it) - } - } } finally { process?.waitFor() diff --git a/platform/build-scripts/src/org/jetbrains/intellij/build/impl/BuildHelper.kt b/platform/build-scripts/src/org/jetbrains/intellij/build/impl/BuildHelper.kt index 77d0440eec1f..6d45f09597ad 100644 --- a/platform/build-scripts/src/org/jetbrains/intellij/build/impl/BuildHelper.kt +++ b/platform/build-scripts/src/org/jetbrains/intellij/build/impl/BuildHelper.kt @@ -76,7 +76,7 @@ suspend fun runIdea(context: CompilationContext, onError: (() -> Unit)? = null) { runJava(mainClass = mainClass, args = args, - jvmArgs = getCommandLineArgumentsForOpenPackages(context) + jvmArgs + listOf("-Dij.dir.lock.debug=true"), + jvmArgs = getCommandLineArgumentsForOpenPackages(context) + jvmArgs + listOf("-Dij.dir.lock.debug=true", "-Dintellij.log.to.json.stdout=true"), classPath = classPath, javaExe = context.stableJavaExecutable, timeout = timeout,