Skip to content

Commit

Permalink
feat(linux): be more restrictive with executable name
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Nov 3, 2016
1 parent 76be355 commit c3136ad
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ Linux specific build options.
| desktop | <a name="LinuxBuildOptions-desktop"></a>The [Desktop file](https://developer.gnome.org/integration-guide/stable/desktop-files.html.en) entries.
| compression | <a name="LinuxBuildOptions-compression"></a>*deb-only.* The compression type, one of `gz`, `bzip2`, `xz`. Defaults to `xz`.
| depends | <a name="LinuxBuildOptions-depends"></a>Package dependencies. Defaults to `["libappindicator1", "libnotify-bin"]`.
| 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>

<a name="MacOptions"></a>
### `.build.mac`
Expand Down
1 change: 1 addition & 0 deletions nsis-auto-updater/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"strictNullChecks": true,
"noEmitHelpers": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"skipLibCheck": true
},
"declaration": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"json8": "^0.9.2",
"path-sort": "^0.1.0",
"ts-babel": "^1.1.3",
"tslint": "^4.0.0-dev.0",
"tslint": "^4.0.0-dev.1",
"typescript": "^2.1.0-dev.20161101",
"validate-commit-msg": "^2.8.2",
"whitespace": "^2.1.0"
Expand Down
8 changes: 7 additions & 1 deletion src/linuxPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ import { LinuxTargetHelper } from "./targets/LinuxTargetHelper"
import AppImageTarget from "./targets/appImage"
import { rename } from "fs-extra-p"
import { LinuxBuildOptions } from "./options/linuxOptions"
import sanitizeFileName from "sanitize-filename"

export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
readonly executableName: string

constructor(info: BuildInfo) {
super(info)

let executableName = this.platformSpecificBuildOptions.executableName
this.executableName = sanitizeFileName(executableName == null ? this.appInfo.name : executableName)
}

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

protected postInitApp(appOutDir: string): Promise<any> {
return rename(path.join(appOutDir, "electron"), path.join(appOutDir, this.appInfo.productFilename))
return rename(path.join(appOutDir, "electron"), path.join(appOutDir, this.executableName))
}

protected async packageInDistributableFormat(outDir: string, appOutDir: string, arch: Arch, targets: Array<Target>): Promise<any> {
Expand Down
7 changes: 7 additions & 0 deletions src/options/linuxOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,11 @@ export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
Package dependencies. Defaults to `["libappindicator1", "libnotify-bin"]`.
*/
readonly depends?: string[] | null

/*
The executable name. Defaults to `productName`.
Cannot be specified per target, allowed only in the `.build.linux`.
*/
readonly executableName?: string | null
}
2 changes: 1 addition & 1 deletion src/publish/BintrayPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class BintrayPublisher implements Publisher {

private readonly client: BintrayClient

constructor(private readonly info: BintrayOptions, private readonly version: string, private readonly options: PublishOptions = {}) {
constructor(info: BintrayOptions, private readonly version: string, private readonly options: PublishOptions = {}) {
let token = info.token
if (isEmptyOrSpaces(token)) {
token = process.env.BT_TOKEN
Expand Down
6 changes: 3 additions & 3 deletions src/targets/LinuxTargetHelper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { readdir, outputFile, ensureDir } from "fs-extra-p"
import * as path from "path"
import { exec, debug, isEmptyOrSpaces } from "../util/util"
import { PlatformPackager } from "../platformPackager"
import BluebirdPromise from "bluebird-lst-c"
import { LinuxBuildOptions } from "../options/linuxOptions"
import { LinuxPackager } from "../linuxPackager"

export const installPrefix = "/opt"

Expand All @@ -12,7 +12,7 @@ export class LinuxTargetHelper {

maxIconPath: string | null = null

constructor(private packager: PlatformPackager<LinuxBuildOptions>) {
constructor(private packager: LinuxPackager) {
this.icons = this.computeDesktopIcons()
}

Expand Down Expand Up @@ -72,7 +72,7 @@ export class LinuxTargetHelper {
const desktopMeta: any = Object.assign({
Name: appInfo.productName,
Comment: platformSpecificBuildOptions.description || appInfo.description,
Exec: exec == null ? `"${installPrefix}/${productFilename}/${productFilename}"` : exec,
Exec: exec == null ? `"${installPrefix}/${productFilename}/${this.packager.executableName}"` : exec,
Terminal: "false",
Type: "Application",
Icon: appInfo.name,
Expand Down
14 changes: 5 additions & 9 deletions src/targets/appImage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PlatformPackager, TargetEx } from "../platformPackager"
import { TargetEx } from "../platformPackager"
import { Arch } from "../metadata"
import * as path from "path"
import { exec, unlinkIfExists } from "../util/util"
Expand All @@ -7,7 +7,7 @@ import { LinuxTargetHelper } from "./LinuxTargetHelper"
import { getBin } from "../util/binDownload"
import BluebirdPromise from "bluebird-lst-c"
import { v1 as uuid1 } from "uuid-1345"
import { LinuxBuildOptions } from "../options/linuxOptions"
import { LinuxPackager } from "../linuxPackager"

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

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

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

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

const appImagePath = await appImagePathPromise
const appExecutableImagePath = `/usr/bin/${appInfo.name}`
const args = [
"-joliet", "on",
"-volid", "AppImage",
"-dev", image,
"-padding", "0",
"-map", appOutDir, "/usr/bin",
"-map", path.join(__dirname, "..", "..", "templates", "linux", "AppRun.sh"), "/AppRun",
"-map", await this.desktopEntry, `/${appInfo.name}.desktop`,
"-move", `/usr/bin/${appInfo.productFilename}`, appExecutableImagePath,
// 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
"-chmod", "+x", "/AppRun", appExecutableImagePath, "--",
// we get executable name in the AppRun by desktop file name, so, must be named as executable
"-map", await this.desktopEntry, `/${this.packager.executableName}.desktop`,
]
for (let [from, to] of (await this.helper.icons)) {
args.push("-map", from, `/usr/share/icons/default/${to}`)
Expand Down
8 changes: 4 additions & 4 deletions src/targets/fpm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Arch } from "../metadata"
import { smarten, PlatformPackager, TargetEx } from "../platformPackager"
import { smarten, TargetEx } from "../platformPackager"
import { use, exec } from "../util/util"
import * as path from "path"
import { getBin } from "../util/binDownload"
Expand All @@ -8,7 +8,7 @@ import BluebirdPromise from "bluebird-lst-c"
import { LinuxTargetHelper, installPrefix } from "./LinuxTargetHelper"
import * as errorMessages from "../errorMessages"
import { TmpDir } from "../util/tmp"
import { LinuxBuildOptions } from "../options/linuxOptions"
import { LinuxPackager } from "../linuxPackager"

const template = require("lodash.template")

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

constructor(name: string, private packager: PlatformPackager<LinuxBuildOptions>, private helper: LinuxTargetHelper, private outDir: string) {
constructor(name: string, private packager: LinuxPackager, private helper: LinuxTargetHelper, private outDir: string) {
super(name)

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

function getResource(value: string | n, defaultFile: string) {
Expand Down
12 changes: 10 additions & 2 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ test.ifDevOrLinuxCi("extra metadata", () => {
foo: {
bar: 12,
},
productName: "NewName"
build: {
linux: {
executableName: "NewName"
}
}
}
return assertPack("test-app-one", {
targets: Platform.LINUX.createTarget(DIR_TARGET),
Expand All @@ -260,7 +264,11 @@ test.ifDevOrLinuxCi("extra metadata", () => {

test.ifDevOrLinuxCi("extra metadata - two", () => {
const extraMetadata = {
productName: "NewName"
build: {
linux: {
executableName: "NewName"
}
}
}
return assertPack("test-app", {
targets: Platform.LINUX.createTarget(DIR_TARGET),
Expand Down
2 changes: 1 addition & 1 deletion test/src/helpers/fileAssert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Assertions {
compare(this.actual.slice().sort(), Array.from(expected).slice().sort())
}

hasProperties<T>(expected: any) {
hasProperties(expected: any) {
const actual = Object.create(null)
for (let name of Object.getOwnPropertyNames(this.actual)) {
if (name in expected) {
Expand Down
2 changes: 1 addition & 1 deletion test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ async function checkLinuxResult(outDir: string, packager: Packager, checkOptions
const productFilename = appInfo.productFilename
const expectedContents = pathSorter(expectedLinuxContents.map(it => {
if (it === "/opt/TestApp/TestApp") {
return `/opt/${productFilename}/${productFilename}`
return `/opt/${productFilename}/TestApp`
}
else if (it === "/usr/share/applications/TestApp.desktop") {
return `/usr/share/applications/${productFilename}.desktop`
Expand Down
11 changes: 10 additions & 1 deletion test/src/linuxPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ test.ifNotWindows("arm deb", app({targets: Platform.LINUX.createTarget("deb", Ar

test.ifDevOrLinuxCi("AppImage", app({targets: Platform.LINUX.createTarget()}))

test.ifDevOrLinuxCi("AppImage - default icon", app({targets: Platform.LINUX.createTarget("appimage")}, {
test.ifDevOrLinuxCi("AppImage - default icon", app({
targets: Platform.LINUX.createTarget("appimage"),
devMetadata: {
build: {
linux: {
executableName: "foo",
}
}
}
}, {
projectDirCreated: projectDir => remove(path.join(projectDir, "build"))
}))

Expand Down
1 change: 1 addition & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"noImplicitReturns": true,
"noEmitHelpers": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"skipLibCheck": true
},
"rootDirs": [
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"strictNullChecks": true,
"noEmitHelpers": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"skipLibCheck": true
},
"declaration": {
Expand Down
3 changes: 0 additions & 3 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"static-before-instance",
"variables-before-functions"
],
"no-unused-variable": [
true
],
"one-line": [
true,
"check-open-brace",
Expand Down
Loading

0 comments on commit c3136ad

Please sign in to comment.