Skip to content

Commit 2b7a40c

Browse files
Add createReleaseTarball task, GIT_TAG_OVERRIDE option, use tar in flake
1 parent aefc7a7 commit 2b7a40c

File tree

3 files changed

+68
-40
lines changed

3 files changed

+68
-40
lines changed

buildSrc/src/main/kotlin/plugins/generate-build-config.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ fun Task.buildConfig(debug_mode: Boolean) {
8484
)
8585

8686
buildConfig {
87-
val git_tag: String? = Command.getCurrentGitTag()
87+
val tag_override: String? = project.properties["GIT_TAG_OVERRIDE"] as String?
88+
val git_tag: String? = (tag_override ?: Command.getCurrentGitTag())?.ifBlank { null }
8889
buildConfigField("GIT_TAG", git_tag)
8990
buildConfigField("GIT_COMMIT_HASH", if (git_tag != null) null else Command.getCurrentGitCommitHash())
9091
buildConfigField("IS_DEBUG", debug_mode)

desktopApp/build.gradle.kts

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.apache.tools.ant.taskdefs.condition.Os
44
import org.gradle.internal.os.OperatingSystem
55
import org.gradle.jvm.tasks.Jar
66
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
7+
import org.jetbrains.compose.desktop.application.tasks.AbstractJPackageTask
78
import plugin.spmp.SpMpDeps
89
import plugin.spmp.getDeps
910
import java.io.FileInputStream
@@ -17,10 +18,6 @@ plugins {
1718
id("org.jetbrains.compose")
1819
}
1920

20-
enum class OS {
21-
LINUX, WINDOWS;
22-
}
23-
2421
val local_properties_path: String = "local.properties"
2522
val strings_file: File = rootProject.file("shared/src/commonMain/resources/assets/values/strings.xml")
2623

@@ -207,30 +204,8 @@ abstract class ActuallyPackageAppImageTask: DefaultTask() {
207204

208205
project.logger.lifecycle("Removing unneeded jars")
209206

210-
val deps: SpMpDeps = project.getDeps()
211-
val ffmpeg_version: String = deps.getVersion("org.bytedeco:ffmpeg-platform")
212-
val javacpp_version: String = ffmpeg_version.split('-', limit = 2)[1]
213-
214-
val platforms: List<String> = JarUtil.getUnneededPlatforms(is_windows = false)
215-
val jar_prefixes: List<String> = platforms.flatMap { platform ->
216-
JarUtil.getUnneededLibraries().map { library ->
217-
val version: String =
218-
when (library) {
219-
"javacpp" -> javacpp_version
220-
"ffmpeg" -> ffmpeg_version
221-
else -> throw NotImplementedError(library)
222-
}
223-
return@map "$library-$version-$platform"
224-
}
225-
}
226-
227-
for (file in dir.resolve("lib/app").listFiles().orEmpty()) {
228-
for (prefix in jar_prefixes) {
229-
if (file.name.startsWith(prefix) && file.name.endsWith(".jar")) {
230-
file.delete()
231-
project.logger.lifecycle("Removing lib/app/${file.name}")
232-
}
233-
}
207+
with (JarUtil) {
208+
dir.resolve("lib/app").removeUnneededJarsFromDir(project)
234209
}
235210
}
236211

@@ -353,6 +328,33 @@ private object JarUtil {
353328
}
354329
)
355330
}
331+
332+
fun File.removeUnneededJarsFromDir(project: Project, deps: SpMpDeps = project.getDeps()) {
333+
val ffmpeg_version: String = deps.getVersion("org.bytedeco:ffmpeg-platform")
334+
val javacpp_version: String = ffmpeg_version.split('-', limit = 2)[1]
335+
336+
val platforms: List<String> = JarUtil.getUnneededPlatforms(is_windows = false)
337+
val jar_prefixes: List<String> = platforms.flatMap { platform ->
338+
JarUtil.getUnneededLibraries().map { library ->
339+
val version: String =
340+
when (library) {
341+
"javacpp" -> javacpp_version
342+
"ffmpeg" -> ffmpeg_version
343+
else -> throw NotImplementedError(library)
344+
}
345+
return@map "$library-$version-$platform"
346+
}
347+
}
348+
349+
for (file in this.listFiles().orEmpty()) {
350+
for (prefix in jar_prefixes) {
351+
if (file.name.startsWith(prefix) && file.name.endsWith(".jar")) {
352+
file.delete()
353+
project.logger.lifecycle("Removing lib/app/${file.name}")
354+
}
355+
}
356+
}
357+
}
356358
}
357359

358360
afterEvaluate {
@@ -362,4 +364,30 @@ afterEvaluate {
362364
tasks.named<Jar>("packageReleaseUberJarForCurrentOS") {
363365
with (JarUtil) { excludeUnneededFiles() }
364366
}
367+
368+
tasks.withType<AbstractJPackageTask> {
369+
doLast {
370+
val jars_directory: File = outputs.files.singleFile.resolve("spmp/lib/app")
371+
with (JarUtil) {
372+
jars_directory.removeUnneededJarsFromDir(project)
373+
}
374+
}
375+
}
376+
}
377+
378+
tasks.register<Tar>("createReleaseTarball") {
379+
val dist_task: Task by tasks.named("createReleaseDistributable")
380+
val dist_directory: File = dist_task.outputs.files.singleFile
381+
dependsOn(dist_task)
382+
383+
val platform: String =
384+
if (Os.isFamily(Os.FAMILY_WINDOWS)) "windows-x86_64"
385+
else "linux-x86_64"
386+
387+
into("/") {
388+
from(dist_directory)
389+
}
390+
391+
archiveFileName = "spmp-v${getString("version_string")}-$platform.tar.gz"
392+
compression = Compression.GZIP
365393
}

flake.nix

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,18 @@
3434
let
3535
pname = "spmp";
3636
version = "0.4.0-RC2";
37-
38-
src = pkgs.fetchurl {
39-
url = "https://github.com/toasterofbread/spmp/releases/download/v${version}/spmp-v${version}-linux-x86_64.appimage";
40-
hash = "sha256-zfXyvW5jynx4yD4iOMDAGeKmolhAqiQmpMLtbKBExxs=";
41-
};
4237
in
4338
pkgs.stdenv.mkDerivation {
4439
inherit pname version;
4540

46-
src = pkgs.appimageTools.extract {
47-
inherit src pname version;
41+
src = pkgs.fetchurl {
42+
url = "https://github.com/toasterofbread/spmp/releases/download/v${version}/spmp-v${version}-linux-x86_64.tar.gz";
43+
hash = "sha256-yHTRTpYPJcYZmPwWsrYa+t8MWWtLZYCsGTJkQWCr7ho=";
4844
};
4945

5046
nativeBuildInputs = with pkgs; [
5147
autoPatchelfHook
48+
gnutar
5249
];
5350

5451
buildInputs = with pkgs; [
@@ -57,16 +54,18 @@
5754
] ++ runtime_packages;
5855

5956
installPhase = ''
60-
mkdir -p $out/appimage
61-
cp -as $src/bin $out/appimage/bin
62-
cp -as $src/lib $out/appimage/lib
57+
tar -xzf $src
58+
59+
mkdir -p $out/dist
60+
mv ./bin $out/dist/bin
61+
mv ./lib $out/dist/lib
6362
6463
lib_paths=($(echo $NIX_LDFLAGS | grep -oP '(?<=-rpath\s| -L)[^ ]+'))
6564
lib_paths_str=$(IFS=:; echo "''${lib_paths[*]}")
6665
6766
mkdir -p $out/bin
6867
echo "#!/bin/sh" >> $out/bin/spmp
69-
echo "LD_LIBRARY_PATH=\"$lib_paths_str:\$LD_LIBRARY_PATH\" $out/appimage/bin/spmp" >> $out/bin/spmp
68+
echo "LD_LIBRARY_PATH=\"$lib_paths_str:\$LD_LIBRARY_PATH\" $out/dist/bin/spmp" >> $out/bin/spmp
7069
chmod +x $out/bin/spmp
7170
'';
7271
};

0 commit comments

Comments
 (0)