From 08eba067e95a120b34af679449acece83f1c4d40 Mon Sep 17 00:00:00 2001 From: Kr328 Date: Mon, 21 Nov 2022 18:44:20 +0800 Subject: [PATCH] Fix: fix build on windows (#2) * Fix: fix build on windows * Fix: use invariantSeparatorsPath instead * Fix: revert bump version --- .../gradle/zygote/ZygoteLoaderDecorator.kt | 18 +++++++++--------- .../kr328/gradle/zygote/tasks/ChecksumTask.kt | 2 +- .../kr328/gradle/zygote/tasks/CustomizeTask.kt | 6 +++--- .../kr328/gradle/zygote/tasks/FlattenTask.kt | 8 ++++++++ .../main/assets/customize.d/11-enforce-arch.sh | 2 +- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/gradle-plugin/src/main/java/com/github/kr328/gradle/zygote/ZygoteLoaderDecorator.kt b/gradle-plugin/src/main/java/com/github/kr328/gradle/zygote/ZygoteLoaderDecorator.kt index 1c91d8a..bcfa26a 100644 --- a/gradle-plugin/src/main/java/com/github/kr328/gradle/zygote/ZygoteLoaderDecorator.kt +++ b/gradle-plugin/src/main/java/com/github/kr328/gradle/zygote/ZygoteLoaderDecorator.kt @@ -78,7 +78,7 @@ object ZygoteLoaderDecorator { val nativeLibs = artifacts.get(InternalArtifactType.MERGED_NATIVE_LIBS) val dex = artifacts.getAll(InternalMultipleArtifactType.DEX).map { it.single() } - dependsOn(flattenAssets, generateInitialPackages, generateModuleProp, packing) + dependsOn(packing) destinationDir = buildDir.resolve("intermediates/merged_magisk/${variant.name}") @@ -103,9 +103,9 @@ object ZygoteLoaderDecorator { fromKtx(dex) { include("classes.dex") } - fromKtx(flattenAssets.get().destinationDir.asFile.resolve("assets")) - fromKtx(generateInitialPackages.get().destinationDir) - fromKtx(generateModuleProp.get().destinationDir) + fromKtx(flattenAssets.flatMap { it.destinationDir.dir("assets") }) + fromKtx(generateInitialPackages.flatMap { it.destinationDir }) + fromKtx(generateModuleProp.flatMap { it.destinationDir }) } val generateChecksum = tasks.registerKtx( @@ -122,19 +122,19 @@ object ZygoteLoaderDecorator { "generateCustomize$capitalized", CustomizeTask::class, ) { - dependsOn(mergeMagisk, generateChecksum) + dependsOn(mergeMagisk) destinationDir.set(buildDir.resolve("generated/customize_sh/${variant.name}")) customizeFiles.set(mergeMagisk.get().destinationDir.resolve("customize.d")) - checksumFiles.set(generateChecksum.get().destinationDir.get().asFile.resolve("customize.d")) + checksumFiles.set(generateChecksum.flatMap { it.destinationDir.dir("customize.d") }) } val packagingMagisk = tasks.registerKtx( "packageMagisk$capitalized", Zip::class ) { - dependsOn(mergeMagisk, generateCustomize) + dependsOn(mergeMagisk) val destinationDir = buildDir.resolve("outputs/magisk") .resolve("${variant.flavorName}") @@ -151,8 +151,8 @@ object ZygoteLoaderDecorator { isPreserveFileTimestamps = false fromKtx(mergeMagisk.get().destinationDir) - fromKtx(generateCustomize.get().destinationDir) - fromKtx(generateChecksum.get().destinationDir) + fromKtx(generateCustomize.flatMap { it.destinationDir }) + fromKtx(generateChecksum.flatMap { it.destinationDir }) } tasks.getByName("assemble$capitalized").dependsOn(packagingMagisk) diff --git a/gradle-plugin/src/main/java/com/github/kr328/gradle/zygote/tasks/ChecksumTask.kt b/gradle-plugin/src/main/java/com/github/kr328/gradle/zygote/tasks/ChecksumTask.kt index 0ecf1a1..9401cb2 100644 --- a/gradle-plugin/src/main/java/com/github/kr328/gradle/zygote/tasks/ChecksumTask.kt +++ b/gradle-plugin/src/main/java/com/github/kr328/gradle/zygote/tasks/ChecksumTask.kt @@ -22,7 +22,7 @@ abstract class ChecksumTask : DefaultTask() { val script = root.walk() .filter { it.isFile } - .map { it.relativeTo(root).path } + .map { it.relativeTo(root).invariantSeparatorsPath } .filterNot { it.startsWith("META-INF") } .sorted() .map { diff --git a/gradle-plugin/src/main/java/com/github/kr328/gradle/zygote/tasks/CustomizeTask.kt b/gradle-plugin/src/main/java/com/github/kr328/gradle/zygote/tasks/CustomizeTask.kt index 0b664e0..0fddea7 100644 --- a/gradle-plugin/src/main/java/com/github/kr328/gradle/zygote/tasks/CustomizeTask.kt +++ b/gradle-plugin/src/main/java/com/github/kr328/gradle/zygote/tasks/CustomizeTask.kt @@ -21,14 +21,14 @@ abstract class CustomizeTask : DefaultTask() { val customizes = customizeFiles.get().asFile.listFiles()?.toList() ?: emptyList() val checksums = checksumFiles.get().asFile.listFiles()?.toList() ?: emptyList() - val files = (customizes + checksums).sortedBy { it.name } + val files = (customizes + checksums).map { it.name }.sorted() val customizeText = buildString { appendLine("# Generated by ZygoteLoader. DO NOT EDIT.") appendLine() files.forEach { - appendLine("[ -f \"\$MODPATH/customize.d/${it.name}\" ] || abort \"! Part '${it.name}' not found\"") - appendLine(". \"\$MODPATH/customize.d/${it.name}\"") + appendLine("[ -f \"\$MODPATH/customize.d/$it\" ] || abort \"! Part '$it' not found\"") + appendLine(". \"\$MODPATH/customize.d/$it\"") } appendLine() appendLine("rm -rf \"\$MODPATH/customize.d\"") diff --git a/gradle-plugin/src/main/java/com/github/kr328/gradle/zygote/tasks/FlattenTask.kt b/gradle-plugin/src/main/java/com/github/kr328/gradle/zygote/tasks/FlattenTask.kt index 8cd5b9b..dbd2136 100644 --- a/gradle-plugin/src/main/java/com/github/kr328/gradle/zygote/tasks/FlattenTask.kt +++ b/gradle-plugin/src/main/java/com/github/kr328/gradle/zygote/tasks/FlattenTask.kt @@ -2,6 +2,7 @@ package com.github.kr328.gradle.zygote.tasks import com.github.kr328.gradle.zygote.util.fromKtx import com.github.kr328.gradle.zygote.util.syncKtx +import org.apache.tools.ant.filters.FixCrLfFilter import org.gradle.api.DefaultTask import org.gradle.api.file.DirectoryProperty import org.gradle.api.tasks.InputDirectory @@ -31,6 +32,13 @@ abstract class FlattenTask : DefaultTask() { .forEach { jar -> from(project.zipTree(jar)) } + + val crlf: Map = mapOf("eol" to FixCrLfFilter.CrLf.newInstance("lf")) + eachFile { + if (it.relativePath.startsWith("assets/META-INF") || it.name.endsWith(".sh")) { + it.filter(crlf, FixCrLfFilter::class.java) + } + } } } } diff --git a/runtime/src/main/assets/customize.d/11-enforce-arch.sh b/runtime/src/main/assets/customize.d/11-enforce-arch.sh index 8242cd2..7ccb9dc 100644 --- a/runtime/src/main/assets/customize.d/11-enforce-arch.sh +++ b/runtime/src/main/assets/customize.d/11-enforce-arch.sh @@ -3,4 +3,4 @@ [ "$ARCH" != "arm" ] && [ "$ARCH" != "arm64" ] && [ "$ARCH" != "x86" ] && [ "$ARCH" != "x64" ] && abort "! Unsupported platform: $ARCH" -ui_print "- Device arch: $ARCH" \ No newline at end of file +ui_print "- Device arch: $ARCH"