1+ import { path7za } from "7zip-bin"
2+ import { appBuilderPath } from "app-builder-bin"
13import BluebirdPromise from "bluebird-lst"
2- import { Arch , debug , exec , serializeToYaml } from "builder-util"
4+ import { Arch , log , serializeToYaml , isEnvTrue , spawn } from "builder-util"
35import { UUID } from "builder-util-runtime"
4- import { copyDir , copyOrLinkFile , unlinkIfExists , copyDirUsingHardLinks , USE_HARD_LINKS } from "builder-util/out/fs"
6+ import { copyOrLinkFile , unlinkIfExists } from "builder-util/out/fs"
57import * as ejs from "ejs"
6- import { ensureDir , readFile , symlink , writeFile } from "fs-extra-p"
8+ import { ensureDir , outputFile , readFile , symlink , writeFile } from "fs-extra-p"
79import { Lazy } from "lazy-val"
810import * as path from "path"
911import { AppImageOptions } from ".."
1012import { Target } from "../core"
11- import { LinuxPackager , toAppImageOrSnapArch } from "../linuxPackager"
13+ import { LinuxPackager } from "../linuxPackager"
1214import { getAppUpdatePublishConfiguration } from "../publish/PublishManager"
1315import { getTemplatePath } from "../util/pathManager"
1416import { appendBlockmap } from "./differentialUpdateInfoBuilder"
1517import { LinuxTargetHelper } from "./LinuxTargetHelper"
1618import { createStageDir } from "./targetUtil"
17- import { getAppImage } from "./tools"
1819
1920const appRunTemplate = new Lazy < ( data : any ) => string > ( async ( ) => {
2021 return ejs . compile ( await readFile ( path . join ( getTemplatePath ( "linux" ) , "AppRun.sh" ) , "utf-8" ) )
@@ -46,14 +47,11 @@ export default class AppImageTarget extends Target {
4647
4748 // pax doesn't like dir with leading dot (e.g. `.__appimage`)
4849 const stageDir = await createStageDir ( this , packager , arch )
49- const appInStageDir = stageDir . getTempFile ( "app" )
50- await copyDirUsingHardLinks ( appOutDir , appInStageDir )
51-
5250 const resourceName = `appimagekit-${ this . packager . executableName } `
5351 const installIcons = await this . copyIcons ( stageDir . dir , resourceName )
5452
5553 const finalDesktopFilename = `${ this . packager . executableName } .desktop`
56- await BluebirdPromise . all ( [
54+ await Promise . all ( [
5755 unlinkIfExists ( artifactPath ) ,
5856 writeFile ( stageDir . getTempFile ( "/AppRun" ) , ( await appRunTemplate . value ) ( {
5957 systemIntegration : this . options . systemIntegration || "ask" ,
@@ -72,49 +70,29 @@ export default class AppImageTarget extends Target {
7270 throw new Error ( "Icon is not provided" )
7371 }
7472
75- //noinspection SpellCheckingInspection
76- const vendorDir = await getAppImage ( )
77-
7873 if ( this . packager . packagerOptions . effectiveOptionComputed != null && await this . packager . packagerOptions . effectiveOptionComputed ( { desktop : await this . desktopEntry . value } ) ) {
7974 return
8075 }
8176
82- if ( arch === Arch . x64 || arch === Arch . ia32 ) {
83- await copyDir ( path . join ( vendorDir , "lib" , arch === Arch . x64 ? "x86_64-linux-gnu" : "i386-linux-gnu" ) , stageDir . getTempFile ( "usr/lib" ) , {
84- isUseHardLink : USE_HARD_LINKS ,
85- } )
86- }
87-
8877 const publishConfig = await getAppUpdatePublishConfiguration ( packager , arch )
8978 if ( publishConfig != null ) {
90- await writeFile ( path . join ( packager . getResourcesDir ( appInStageDir ) , "app-update.yml" ) , serializeToYaml ( publishConfig ) )
79+ await outputFile ( path . join ( packager . getResourcesDir ( stageDir . getTempFile ( "app" ) ) , "app-update.yml" ) , serializeToYaml ( publishConfig ) )
9180 }
9281
93- const vendorToolDir = path . join ( vendorDir , process . platform === "darwin" ? "darwin" : `linux-${ process . arch } ` )
94- // default gzip compression - 51.9, xz - 50.4 difference is negligible, start time - well, it seems, a little bit longer (but on Parallels VM on external SSD disk)
95- // so, to be decided later, is it worth to use xz by default
96- const args = [
97- "--runtime-file" , path . join ( vendorDir , `runtime-${ ( archToRuntimeName ( arch ) ) } ` ) ,
98- "--no-appstream" ,
99- ]
100- if ( debug . enabled ) {
101- args . push ( "--verbose" )
102- }
82+ const args = [ "appimage" , "--stage" , stageDir . dir , "--arch" , Arch [ arch ] , "--output" , artifactPath , "--app" , appOutDir ]
10383 if ( packager . compression === "maximum" ) {
104- args . push ( "--comp" , "xz" )
84+ args . push ( "--compression" , "xz" )
85+ }
86+ if ( log . isDebugEnabled && ! isEnvTrue ( process . env . ELECTRON_BUILDER_REMOVE_STAGE_EVEN_IF_DEBUG ) ) {
87+ args . push ( "--no-remove-stage" )
10588 }
106- args . push ( stageDir . dir , artifactPath )
107- await exec ( path . join ( vendorToolDir , "appimagetool" ) , args , {
89+ await spawn ( appBuilderPath , args , {
10890 env : {
10991 ...process . env ,
110- PATH : `${ vendorToolDir } :${ process . env . PATH } ` ,
111- // to avoid detection by appimagetool (see extract_arch_from_text about expected arch names)
112- ARCH : toAppImageOrSnapArch ( arch ) ,
113- }
92+ SZA_PATH : path7za ,
93+ } ,
11494 } )
11595
116- await stageDir . cleanup ( )
117-
11896 const updateInfo = await appendBlockmap ( artifactPath )
11997 packager . info . dispatchArtifactCreated ( {
12098 file : artifactPath ,
@@ -154,23 +132,4 @@ export default class AppImageTarget extends Target {
154132 }
155133 return installIcons
156134 }
157- }
158-
159- function archToRuntimeName ( arch : Arch ) {
160- switch ( arch ) {
161- case Arch . armv7l :
162- return "armv7"
163-
164- case Arch . arm64 :
165- return "arm64"
166-
167- case Arch . ia32 :
168- return "i686"
169-
170- case Arch . x64 :
171- return "x86_64"
172-
173- default :
174- throw new Error ( `AppImage for arch ${ Arch [ arch ] } not supported` )
175- }
176135}
0 commit comments