Skip to content

Commit c3136ad

Browse files
committed
feat(linux): be more restrictive with executable name
Closes #806
1 parent 76be355 commit c3136ad

File tree

18 files changed

+93
-70
lines changed

18 files changed

+93
-70
lines changed

.idea/dictionaries/develar.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/Options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ Linux specific build options.
147147
| desktop | <a name="LinuxBuildOptions-desktop"></a>The [Desktop file](https://developer.gnome.org/integration-guide/stable/desktop-files.html.en) entries.
148148
| compression | <a name="LinuxBuildOptions-compression"></a>*deb-only.* The compression type, one of `gz`, `bzip2`, `xz`. Defaults to `xz`.
149149
| depends | <a name="LinuxBuildOptions-depends"></a>Package dependencies. Defaults to `["libappindicator1", "libnotify-bin"]`.
150+
| executableName | <a name="LinuxBuildOptions-executableName"></a><p>The executable name. Defaults to <code>productName</code>.</p> <p>Cannot be specified per target, allowed only in the <code>.build.linux</code>.</p>
150151

151152
<a name="MacOptions"></a>
152153
### `.build.mac`

nsis-auto-updater/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"strictNullChecks": true,
1313
"noEmitHelpers": true,
1414
"noFallthroughCasesInSwitch": true,
15+
"noUnusedLocals": true,
1516
"skipLibCheck": true
1617
},
1718
"declaration": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"json8": "^0.9.2",
114114
"path-sort": "^0.1.0",
115115
"ts-babel": "^1.1.3",
116-
"tslint": "^4.0.0-dev.0",
116+
"tslint": "^4.0.0-dev.1",
117117
"typescript": "^2.1.0-dev.20161101",
118118
"validate-commit-msg": "^2.8.2",
119119
"whitespace": "^2.1.0"

src/linuxPackager.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ import { LinuxTargetHelper } from "./targets/LinuxTargetHelper"
88
import AppImageTarget from "./targets/appImage"
99
import { rename } from "fs-extra-p"
1010
import { LinuxBuildOptions } from "./options/linuxOptions"
11+
import sanitizeFileName from "sanitize-filename"
1112

1213
export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
14+
readonly executableName: string
15+
1316
constructor(info: BuildInfo) {
1417
super(info)
18+
19+
let executableName = this.platformSpecificBuildOptions.executableName
20+
this.executableName = sanitizeFileName(executableName == null ? this.appInfo.name : executableName)
1521
}
1622

1723
normalizePlatformSpecificBuildOptions(options: LinuxBuildOptions | n): LinuxBuildOptions {
@@ -64,7 +70,7 @@ export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
6470
}
6571

6672
protected postInitApp(appOutDir: string): Promise<any> {
67-
return rename(path.join(appOutDir, "electron"), path.join(appOutDir, this.appInfo.productFilename))
73+
return rename(path.join(appOutDir, "electron"), path.join(appOutDir, this.executableName))
6874
}
6975

7076
protected async packageInDistributableFormat(outDir: string, appOutDir: string, arch: Arch, targets: Array<Target>): Promise<any> {

src/options/linuxOptions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,11 @@ export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
6565
Package dependencies. Defaults to `["libappindicator1", "libnotify-bin"]`.
6666
*/
6767
readonly depends?: string[] | null
68+
69+
/*
70+
The executable name. Defaults to `productName`.
71+
72+
Cannot be specified per target, allowed only in the `.build.linux`.
73+
*/
74+
readonly executableName?: string | null
6875
}

src/publish/BintrayPublisher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class BintrayPublisher implements Publisher {
1414

1515
private readonly client: BintrayClient
1616

17-
constructor(private readonly info: BintrayOptions, private readonly version: string, private readonly options: PublishOptions = {}) {
17+
constructor(info: BintrayOptions, private readonly version: string, private readonly options: PublishOptions = {}) {
1818
let token = info.token
1919
if (isEmptyOrSpaces(token)) {
2020
token = process.env.BT_TOKEN

src/targets/LinuxTargetHelper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { readdir, outputFile, ensureDir } from "fs-extra-p"
22
import * as path from "path"
33
import { exec, debug, isEmptyOrSpaces } from "../util/util"
4-
import { PlatformPackager } from "../platformPackager"
54
import BluebirdPromise from "bluebird-lst-c"
65
import { LinuxBuildOptions } from "../options/linuxOptions"
6+
import { LinuxPackager } from "../linuxPackager"
77

88
export const installPrefix = "/opt"
99

@@ -12,7 +12,7 @@ export class LinuxTargetHelper {
1212

1313
maxIconPath: string | null = null
1414

15-
constructor(private packager: PlatformPackager<LinuxBuildOptions>) {
15+
constructor(private packager: LinuxPackager) {
1616
this.icons = this.computeDesktopIcons()
1717
}
1818

@@ -72,7 +72,7 @@ export class LinuxTargetHelper {
7272
const desktopMeta: any = Object.assign({
7373
Name: appInfo.productName,
7474
Comment: platformSpecificBuildOptions.description || appInfo.description,
75-
Exec: exec == null ? `"${installPrefix}/${productFilename}/${productFilename}"` : exec,
75+
Exec: exec == null ? `"${installPrefix}/${productFilename}/${this.packager.executableName}"` : exec,
7676
Terminal: "false",
7777
Type: "Application",
7878
Icon: appInfo.name,

src/targets/appImage.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PlatformPackager, TargetEx } from "../platformPackager"
1+
import { TargetEx } from "../platformPackager"
22
import { Arch } from "../metadata"
33
import * as path from "path"
44
import { exec, unlinkIfExists } from "../util/util"
@@ -7,7 +7,7 @@ import { LinuxTargetHelper } from "./LinuxTargetHelper"
77
import { getBin } from "../util/binDownload"
88
import BluebirdPromise from "bluebird-lst-c"
99
import { v1 as uuid1 } from "uuid-1345"
10-
import { LinuxBuildOptions } from "../options/linuxOptions"
10+
import { LinuxPackager } from "../linuxPackager"
1111

1212
const appImageVersion = process.platform === "darwin" ? "AppImage-09-07-16-mac" : "AppImage-09-07-16-linux"
1313
//noinspection SpellCheckingInspection
@@ -19,7 +19,7 @@ export default class AppImageTarget extends TargetEx {
1919
private readonly options = Object.assign({}, this.packager.platformSpecificBuildOptions, (<any>this.packager.devMetadata.build)[this.name])
2020
private readonly desktopEntry: Promise<string>
2121

22-
constructor(private packager: PlatformPackager<LinuxBuildOptions>, private helper: LinuxTargetHelper, private outDir: string) {
22+
constructor(private packager: LinuxPackager, private helper: LinuxTargetHelper, private outDir: string) {
2323
super("appImage")
2424

2525
// we add X-AppImage-BuildId to ensure that new desktop file will be installed
@@ -35,22 +35,18 @@ export default class AppImageTarget extends TargetEx {
3535

3636
// avoid spaces in the file name
3737
const image = path.join(this.outDir, packager.generateName("AppImage", arch, true))
38-
const appInfo = packager.appInfo
3938
await unlinkIfExists(image)
4039

4140
const appImagePath = await appImagePathPromise
42-
const appExecutableImagePath = `/usr/bin/${appInfo.name}`
4341
const args = [
4442
"-joliet", "on",
4543
"-volid", "AppImage",
4644
"-dev", image,
4745
"-padding", "0",
4846
"-map", appOutDir, "/usr/bin",
4947
"-map", path.join(__dirname, "..", "..", "templates", "linux", "AppRun.sh"), "/AppRun",
50-
"-map", await this.desktopEntry, `/${appInfo.name}.desktop`,
51-
"-move", `/usr/bin/${appInfo.productFilename}`, appExecutableImagePath,
52-
// http://stackoverflow.com/questions/13633488/can-i-store-unix-permissions-in-a-zip-file-built-with-apache-ant, xorriso doesn't preserve it for zip, but we set it in any case
53-
"-chmod", "+x", "/AppRun", appExecutableImagePath, "--",
48+
// we get executable name in the AppRun by desktop file name, so, must be named as executable
49+
"-map", await this.desktopEntry, `/${this.packager.executableName}.desktop`,
5450
]
5551
for (let [from, to] of (await this.helper.icons)) {
5652
args.push("-map", from, `/usr/share/icons/default/${to}`)

src/targets/fpm.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Arch } from "../metadata"
2-
import { smarten, PlatformPackager, TargetEx } from "../platformPackager"
2+
import { smarten, TargetEx } from "../platformPackager"
33
import { use, exec } from "../util/util"
44
import * as path from "path"
55
import { getBin } from "../util/binDownload"
@@ -8,7 +8,7 @@ import BluebirdPromise from "bluebird-lst-c"
88
import { LinuxTargetHelper, installPrefix } from "./LinuxTargetHelper"
99
import * as errorMessages from "../errorMessages"
1010
import { TmpDir } from "../util/tmp"
11-
import { LinuxBuildOptions } from "../options/linuxOptions"
11+
import { LinuxPackager } from "../linuxPackager"
1212

1313
const template = require("lodash.template")
1414

@@ -33,7 +33,7 @@ export default class FpmTarget extends TargetEx {
3333
private readonly scriptFiles: Promise<Array<string>>
3434
private readonly desktopEntry: Promise<string>
3535

36-
constructor(name: string, private packager: PlatformPackager<LinuxBuildOptions>, private helper: LinuxTargetHelper, private outDir: string) {
36+
constructor(name: string, private packager: LinuxPackager, private helper: LinuxTargetHelper, private outDir: string) {
3737
super(name)
3838

3939
this.scriptFiles = this.createScripts()
@@ -46,7 +46,7 @@ export default class FpmTarget extends TargetEx {
4646
const packager = this.packager
4747
const templateOptions = Object.assign({
4848
// old API compatibility
49-
executable: packager.appInfo.productFilename,
49+
executable: this.packager.executableName,
5050
}, packager.platformSpecificBuildOptions)
5151

5252
function getResource(value: string | n, defaultFile: string) {

0 commit comments

Comments
 (0)