Skip to content

Commit 38a5ddd

Browse files
authored
Remove gtest during build (#251)
* Remove gtest during build Clarify outputs for async-profiler checkout * Hook gtest to the test command * Add git's safe directory option This avoids ownership issues in builds
1 parent 9d5a5b1 commit 38a5ddd

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

ddprof-lib/build.gradle

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {
265268
def 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") {
386426
def 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")

ddprof-lib/gtest/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ tasks.whenTaskAdded { task ->
199199
}
200200

201201
inputs.files binary
202-
outputs.upToDateWhen {true}
202+
// Test tasks should run every time the test command is run
203+
outputs.upToDateWhen { false }
203204
}
204205

205206
def compileTask = tasks.findByName("compileGtest${config.name.capitalize()}_${testName}")

ddprof-test/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,11 @@ gradle.projectsEvaluated {
120120
if (testTask && assembleTask) {
121121
assembleTask.dependsOn testTask
122122
}
123+
124+
// Hook C++ gtest tasks to run as part of the corresponding Java test tasks
125+
def gtestTask = project(':ddprof-lib:gtest').tasks.findByName("gtest${it.capitalize()}")
126+
if (testTask && gtestTask) {
127+
testTask.dependsOn gtestTask
128+
}
123129
}
124130
}

0 commit comments

Comments
 (0)