diff --git a/ddprof-lib/build.gradle b/ddprof-lib/build.gradle index 74dfd7c92..275c4e313 100644 --- a/ddprof-lib/build.gradle +++ b/ddprof-lib/build.gradle @@ -113,6 +113,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 def debugFile = getDebugFilePath(config) @@ -265,7 +268,34 @@ 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 { + // 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..." @@ -277,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 { @@ -336,6 +373,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 +426,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 +687,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") diff --git a/ddprof-lib/gtest/build.gradle b/ddprof-lib/gtest/build.gradle index d2604ff84..80308f018 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 9d2fa38c7..9952619e1 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