-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from electron-userland/common-dependencies
Add minimal Electron dependencies
- Loading branch information
Showing
6 changed files
with
155 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use strict' | ||
|
||
const dependencies = require('electron-installer-common/src/dependencies') | ||
const spawn = require('./spawn') | ||
|
||
const dependencyMap = { | ||
gconf: 'GConf2', | ||
glib2: 'glib2', | ||
gtk2: 'gtk2', | ||
gtk3: 'gtk3', | ||
gvfs: 'gvfs-client', | ||
kdeCliTools: 'kde-cli-tools', | ||
kdeRuntime: 'kde-runtime', | ||
notify: 'libnotify', | ||
nss: 'nss', | ||
trashCli: 'trash-cli', | ||
uuid: 'libuuid', | ||
xdgUtils: 'xdg-utils', | ||
xss: 'libXScrnSaver', | ||
xtst: 'libXtst' | ||
} | ||
|
||
/** | ||
* Retrieves the RPM version number and determines whether it has support for boolean | ||
* dependencies (>= 4.13.0). | ||
*/ | ||
function rpmSupportsBooleanDependencies (logger) { | ||
return spawn('rpmbuild', ['--version'], logger) | ||
.then(output => rpmVersionSupportsBooleanDependencies(output.trim().split(' ')[2])) | ||
} | ||
|
||
/** | ||
* Determine whether the RPM version string has support for boolean dependencies (>= 4.13.0). | ||
* | ||
* RPM does not follow semantic versioning, so `semver` cannot be used. | ||
*/ | ||
function rpmVersionSupportsBooleanDependencies (rpmVersionString) { | ||
const rpmVersion = rpmVersionString.split('.').slice(0, 3).map(n => parseInt(n)) | ||
return rpmVersion >= [4, 13, 0] | ||
} | ||
|
||
/** | ||
* Transforms the list of trash requires into an RPM boolean dependency list. | ||
*/ | ||
function trashRequiresAsBoolean (electronVersion, dependencyMap) { | ||
const trashDepends = dependencies.getTrashDepends(electronVersion, dependencyMap) | ||
if (trashDepends.length === 1) { | ||
return [trashDepends[0]] | ||
} else { | ||
return [`(${trashDepends.join(' or ')})`] | ||
} | ||
} | ||
|
||
module.exports = { | ||
dependencyMap, | ||
/** | ||
* The dependencies for Electron itself, given an Electron version. | ||
*/ | ||
forElectron: function dependenciesForElectron (electronVersion, logger) { | ||
const requires = dependencies.getDepends(electronVersion, dependencyMap) | ||
return module.exports.rpmSupportsBooleanDependencies(logger) | ||
.then(supportsBooleanDependencies => { | ||
if (supportsBooleanDependencies) { | ||
const trashRequires = trashRequiresAsBoolean(electronVersion, dependencyMap) | ||
return { requires: requires.concat(trashRequires) } | ||
} else { | ||
console.warn("You are using RPM < 4.13, which does not support boolean dependencies. This is required to express the dependencies needed for the 'shell.moveItemToTrash' API.\nIf you do not use this API, you can safely ignore this warning.\nIf you do use this API, please upgrade to RPM 4.13 or above to have the trash dependencies added to your RPM's requires section.") | ||
return { requires } | ||
} | ||
}) | ||
}, | ||
rpmSupportsBooleanDependencies, | ||
rpmVersionSupportsBooleanDependencies, | ||
trashRequiresAsBoolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const dependencies = require('../src/dependencies') | ||
const { expect } = require('chai') | ||
const sinon = require('sinon') | ||
|
||
describe('dependencies', () => { | ||
describe('forElectron', () => { | ||
beforeEach(() => { | ||
sinon.spy(console, 'warn') | ||
}) | ||
|
||
afterEach(() => { | ||
sinon.restore() | ||
}) | ||
|
||
it('uses an RPM that does not support boolean dependencies', () => { | ||
sinon.stub(dependencies, 'rpmSupportsBooleanDependencies').resolves(false) | ||
return dependencies.forElectron('v1.0.0') | ||
.then(result => { | ||
expect(console.warn.calledWithMatch(/^You are using RPM < 4.13/)).to.equal(true) | ||
}) | ||
}) | ||
|
||
it('uses an RPM that supports boolean dependencies', () => { | ||
sinon.stub(dependencies, 'rpmSupportsBooleanDependencies').resolves(true) | ||
return dependencies.forElectron('v1.0.0') | ||
.then(result => { | ||
expect(console.warn.calledWithMatch(/^You are using RPM < 4.13/)).to.equal(false) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('rpmVersionSupportsBooleanDependencies', () => { | ||
it('works with release candidates', () => { | ||
expect(dependencies.rpmVersionSupportsBooleanDependencies('4.13.0-rc1')).to.equal(true) | ||
}) | ||
|
||
it('works with git snapshots', () => { | ||
expect(dependencies.rpmVersionSupportsBooleanDependencies('4.11.90-git12844')).to.equal(false) | ||
}) | ||
|
||
it('works with 4 part versions (1.2.3.4)', () => { | ||
expect(dependencies.rpmVersionSupportsBooleanDependencies('4.1.12.2')).to.equal(false) | ||
}) | ||
}) | ||
|
||
describe('trashRequiresAsBoolean', () => { | ||
it('does not use parentheses for one item', () => { | ||
const trashDeps = dependencies.trashRequiresAsBoolean('1.0.0', dependencies.dependencyMap)[0] | ||
expect(trashDeps[0]).to.not.match(/^\(/) | ||
}) | ||
|
||
it('ORs more than one item', () => { | ||
const trashDeps = dependencies.trashRequiresAsBoolean('1.5.0', dependencies.dependencyMap)[0] | ||
expect(trashDeps).to.match(/^\(.* or .*\)$/) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v0.29.2 | ||
v1.8.5 |