Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(build): a Linux icon is a file, not surgery on the executable

esengine6b688df91469
diff --git a/build-tools/utils/desktopApp.js b/build-tools/utils/desktopApp.js
index b8678321a..651bff737 100644
--- a/build-tools/utils/desktopApp.js
+++ b/build-tools/utils/desktopApp.js
@@ -135,13 +135,15 @@ export async function assembleDesktopApp(options) {
const iconPng = options.iconPng && existsSync(options.iconPng) ? options.iconPng : sources.icon;
if (existsSync(iconPng)) {
const png = await readFile(iconPng);
- // Where each OS keeps it: macOS beside the app's other resources, Windows
- // INSIDE the executable — which is why one is a file to write and the
- // other is a rewrite of the thing that was just copied.
+ // Three OSes, three places: a container beside the resources (macOS),
+ // INSIDE the executable (Windows), and a plain file a .desktop entry
+ // points at (Linux — a PE rewriter over an ELF would corrupt it).
if (platform === 'macos') {
await writeFile(path.join(root, layout.beside, 'AppIcon.icns'), pngToIcns(png));
- } else {
+ } else if (platform === 'windows') {
await writeFile(executable, setExeIcon(await readFile(executable), png));
+ } else {
+ await writeFile(path.join(root, 'icon.png'), png);
}
}
diff --git a/desktop/tests/desktop-app.test.ts b/desktop/tests/desktop-app.test.ts
index 117451ae2..4361c2454 100644
--- a/desktop/tests/desktop-app.test.ts
+++ b/desktop/tests/desktop-app.test.ts
@@ -157,10 +157,30 @@ describe('Windows assembly', () => {
});
it('refuses a platform with no layout', async () => {
+ // A desktop OS the assembler does not have a shape for: it says which it
+ // has rather than producing a directory shaped like the wrong one.
await expect(assembleDesktopApp({
- platform: 'linux' as 'windows', templateDir, contentDir, outDir, app: APP,
+ platform: 'freebsd' as 'windows', templateDir, contentDir, outDir, app: APP,
})).rejects.toThrow(/no desktop layout/);
});
+
+ it('lays a Linux app out as the directory a depot maps whole', async () => {
+ // Windows' shape without the extension: the runtime at the root of a
+ // directory named for the app, its files beside it.
+ writeFileSync(path.join(templateDir, 'estella_desktop'), 'runtime');
+ const { dir: root } = await assembleDesktopApp({
+ platform: 'linux', templateDir, contentDir, outDir, app: APP,
+ });
+ expect(root).toBe(path.join(outDir, 'Acme Game'));
+ expect(existsSync(path.join(root, 'Acme Game'))).toBe(true);
+ expect(existsSync(path.join(root, 'Content', 'game.config.json'))).toBe(true);
+ // The icon is a FILE here, not something inside the binary: a .desktop
+ // entry points at one, and a PE rewriter run over an ELF would corrupt
+ // the executable it was meant to decorate.
+ expect(existsSync(path.join(root, 'icon.png'))).toBe(true);
+ expect(existsSync(path.join(root, 'AppIcon.icns'))).toBe(false);
+ expect(existsSync(path.join(root, 'Info.plist'))).toBe(false);
+ });
});
describe('the store library a package carries', () => {