From f021c4f9965ca126530b495f36fe0c9365fe23cd Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Tue, 7 May 2024 22:20:51 +0600 Subject: [PATCH] cd: use dart tar archive for creating tar file --- cli/commands/build/linux.dart | 38 ++++++++++++++++++++++++----------- pubspec.lock | 14 +++---------- pubspec.yaml | 1 + 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/cli/commands/build/linux.dart b/cli/commands/build/linux.dart index 0ba895ed..8ada6503 100644 --- a/cli/commands/build/linux.dart +++ b/cli/commands/build/linux.dart @@ -5,6 +5,7 @@ import 'package:io/io.dart'; import 'package:args/command_runner.dart'; import 'package:intl/intl.dart'; import 'package:path/path.dart'; +import 'package:archive/archive.dart'; import '../../core/env.dart'; import 'common.dart'; @@ -48,26 +49,39 @@ class LinuxBuildCommand extends Command with BuildCommandCommonSteps { final bundleDirPath = join(cwd.path, "build", "linux", "x64", "release", "bundle"); - final tarPath = join( + final tarFile = File(join( cwd.path, - "build", + "dist", "spotube-linux-" "${CliEnv.channel == BuildChannel.nightly ? "nightly" : versionWithoutBuildNumber}" "-x86_64.tar.xz", - ); + )); await copyPath(bundleDirPath, tempDir); - - await shell.run( - """ - cp ${join(cwd.path, "linux", "spotube.desktop")} $tempDir - cp ${join(cwd.path, "linux", "com.github.KRTirtho.Spotube.appdata.xml")} $tempDir - cp ${join(cwd.path, "assets", "spotube-logo.png")} $tempDir - tar -cJf $tarPath -C $tempDir . - """, + await copyPath(join(cwd.path, "linux", "spotube.desktop"), tempDir); + await copyPath( + join(cwd.path, "linux", "com.github.KRTirtho.Spotube.appdata.xml"), + tempDir, ); + await copyPath(join(cwd.path, "assets", "spotube-logo.png"), tempDir); - await File(tarPath).copy(join(cwd.path, "dist")); + final archive = Archive(); + + for (final entity in Directory(tempDir).listSync(recursive: true)) { + if (entity is File) { + final fileRelPath = relative(entity.path, from: tempDir); + final file = File(entity.path); + final fileData = file.readAsBytesSync(); + archive.addFile(ArchiveFile(fileRelPath, fileData.length, fileData)); + } + } + + // convert to tar.xz + final tarEncoder = TarEncoder(); + final xzEncoder = XZEncoder(); + final tarXzData = xzEncoder.encode(tarEncoder.encode(archive)); + + await tarFile.writeAsBytes(tarXzData); final ogDeb = File( join( diff --git a/pubspec.lock b/pubspec.lock index 192bac0f..20166a3d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -42,13 +42,13 @@ packages: source: hosted version: "4.0.1" archive: - dependency: transitive + dependency: "direct dev" description: name: archive - sha256: "22600aa1e926be775fa5fe7e6894e7fb3df9efda8891c73f70fb3262399a432d" + sha256: ecf4273855368121b1caed0d10d4513c7241dfc813f7d3c8933b36622ae9b265 url: "https://pub.dev" source: hosted - version: "3.4.10" + version: "3.5.1" args: dependency: "direct main" description: @@ -1702,14 +1702,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.8" - pointycastle: - dependency: transitive - description: - name: pointycastle - sha256: "70fe966348fe08c34bf929582f1d8247d9d9408130723206472b4687227e4333" - url: "https://pub.dev" - source: hosted - version: "3.8.0" pool: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 7435e077..fae2d946 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -147,6 +147,7 @@ dev_dependencies: process_run: ^0.14.2 xml: ^6.5.0 io: ^1.0.4 + archive: ^3.5.1 dependency_overrides: uuid: ^4.4.0