Extract and use `SimpleCargoProject`.

This commit is contained in:
Nick Alexander 2022-01-11 14:38:15 -08:00 коммит произвёл Nick Alexander
Родитель 057e5fccb2
Коммит 193b9fc0c1
2 изменённых файлов: 71 добавлений и 20 удалений

Просмотреть файл

@ -20,26 +20,10 @@ class CargoBuildTest extends AbstractTest {
.build()
.writeProject()
def cargoModule = this.class.classLoader.getResource("rust/Cargo.toml").path
cargoModule = new File(cargoModule).parent
file('app/build.gradle') << """
cargo {
module = "${cargoModule}"
targetDirectory = "${cargoModule}/../target"
targets = ["x86_64"]
libname = "rust"
}
""".stripIndent()
file('library/build.gradle') << """
cargo {
module = "${cargoModule}"
targetDirectory = "${cargoModule}/../target"
targets = ["x86_64"]
libname = "rust"
}
""".stripIndent()
SimpleCargoProject.builder(temporaryFolder.root)
.withTargets(["x86_64"])
.build()
.writeProject()
when:
BuildResult buildResult = withGradleVersion(gradleVersion.version)

Просмотреть файл

@ -0,0 +1,67 @@
package com.nishtahir
class SimpleCargoProject {
File projectDir
List<String> targets
SimpleCargoProject(File projectDir, List<String> targets) {
this.projectDir = projectDir
this.targets = targets
}
static class Builder {
File projectDir
List<String> targets
Builder(File projectDir) {
this.projectDir = projectDir
}
def withTargets(targets) {
this.targets = targets
return this
}
def build() {
if (targets.isEmpty()) {
throw new IllegalStateException("No targets provided")
}
return new SimpleCargoProject(this.projectDir, this.targets)
}
}
static def builder(File projectDir) {
return new Builder(projectDir)
}
def file(String path) {
def file = new File(projectDir, path)
file.parentFile.mkdirs()
return file
}
def writeProject() {
def cargoModule = this.class.classLoader.getResource("rust/Cargo.toml").path
cargoModule = new File(cargoModule).parent
def targetStrings = targets.collect({"\"${it}\"" }).join(", ")
file('app/build.gradle') << """
cargo {
module = "${cargoModule}"
targetDirectory = "${cargoModule}/../target"
targets = [${targetStrings}]
libname = "rust"
}
""".stripIndent()
file('library/build.gradle') << """
cargo {
module = "${cargoModule}"
targetDirectory = "${cargoModule}/../target"
targets = [${targetStrings}]
libname = "rust"
}
""".stripIndent()
}
}