Skip to content

Commit 014b84a

Browse files
Merge pull request #363 from opendocument-app/conanInstallParallel
Run conan install in parallel
2 parents b3b7b86 + 18580ec commit 014b84a

File tree

7 files changed

+109
-56
lines changed

7 files changed

+109
-56
lines changed

app/build.gradle

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.apache.tools.ant.filters.ReplaceTokens
2+
13
plugins {
24
id 'com.android.application'
35
id 'com.google.gms.google-services'
@@ -10,35 +12,57 @@ android {
1012

1113
tasks.register('conanProfile', Copy) {
1214
from "conanprofile.txt"
13-
into "build/"
15+
into project.layout.buildDirectory
16+
filter(ReplaceTokens, tokens: ["NDK_PATH": android.ndkDirectory.toString()])
17+
}
1418

15-
doLast {
16-
def file = file("build/conanprofile.txt")
17-
def content = file.text
18-
content = content.replace("<NDK_PATH>", android.ndkDirectory.toString())
19-
file.write(content)
19+
abstract class ConanInstallTask extends Exec {
20+
@Input
21+
abstract Property<String> getArch()
22+
23+
// Cannot read project.layout.buildDirectory when configuration-cache is enabled
24+
@Input
25+
abstract Property<String> getArchBuildDirPath()
26+
27+
@OutputDirectory
28+
final Provider<Directory> outputDirectory = archBuildDirPath.map { new File(it) }
29+
30+
@Override
31+
protected void exec() {
32+
commandLine(
33+
"conan", "install", ".",
34+
"--output-folder=" + archBuildDirPath.get(),
35+
"--build=missing",
36+
"--profile:host=build/conanprofile.txt",
37+
"-s", "arch=" + arch.get(),
38+
"-s", "build_type=Release",
39+
"-s", "&:build_type=RelWithDebInfo",
40+
"-s", "odrcore/*:build_type=RelWithDebInfo",
41+
)
42+
super.exec()
2043
}
2144
}
2245

23-
tasks.register('conanInstall') {
24-
dependsOn(tasks.named("conanProfile"))
25-
doFirst {
26-
["armv7", "armv8", "x86", "x86_64"].each { String arch ->
27-
exec {
28-
commandLine(
29-
"conan", "install", ".",
30-
"--output-folder=build/conan/" + arch,
31-
"--build=missing",
32-
"--profile:host=build/conanprofile.txt",
33-
"-s", "arch=" + arch,
34-
"-s", "build_type=Release",
35-
"-s", "&:build_type=RelWithDebInfo",
36-
"-s", "odrcore/*:build_type=RelWithDebInfo",
37-
)
38-
}
46+
["armv8", "armv7", "x86", "x86_64"].each { architecture ->
47+
tasks.register('conanInstall-' + architecture, ConanInstallTask) {
48+
setArch(architecture)
49+
setArchBuildDirPath(new File(project.layout.buildDirectory.get().toString(), 'conan/' + architecture).absolutePath)
50+
dependsOn(tasks.named("conanProfile"))
51+
52+
// Execute at least one conanInstall before running all three others in parallel.
53+
// Some issue with conan's local cache
54+
// @TODO: isolate and report to conan-client bugtracker
55+
if (architecture != "armv8") {
56+
dependsOn(tasks.named("conanInstall-armv8"))
3957
}
4058
}
4159
}
60+
tasks.register("conanInstall") {
61+
["armv7", "armv8", "x86", "x86_64"].each { arch ->
62+
dependsOn tasks.named('conanInstall-' + arch)
63+
}
64+
}
65+
4266
tasks.named("preBuild").configure { preBuildTask ->
4367
preBuildTask.dependsOn(tasks.named("conanInstall"))
4468
}
@@ -176,7 +200,8 @@ dependencies {
176200
// Without removing .cxx dir on cleanup, double gradle clean is erroring out.
177201
// Before removing this workaround, check if "./gradlew assembleDebug; ./gradlew clean; ./gradlew clean" works
178202
tasks.named("clean") {
203+
def dotCxxDir = layout.projectDirectory.dir(".cxx")
179204
doFirst {
180-
delete getLayout().getProjectDirectory().dir(".cxx")
205+
delete dotCxxDir
181206
}
182207
}

app/conanprofile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ compiler.cppstd=17
99
compiler.libcxx=c++_shared
1010

1111
[conf]
12-
tools.android:ndk_path=<NDK_PATH>
12+
tools.android:ndk_path=@NDK_PATH@
1313
tools.build:skip_test=True

gradle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ android.useAndroidX=true
1717
android.defaults.buildfeatures.buildconfig=true
1818
android.nonTransitiveRClass=true
1919
android.nonFinalResIds=true
20+
21+
# Enabling Gradle's configuration cache ( https://docs.gradle.org/current/userguide/configuration_cache.html ) executes some Gradle tasks in parallel.
22+
# In our case it's required to execute conanInstall's in parallel. In case of problems - disable or comment out for un-paralleled conan installs
23+
org.gradle.configuration-cache=true

gradle/wrapper/gradle-wrapper.jar

-15.9 KB
Binary file not shown.
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#Fri Jun 24 20:32:41 CEST 2022
21
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
42
distributionPath=wrapper/dists
5-
zipStorePath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

gradlew

Lines changed: 31 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 21 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)