Skip to content

Commit a35d875

Browse files
committed
Fix test project generation on Windows: no backslashes in strings.
1 parent 025c329 commit a35d875

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

plugin/src/test/groovy/com/nishtahir/SimpleCargoProject.groovy

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,31 @@ class SimpleCargoProject {
4141
}
4242

4343
def writeProject() {
44-
def cargoModule = this.class.classLoader.getResource("rust/Cargo.toml").path
45-
cargoModule = new File(cargoModule).parent
44+
def cargoModuleFile = new File(this.class.classLoader.getResource("rust/Cargo.toml").path).parentFile
45+
def targetDirectoryFile = new File(cargoModuleFile.parentFile, "target")
46+
47+
// On Windows, path components are backslash-separated. We need to
48+
// express the path as Groovy source, which means backslashes need to be
49+
// escaped. The easiest way is to replace backslashes with forward
50+
// slashes.
51+
def module = cargoModuleFile.path.replace("\\", "/")
52+
def targetDirectory = targetDirectoryFile.path.replace("\\", "/")
4653

4754
def targetStrings = targets.collect({"\"${it}\"" }).join(", ")
4855

4956
file('app/build.gradle') << """
5057
cargo {
51-
module = "${cargoModule}"
52-
targetDirectory = "${cargoModule}/../target"
58+
module = "${module}"
59+
targetDirectory = "${targetDirectory}"
5360
targets = [${targetStrings}]
5461
libname = "rust"
5562
}
5663
""".stripIndent()
5764

5865
file('library/build.gradle') << """
5966
cargo {
60-
module = "${cargoModule}"
61-
targetDirectory = "${cargoModule}/../target"
67+
module = "${module}"
68+
targetDirectory = "${targetDirectory}"
6269
targets = [${targetStrings}]
6370
libname = "rust"
6471
}

0 commit comments

Comments
 (0)