From 08dcb39f87f63d220328ff75fbd9ac5ea7abd2fe Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 15 Aug 2016 16:00:33 +0200 Subject: [PATCH] Start on RPM package creation --- resources/linux/redhat/atom.spec.in | 22 ++++++-- script/build | 8 +++ script/lib/create-rpm-package.js | 87 +++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 script/lib/create-rpm-package.js diff --git a/resources/linux/redhat/atom.spec.in b/resources/linux/redhat/atom.spec.in index 3397135bd..0ee120b35 100644 --- a/resources/linux/redhat/atom.spec.in +++ b/resources/linux/redhat/atom.spec.in @@ -22,10 +22,24 @@ chmod 755 "%{buildroot}/<%= installDir %>/bin/<%= appFileName %>" mkdir -p "%{buildroot}/<%= installDir %>/share/applications/" cp "<%= appFileName %>.desktop" "%{buildroot}/<%= installDir %>/share/applications/" -for i in 1024 512 256 128 64 48 32 24 16; do - mkdir -p "%{buildroot}/<%= installDir %>/share/icons/hicolor/${i}x${i}/apps" - cp "icons/${i}.png" "%{buildroot}/<%= installDir %>/share/icons/hicolor/${i}x${i}/apps/<%= appFileName %>.png" -done +mkdir -p "%{buildroot}/<%= installDir %>/share/icons/hicolor/1024x1024/apps" +cp "icons/1024.png" "%{buildroot}/<%= installDir %>/share/icons/hicolor/1024x1024/apps/<%= appFileName %>.png" +mkdir -p "%{buildroot}/<%= installDir %>/share/icons/hicolor/512x512/apps" +cp "icons/512.png" "%{buildroot}/<%= installDir %>/share/icons/hicolor/512x512/apps/<%= appFileName %>.png" +mkdir -p "%{buildroot}/<%= installDir %>/share/icons/hicolor/256x256/apps" +cp "icons/256.png" "%{buildroot}/<%= installDir %>/share/icons/hicolor/256x256/apps/<%= appFileName %>.png" +mkdir -p "%{buildroot}/<%= installDir %>/share/icons/hicolor/128x128/apps" +cp "icons/128.png" "%{buildroot}/<%= installDir %>/share/icons/hicolor/128x128/apps/<%= appFileName %>.png" +mkdir -p "%{buildroot}/<%= installDir %>/share/icons/hicolor/64x64/apps" +cp "icons/64.png" "%{buildroot}/<%= installDir %>/share/icons/hicolor/64x64/apps/<%= appFileName %>.png" +mkdir -p "%{buildroot}/<%= installDir %>/share/icons/hicolor/48x48/apps" +cp "icons/48.png" "%{buildroot}/<%= installDir %>/share/icons/hicolor/48x48/apps/<%= appFileName %>.png" +mkdir -p "%{buildroot}/<%= installDir %>/share/icons/hicolor/32x32/apps" +cp "icons/32.png" "%{buildroot}/<%= installDir %>/share/icons/hicolor/32x32/apps/<%= appFileName %>.png" +mkdir -p "%{buildroot}/<%= installDir %>/share/icons/hicolor/24x24/apps" +cp "icons/24.png" "%{buildroot}/<%= installDir %>/share/icons/hicolor/24x24/apps/<%= appFileName %>.png" +mkdir -p "%{buildroot}/<%= installDir %>/share/icons/hicolor/16x16/apps" +cp "icons/16.png" "%{buildroot}/<%= installDir %>/share/icons/hicolor/16x16/apps/<%= appFileName %>.png" %files <%= installDir %>/bin/<%= appFileName %> diff --git a/script/build b/script/build index bdbd54417..527cd1cbb 100755 --- a/script/build +++ b/script/build @@ -12,6 +12,7 @@ const argv = require('yargs') .describe('code-sign', 'Code-sign executables (macOS and Windows only)') .describe('create-windows-installer', 'Create installer (Windows only)') .describe('create-debian-package', 'Create .deb package (Linux only)') + .describe('create-rpm-package', 'Create .rpm package (Linux only)') .describe('compress-artifacts', 'Compress Atom binaries (and symbols on macOS)') .describe('install', 'Install Atom') .argv @@ -21,6 +22,7 @@ const codeSignOnMac = require('./lib/code-sign-on-mac') const compressArtifacts = require('./lib/compress-artifacts') const copyAssets = require('./lib/copy-assets') const createDebianPackage = require('./lib/create-debian-package') +const createRpmPackage = require('./lib/create-rpm-package') const createWindowsInstaller = require('./lib/create-windows-installer') const downloadChromedriver = require('./lib/download-chromedriver') const dumpSymbols = require('./lib/dump-symbols') @@ -73,6 +75,12 @@ dumpSymbols() } else { console.log('Skipping creating debian package. Specify the --create-debian-package option to create it.'.gray) } + + if (argv.createRpmPackage) { + createRpmPackage(packagedAppPath) + } else { + console.log('Skipping creating rpm package. Specify the --create-rpm-package option to create it.'.gray) + } } return Promise.resolve(packagedAppPath) diff --git a/script/lib/create-rpm-package.js b/script/lib/create-rpm-package.js new file mode 100644 index 000000000..85f880319 --- /dev/null +++ b/script/lib/create-rpm-package.js @@ -0,0 +1,87 @@ +'use strict' + +const childProcess = require('child_process') +const copySync = require('./copy-sync') +const fs = require('fs-extra') +const os = require('os') +const path = require('path') +const template = require('lodash.template') + +const CONFIG = require('../config') + +module.exports = function (packagedAppPath) { + console.log(`Creating rpm package for "${packagedAppPath}"`) + const atomExecutableName = CONFIG.channel === 'beta' ? 'atom-beta' : 'atom' + const apmExecutableName = CONFIG.channel === 'beta' ? 'apm-beta' : 'apm' + const appName = CONFIG.channel === 'beta' ? 'Atom Beta' : 'Atom' + const appDescription = CONFIG.appMetadata.description + // RPM versions can't have dashes in them. + // * http://www.rpm.org/max-rpm/ch-rpm-file-format.html + // * https://github.com/mojombo/semver/issues/145 + const appVersion = CONFIG.appMetadata.version.replace(/-beta/, "~beta").replace(/-dev/, "~dev") + let arch + if (process.arch === 'ia32') { + arch = 'i386' + } else if (process.arch === 'x64') { + arch = 'amd64' + } else { + arch = process.arch + } + + const outputRpmPackageFilePath = path.join(CONFIG.buildOutputPath, 'atom.x86_64.rpm') + const rpmPackageDirPath = path.join(CONFIG.homeDirPath, 'rpmbuild') + const rpmPackageBuildDirPath = path.join(rpmPackageDirPath, 'BUILD') + const rpmPackageSourcesDirPath = path.join(rpmPackageDirPath, 'SOURCES') + const rpmPackageSpecsDirPath = path.join(rpmPackageDirPath, 'SPECS') + const rpmPackageRpmsDirPath = path.join(rpmPackageDirPath, 'RPMS') + const rpmPackageApplicationDirPath = path.join(rpmPackageBuildDirPath, appName) + const rpmPackageIconsDirPath = path.join(rpmPackageBuildDirPath, 'icons') + + if (fs.existsSync(rpmPackageBuildDirPath)) { + console.log(`Deleting existing rpm build directory at "${rpmPackageBuildDirPath}"`) + fs.removeSync(rpmPackageBuildDirPath) + } + + console.log(`Creating rpm package directory structure at "${rpmPackageDirPath}"`) + fs.mkdirpSync(rpmPackageBuildDirPath) + fs.mkdirpSync(rpmPackageSourcesDirPath) + fs.mkdirpSync(rpmPackageSpecsDirPath) + + console.log(`Copying "${packagedAppPath}" to "${rpmPackageApplicationDirPath}"`) + copySync(packagedAppPath, rpmPackageApplicationDirPath) + + console.log(`Copying icons into "${rpmPackageIconsDirPath}"`) + copySync( + path.join(CONFIG.repositoryRootPath, 'resources', 'app-icons', CONFIG.channel, 'png'), + rpmPackageIconsDirPath + ) + + console.log(`Writing rpm package spec file into "${rpmPackageSpecsDirPath}"`) + const rpmPackageSpecFilePath = path.join(rpmPackageSpecsDirPath, 'atom.spec') + const rpmPackageSpecsTemplate = fs.readFileSync(path.join(CONFIG.repositoryRootPath, 'resources', 'linux', 'redhat', 'atom.spec.in')) + const rpmPackageSpecsContents = template(rpmPackageSpecsTemplate)({ + appName: appName, appFileName: atomExecutableName, apmFileName: apmExecutableName, + description: appDescription, installDir: '/usr', version: appVersion + }) + fs.writeFileSync(rpmPackageSpecFilePath, rpmPackageSpecsContents) + + console.log(`Writing desktop entry file into "${rpmPackageBuildDirPath}"`) + const desktopEntryTemplate = fs.readFileSync(path.join(CONFIG.repositoryRootPath, 'resources', 'linux', 'atom.desktop.in')) + const desktopEntryContents = template(desktopEntryTemplate)({ + appName: appName, appFileName: atomExecutableName, description: appDescription, + installDir: '/usr', iconName: atomExecutableName + }) + fs.writeFileSync(path.join(rpmPackageBuildDirPath, `${atomExecutableName}.desktop`), desktopEntryContents) + + console.log(`Copying atom.sh into "${rpmPackageBuildDirPath}"`) + copySync( + path.join(CONFIG.repositoryRootPath, 'atom.sh'), + path.join(rpmPackageBuildDirPath, 'atom.sh') + ) + + console.log(`Generating .rpm package from "${rpmPackageDirPath}"`) + childProcess.spawnSync('rpmbuild', ['-ba', '--clean', rpmPackageSpecFilePath]) + + // TODO: copy generated package into out/ + // console.log(`Copying generated package into "${outputRpmPackageFilePath}"`) +}