@@ -113,6 +113,9 @@ def createDebugLinkTask(config, linkTask, extractDebugTask) {
113113 dependsOn extractDebugTask
114114 description = ' Add debug link to the original library'
115115
116+ inputs. files linkTask, extractDebugTask
117+ outputs. file { linkTask. get(). linkedFile. get(). asFile }
118+
116119 doFirst {
117120 def sourceFile = linkTask. get(). linkedFile. get(). asFile
118121 def debugFile = getDebugFilePath(config)
@@ -265,7 +268,34 @@ tasks.register('copyExternalLibs', Copy) {
265268def cloneAPTask = tasks. register(' cloneAsyncProfiler' ) {
266269 description = ' Clones async-profiler repo if directory is missing or updates it if commit hash differs'
267270 inputs. file(" ${ rootDir} /gradle/ap-lock.properties" )
268- doFirst {
271+ outputs. dir(" ${ projectDir} /build/async-profiler" )
272+ outputs. upToDateWhen {
273+ def targetDir = file(" ${ projectDir} /build/async-profiler" )
274+ if (! targetDir. exists()) {
275+ return false
276+ }
277+ def currentCommit = " "
278+ try {
279+ new ByteArrayOutputStream (). withStream { os ->
280+ exec {
281+ workingDir targetDir. absolutePath
282+ commandLine ' git' , ' rev-parse' , ' HEAD'
283+ standardOutput = os
284+ }
285+ currentCommit = os. toString(). trim()
286+ }
287+ return currentCommit == commit_lock
288+ } catch (Exception e) {
289+ return false
290+ }
291+ }
292+ doLast {
293+ // Fix for CI environments where git detects dubious ownership
294+ exec {
295+ commandLine ' git' , ' config' , ' --global' , ' --add' , ' safe.directory' , projectDir. parentFile. absolutePath
296+ ignoreExitValue = true // Don't fail if this command fails
297+ }
298+
269299 def targetDir = file(" ${ projectDir} /build/async-profiler" )
270300 if (! targetDir. exists()) {
271301 println " Cloning missing async-profiler git subdirectory..."
@@ -277,6 +307,13 @@ def cloneAPTask = tasks.register('cloneAsyncProfiler') {
277307 commandLine ' git' , ' checkout' , commit_lock
278308 }
279309 } else {
310+ // Also fix git ownership for existing directory
311+ exec {
312+ workingDir targetDir. absolutePath
313+ commandLine ' git' , ' config' , ' --global' , ' --add' , ' safe.directory' , targetDir. absolutePath
314+ ignoreExitValue = true
315+ }
316+
280317 def currentCommit = " "
281318 new ByteArrayOutputStream (). withStream { os ->
282319 exec {
@@ -336,6 +373,9 @@ def patchStackFrame = tasks.register("patchStackFrame") {
336373 configure {
337374 dependsOn copyUpstreamFiles
338375 }
376+ inputs. files copyUpstreamFiles
377+ outputs. file(" ${ projectDir} /src/main/cpp-external/stackFrame_x64.cpp" )
378+
339379 doLast {
340380 def file = file(" ${ projectDir} /src/main/cpp-external/stackFrame_x64.cpp" )
341381 if (! file. exists()) throw new GradleException (" File not found: ${ file} " )
@@ -386,8 +426,11 @@ def patchStackFrame = tasks.register("patchStackFrame") {
386426def patchStackWalker = tasks. register(" patchStackWalker" ) {
387427 description = ' Patch stackWalker.cpp after copying'
388428 configure {
389- dependsOn copyUpstreamFiles
429+ dependsOn copyUpstreamFiles, patchStackFrame
390430 }
431+ inputs. files copyUpstreamFiles
432+ outputs. file(" ${ projectDir} /src/main/cpp-external/stackWalker.cpp" )
433+
391434 doLast {
392435 def file = file(" ${ projectDir} /src/main/cpp-external/stackWalker.cpp" )
393436 if (! file. exists()) throw new GradleException (" File not found: ${ file} " )
@@ -644,10 +687,6 @@ gradle.projectsEvaluated {
644687 copyTask. dependsOn linkTask
645688 }
646689 }
647- def gtestTask = project(' :ddprof-lib:gtest' ). tasks. findByName(" gtest${ it.capitalize()} " )
648- if (gtestTask != null ) {
649- linkTask. dependsOn gtestTask
650- }
651690 }
652691 def javadocTask = tasks. findByName(" javadoc" )
653692 def copyReleaseLibs = tasks. findByName(" copyReleaseLibs" )
0 commit comments