Add grunt mkrpm task to create rpm package

This commit is contained in:
Ardeshir Javaherchi 2014-10-11 17:04:14 -07:00
parent e33e5df467
commit b5c6d76999
4 changed files with 93 additions and 0 deletions

View File

@ -234,6 +234,7 @@ module.exports = (grunt) ->
ciTasks.push('dump-symbols') if process.platform isnt 'win32'
ciTasks.push('set-version', 'check-licenses', 'lint')
ciTasks.push('mkdeb') if process.platform is 'linux'
ciTasks.push('mkrpm') if process.platform is 'linux'
ciTasks.push('test') if process.platform is 'darwin'
ciTasks.push('codesign')
ciTasks.push('publish-build')

View File

@ -0,0 +1,44 @@
fs = require 'fs'
path = require 'path'
_ = require 'underscore-plus'
module.exports = (grunt) ->
{spawn} = require('./task-helpers')(grunt)
fillTemplate = (filePath, data) ->
template = _.template(String(fs.readFileSync("#{filePath}.in")))
filled = template(data)
outputPath = path.join(grunt.config.get('atom.buildDir'), path.basename(filePath))
grunt.file.write(outputPath, filled)
outputPath
grunt.registerTask 'mkrpm', 'Create rpm package', ->
done = @async()
if process.arch is 'ia32'
arch = 'i386'
else if process.arch is 'x64'
arch = 'amd64'
else
return done("Unsupported arch #{process.arch}")
{name, version, description} = grunt.file.readJSON('package.json')
section = 'devel'
maintainer = 'GitHub <atom@github.com>'
installDir = grunt.config.get('atom.installDir')
shareDir = path.join(installDir, 'share', 'atom')
iconName = path.join(shareDir, 'resources', 'app', 'resources', 'atom.png')
data = {name, version, description, section, maintainer, installDir, iconName}
specFilePath = fillTemplate(path.join('resources', 'linux', 'redhat', 'atom.spec'), data)
desktopFilePath = fillTemplate(path.join('resources', 'linux', 'Atom.desktop'), data)
cmd = path.join('script', 'mkrpm')
args = [specFilePath, desktopFilePath]
spawn {cmd, args}, (error) ->
if error?
done(error)
else
grunt.log.ok "Created rpm package"
done()

View File

@ -0,0 +1,29 @@
Name: <%= name %>
Version: <%= version %>
Release: 0.1%{?dist}
Summary: Atom is a hackable text editor for the 21st century
License: MIT
URL: https://atom.io/
BuildConflicts: gyp
BuildRequires: make, gcc, gcc-c++, glibc-devel, git-core, libgnome-keyring-devel
Requires: libgnome-keyring
AutoReqProv: no # Avoid libchromiumcontent.so missing dependency
%description
<%= description %>
%install
mkdir -p %{buildroot}/usr/local/share/atom
cp -r /tmp/atom-build/Atom/* %{buildroot}/usr/local/share/atom
mkdir -p %{buildroot}/usr/local/bin/
ln -sf /usr/local/share/atom/resources/app/apm/node_modules/.bin/apm %{buildroot}/usr/local/bin/apm
cp atom.sh %{buildroot}/usr/local/bin/atom
chmod 755 atom.sh
mkdir -p %{buildroot}/usr/local/share/applications/
mv Atom.desktop %{buildroot}/usr/local/share/applications/
%files
/usr/local/bin/atom
/usr/local/bin/apm
/usr/local/share/atom/
/usr/local/share/applications/Atom.desktop

19
script/mkrpm Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
SPEC_FILE="$1"
DESKTOP_FILE="$2"
RPM_BUILD_ROOT=~/rpmbuild
ARCH=`uname -m`
rpmdev-setuptree
cp -r /tmp/atom-build/Atom/* $RPM_BUILD_ROOT/BUILD
cp $SPEC_FILE $RPM_BUILD_ROOT/SPECS
cp ./atom.sh $RPM_BUILD_ROOT/BUILD
cp $DESKTOP_FILE $RPM_BUILD_ROOT/BUILD
rpmbuild -ba $SPEC_FILE
cp $RPM_BUILD_ROOT/RPMS/$ARCH/atom-*.rpm "./"
rm -rf $RPM_BUILD_ROOT