Hi,
I’ve had a good look around, and I don’t think my problem is specific to native, but, here goes.
I might be trying to solve the wrong problem, and I’ve only started using Gradle a few weeks ago, so I might be making some obvious mistakes.
I’ve trimmed the build script below a little, but it should still contain everything relevant.
I’m targeting both windows and linux, which generates a whole lot of tasks (on top of having two build types), and I’m trying to hide the tasks that aren’t buildable on the current operating system.
I could alternatively not target the platform I’m not running on, but with only one platform in play, Gradle removes it from the task names, and also the output file paths and I’d rather have that (I know I can modify the shared and static library file paths myself, which is the only other option I can see).
apply plugin: 'cpp'
apply plugin: 'google-test'
model {
components {
MyProj(NativeLibrarySpec) {
targetPlatform 'windows_x64'
targetPlatform 'linux_x64'
}
}
testSuites {
MyProjTest {
}
}
binaries {
withType(NativeBinarySpec) { binary ->
if (binary.buildable == false) {
// binary.name would be something like the following here:
// - linux_x64DebugSharedLibrary
// - linux_x64ReleaseGoogleTestExe
// The combination will create something like:
// - MyProjLinux_x64DebugSharedLibrary
// - MyProjTestLinux_x64ReleaseGoogleTestExe
def lifeCycleTaskName = "${binary.component.name}${binary.name.capitalize()}"
project.tasks.matching { it.name == lifeCycleTaskName }.all {
enabled = false
group = null
}
binary.tasks.all {
enabled = false
group = null
}
}
}
}
}
I tried to find the lifecycle tasks automatically by their dependencies (assuming that’s how they reference the compile/link/create tasks?) but I couldn’t find them. Would appreciate any insight here. So instead I’m working it out with strings.
This produces the gradle tasks output:
:MyProj:tasks
------------------------------------------------------------
All tasks runnable from project :MyProj
------------------------------------------------------------
Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
clean - Deletes the build directory.
MyProjTestWindows_x64DebugGoogleTestExe - Assembles google test exe 'MyProjTest:windows_x64:debug:googleTestExe'.
MyProjTestWindows_x64ReleaseGoogleTestExe - Assembles google test exe 'MyProjTest:windows_x64:release:googleTestExe'.
MyProjWindows_x64DebugSharedLibrary - Assembles shared library 'MyProj:windows_x64:debug:sharedLibrary'.
MyProjWindows_x64DebugStaticLibrary - Assembles static library 'MyProj:windows_x64:debug:staticLibrary'.
MyProjWindows_x64ReleaseSharedLibrary - Assembles shared library 'MyProj:windows_x64:release:sharedLibrary'.
MyProjWindows_x64ReleaseStaticLibrary - Assembles static library 'MyProj:windows_x64:release:staticLibrary'.
installMyProjTestWindows_x64DebugGoogleTestExe - Installs a development image of google test exe 'MyProjTest:windows_x64:debug:googleTestExe'
installMyProjTestWindows_x64ReleaseGoogleTestExe - Installs a development image of google test exe 'MyProjTest:windows_x64:release:googleTestExe'
Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in project ':MyProj'.
components - Displays the components produced by project ':MyProj'. [incubating]
dependencies - Displays all dependencies declared in project ':MyProj'.
dependencyInsight - Displays the insight into a specific dependency in project ':MyProj'.
help - Displays a help message.
model - Displays the configuration model of project ':MyProj'. [incubating]
projects - Displays the sub-projects of project ':MyProj'.
properties - Displays the properties of project ':MyProj'.
tasks - Displays the tasks runnable from project ':MyProj'.
Verification tasks
------------------
check - Runs all checks.
Other tasks
-----------
MyProjLinux_x64DebugSharedLibrary - Assembles shared library 'MyProj:linux_x64:debug:sharedLibrary'.
MyProjLinux_x64DebugStaticLibrary - Assembles static library 'MyProj:linux_x64:debug:staticLibrary'.
MyProjLinux_x64ReleaseSharedLibrary - Assembles shared library 'MyProj:linux_x64:release:sharedLibrary'.
MyProjLinux_x64ReleaseStaticLibrary - Assembles static library 'MyProj:linux_x64:release:staticLibrary'.
runMyProjTestLinux_x64DebugGoogleTestExe - Runs the google test exe 'MyProjTest:linux_x64:debug:googleTestExe'
runMyProjTestLinux_x64ReleaseGoogleTestExe - Runs the google test exe 'MyProjTest:linux_x64:release:googleTestExe'
Obviously, that hasn’t hidden all of the tasks in the way that I’d want, but I remember reading something about group = null
not working if the task is referenced, but I can’t find what’s referencing those either (I’ve had the same problem with other tasks not shown here, but not relevant to this question).
I’m trying to work out whether I’m approaching this problem the wrong way to begin with, or whether, if I’m on the right track, if there’s any way to find out what’s preventing those tasks in ‘Other’ from being hidden completely?
Many thanks,
Phil