From 7918ebb6264f7fcd4fc932edaff73afe57bc65fa Mon Sep 17 00:00:00 2001 From: r1viollet Date: Thu, 24 Jul 2025 14:41:52 +0200 Subject: [PATCH 1/4] Remove gtest during build Clarify outputs for async-profiler checkout --- ddprof-lib/build.gradle | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/ddprof-lib/build.gradle b/ddprof-lib/build.gradle index 74dfd7c9..e2c194b6 100644 --- a/ddprof-lib/build.gradle +++ b/ddprof-lib/build.gradle @@ -112,6 +112,9 @@ def createDebugLinkTask(config, linkTask, extractDebugTask) { } dependsOn extractDebugTask description = 'Add debug link to the original library' + + inputs.files linkTask, extractDebugTask + outputs.file { linkTask.get().linkedFile.get().asFile } doFirst { def sourceFile = linkTask.get().linkedFile.get().asFile @@ -265,7 +268,28 @@ tasks.register('copyExternalLibs', Copy) { def cloneAPTask = tasks.register('cloneAsyncProfiler') { description = 'Clones async-profiler repo if directory is missing or updates it if commit hash differs' inputs.file("${rootDir}/gradle/ap-lock.properties") - doFirst { + outputs.dir("${projectDir}/build/async-profiler") + outputs.upToDateWhen { + def targetDir = file("${projectDir}/build/async-profiler") + if (!targetDir.exists()) { + return false + } + def currentCommit = "" + try { + new ByteArrayOutputStream().withStream { os -> + exec { + workingDir targetDir.absolutePath + commandLine 'git', 'rev-parse', 'HEAD' + standardOutput = os + } + currentCommit = os.toString().trim() + } + return currentCommit == commit_lock + } catch (Exception e) { + return false + } + } + doLast { def targetDir = file("${projectDir}/build/async-profiler") if (!targetDir.exists()) { println "Cloning missing async-profiler git subdirectory..." @@ -336,6 +360,9 @@ def patchStackFrame = tasks.register("patchStackFrame") { configure { dependsOn copyUpstreamFiles } + inputs.files copyUpstreamFiles + outputs.file("${projectDir}/src/main/cpp-external/stackFrame_x64.cpp") + doLast { def file = file("${projectDir}/src/main/cpp-external/stackFrame_x64.cpp") if (!file.exists()) throw new GradleException("File not found: ${file}") @@ -386,8 +413,11 @@ def patchStackFrame = tasks.register("patchStackFrame") { def patchStackWalker = tasks.register("patchStackWalker") { description = 'Patch stackWalker.cpp after copying' configure { - dependsOn copyUpstreamFiles + dependsOn copyUpstreamFiles, patchStackFrame } + inputs.files copyUpstreamFiles + outputs.file("${projectDir}/src/main/cpp-external/stackWalker.cpp") + doLast { def file = file("${projectDir}/src/main/cpp-external/stackWalker.cpp") if (!file.exists()) throw new GradleException("File not found: ${file}") @@ -644,10 +674,6 @@ gradle.projectsEvaluated { copyTask.dependsOn linkTask } } - def gtestTask = project(':ddprof-lib:gtest').tasks.findByName("gtest${it.capitalize()}") - if (gtestTask != null) { - linkTask.dependsOn gtestTask - } } def javadocTask = tasks.findByName("javadoc") def copyReleaseLibs = tasks.findByName("copyReleaseLibs") From 82afa1e1cbb82c40347aebc753de5340ee56d8e2 Mon Sep 17 00:00:00 2001 From: r1viollet Date: Thu, 24 Jul 2025 14:59:52 +0200 Subject: [PATCH 2/4] Hook gtest to the test command --- ddprof-lib/build.gradle | 6 +++--- ddprof-lib/gtest/build.gradle | 3 ++- ddprof-test/build.gradle | 6 ++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ddprof-lib/build.gradle b/ddprof-lib/build.gradle index e2c194b6..dbbd88aa 100644 --- a/ddprof-lib/build.gradle +++ b/ddprof-lib/build.gradle @@ -112,7 +112,7 @@ def createDebugLinkTask(config, linkTask, extractDebugTask) { } dependsOn extractDebugTask description = 'Add debug link to the original library' - + inputs.files linkTask, extractDebugTask outputs.file { linkTask.get().linkedFile.get().asFile } @@ -362,7 +362,7 @@ def patchStackFrame = tasks.register("patchStackFrame") { } inputs.files copyUpstreamFiles outputs.file("${projectDir}/src/main/cpp-external/stackFrame_x64.cpp") - + doLast { def file = file("${projectDir}/src/main/cpp-external/stackFrame_x64.cpp") if (!file.exists()) throw new GradleException("File not found: ${file}") @@ -417,7 +417,7 @@ def patchStackWalker = tasks.register("patchStackWalker") { } inputs.files copyUpstreamFiles outputs.file("${projectDir}/src/main/cpp-external/stackWalker.cpp") - + doLast { def file = file("${projectDir}/src/main/cpp-external/stackWalker.cpp") if (!file.exists()) throw new GradleException("File not found: ${file}") diff --git a/ddprof-lib/gtest/build.gradle b/ddprof-lib/gtest/build.gradle index d2604ff8..80308f01 100644 --- a/ddprof-lib/gtest/build.gradle +++ b/ddprof-lib/gtest/build.gradle @@ -199,7 +199,8 @@ tasks.whenTaskAdded { task -> } inputs.files binary - outputs.upToDateWhen {true} + // Test tasks should run every time the test command is run + outputs.upToDateWhen { false } } def compileTask = tasks.findByName("compileGtest${config.name.capitalize()}_${testName}") diff --git a/ddprof-test/build.gradle b/ddprof-test/build.gradle index 9d2fa38c..9952619e 100644 --- a/ddprof-test/build.gradle +++ b/ddprof-test/build.gradle @@ -120,5 +120,11 @@ gradle.projectsEvaluated { if (testTask && assembleTask) { assembleTask.dependsOn testTask } + + // Hook C++ gtest tasks to run as part of the corresponding Java test tasks + def gtestTask = project(':ddprof-lib:gtest').tasks.findByName("gtest${it.capitalize()}") + if (testTask && gtestTask) { + testTask.dependsOn gtestTask + } } } \ No newline at end of file From 8f5d37e128168d8071bec02ddb261b67bae801d4 Mon Sep 17 00:00:00 2001 From: r1viollet Date: Mon, 28 Jul 2025 09:52:22 +0200 Subject: [PATCH 3/4] Add git's safe directory option This avoids ownership issues in builds --- ddprof-lib/build.gradle | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ddprof-lib/build.gradle b/ddprof-lib/build.gradle index dbbd88aa..9c5a1a86 100644 --- a/ddprof-lib/build.gradle +++ b/ddprof-lib/build.gradle @@ -290,6 +290,12 @@ def cloneAPTask = tasks.register('cloneAsyncProfiler') { } } doLast { + // Fix for CI environments where git detects dubious ownership + exec { + commandLine 'git', 'config', '--global', '--add', 'safe.directory', projectDir.parentFile.absolutePath + ignoreExitValue = true // Don't fail if this command fails + } + def targetDir = file("${projectDir}/build/async-profiler") if (!targetDir.exists()) { println "Cloning missing async-profiler git subdirectory..." @@ -301,6 +307,13 @@ def cloneAPTask = tasks.register('cloneAsyncProfiler') { commandLine 'git', 'checkout', commit_lock } } else { + // Also fix git ownership for existing directory + exec { + workingDir targetDir.absolutePath + commandLine 'git', 'config', '--global', '--add', 'safe.directory', targetDir.absolutePath + ignoreExitValue = true + } + def currentCommit = "" new ByteArrayOutputStream().withStream { os -> exec { From 5204adeabfafddd36982c99a2b88bfa90dbe4f75 Mon Sep 17 00:00:00 2001 From: r1viollet Date: Mon, 28 Jul 2025 09:56:56 +0200 Subject: [PATCH 4/4] Fix a formatting issue --- ddprof-lib/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ddprof-lib/build.gradle b/ddprof-lib/build.gradle index 9c5a1a86..275c4e31 100644 --- a/ddprof-lib/build.gradle +++ b/ddprof-lib/build.gradle @@ -295,7 +295,7 @@ def cloneAPTask = tasks.register('cloneAsyncProfiler') { commandLine 'git', 'config', '--global', '--add', 'safe.directory', projectDir.parentFile.absolutePath ignoreExitValue = true // Don't fail if this command fails } - + def targetDir = file("${projectDir}/build/async-profiler") if (!targetDir.exists()) { println "Cloning missing async-profiler git subdirectory..." @@ -313,7 +313,7 @@ def cloneAPTask = tasks.register('cloneAsyncProfiler') { commandLine 'git', 'config', '--global', '--add', 'safe.directory', targetDir.absolutePath ignoreExitValue = true } - + def currentCommit = "" new ByteArrayOutputStream().withStream { os -> exec {