Merge pull request #13431 from atom/dg-use-npm-chromedriver

Switch to npm provided chromedriver instead of manually downloaded
This commit is contained in:
Damien Guard 2016-12-13 13:12:03 -08:00 committed by GitHub
commit ad77c319ad
6 changed files with 27 additions and 68 deletions

View File

@ -5,7 +5,7 @@
* Node.js 4.4.x or later (the architecture of node available to the build system will determine whether you build 32-bit or 64-bit Atom)
* Python v2.7.x
* The python.exe must be available at `%SystemDrive%\Python27\python.exe`. If it is installed elsewhere create a symbolic link to the directory containing the python.exe using: `mklink /d %SystemDrive%\Python27 D:\elsewhere\Python27`
* 7zip (7z.exe available from the command line) - for unpacking Chromedriver and creating distribution zips
* 7zip (7z.exe available from the command line) - for creating distribution zip files
* Visual Studio, either:
* [Visual C++ Build Tools 2015](http://landinghub.visualstudio.com/visual-cpp-build-tools)
* [Visual Studio 2013 Update 5](https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs) (Express Edition or better)

View File

@ -23,6 +23,7 @@ const argv = yargs
.wrap(yargs.terminalWidth())
.argv
const checkChromedriverVersion = require('./lib/check-chromedriver-version')
const cleanOutputDirectory = require('./lib/clean-output-directory')
const codeSignOnMac = require('./lib/code-sign-on-mac')
const compressArtifacts = require('./lib/compress-artifacts')
@ -30,7 +31,6 @@ 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')
const generateAPIDocs = require('./lib/generate-api-docs')
const generateMetadata = require('./lib/generate-metadata')
@ -48,6 +48,7 @@ process.on('unhandledRejection', function (e) {
process.exit(1)
})
checkChromedriverVersion()
cleanOutputDirectory()
copyAssets()
transpileBabelPaths()
@ -58,7 +59,6 @@ generateModuleCache()
prebuildLessCache()
generateMetadata()
generateAPIDocs()
downloadChromedriver()
dumpSymbols()
.then(packageApplication)
.then(packagedAppPath => {

View File

@ -0,0 +1,22 @@
'use strict'
const buildMetadata = require('../package.json')
const CONFIG = require('../config')
const semver = require('semver')
module.exports = function () {
// Chromedriver should be specified as ~x.y where x and y match Electron major/minor
const chromedriverVer = buildMetadata.dependencies['electron-chromedriver']
// Always use tilde on electron-chromedriver so that it can pick up the best patch vesion
if (!chromedriverVer.startsWith('~')) {
throw new Error(`electron-chromedriver version in script/package.json should start with a tilde to match latest patch version.`)
}
const electronVer = CONFIG.appMetadata.electronVersion
if (!semver.satisfies(electronVer, chromedriverVer)) {
throw new Error(`electron-chromedriver ${chromedriverVer} incompatible with electron ${electronVer}.\n` +
'Did you upgrade electron in package.json and forget to upgrade electron-chromedriver in ' +
`script/package.json to '~${semver.major(electronVer)}.${semver.minor(electronVer)}' ?`)
}
}

View File

@ -1,64 +0,0 @@
'use strict'
const assert = require('assert')
const downloadFileFromGithub = require('./download-file-from-github')
const fs = require('fs-extra')
const path = require('path')
const semver = require('semver')
const spawnSync = require('./spawn-sync')
const syncRequest = require('sync-request')
const CONFIG = require('../config')
module.exports = function () {
// Chromedriver is only distributed with the first patch release for any given
// major and minor version of electron.
const electronVersion = semver.parse(CONFIG.appMetadata.electronVersion)
const electronVersionWithChromedriver = `${electronVersion.major}.${electronVersion.minor}.0`
const electronAssets = getElectronAssetsForVersion(electronVersionWithChromedriver)
const chromeDriverMatch = new RegExp(`^chromedriver-v.*-${process.platform}-${process.arch}`)
const chromedriverAssets = electronAssets.filter(e => chromeDriverMatch.test(e.name))
assert(chromedriverAssets.length === 1, 'Found more than one chrome driver asset to download!')
const chromedriverAsset = chromedriverAssets[0]
const chromedriverZipPath = path.join(CONFIG.electronDownloadPath, `electron-${electronVersionWithChromedriver}-${chromedriverAsset.name}`)
if (!fs.existsSync(chromedriverZipPath)) {
downloadFileFromGithub(chromedriverAsset.url, chromedriverZipPath)
}
const chromedriverDirPath = path.join(CONFIG.electronDownloadPath, 'chromedriver')
unzipPath(chromedriverZipPath, chromedriverDirPath)
}
function getElectronAssetsForVersion (version) {
const releaseURL = `https://api.github.com/repos/electron/electron/releases/tags/v${version}`
const response = syncRequest('GET', releaseURL, {'headers': {'User-Agent': 'Atom Build'}})
if (response.statusCode === 200) {
const release = JSON.parse(response.body)
return release.assets.map(a => { return {name: a.name, url: a.browser_download_url} })
} else {
throw new Error(`Error getting assets for ${releaseURL}. HTTP Status ${response.statusCode}.`)
}
}
function unzipPath (inputPath, outputPath) {
if (fs.existsSync(outputPath)) {
console.log(`Removing "${outputPath}"`)
fs.removeSync(outputPath)
}
console.log(`Unzipping "${inputPath}" to "${outputPath}"`)
try {
spawnSync('unzip', [inputPath, '-d', outputPath])
}
catch(err) {
if (err.code === 'ENOENT') {
// Unzip might not be available on Windows even though it comes with git so fall back to 7zip
spawnSync('7z', ['x', inputPath, `-o${outputPath}`])
}
else {
throw err;
}
}
}

View File

@ -8,6 +8,7 @@
"colors": "1.1.2",
"csslint": "1.0.2",
"donna": "1.0.13",
"electron-chromedriver": "~1.3",
"electron-packager": "7.3.0",
"electron-winstaller": "2.5.1",
"fs-extra": "0.30.0",

View File

@ -10,7 +10,7 @@ webdriverio = require '../../../script/node_modules/webdriverio'
AtomPath = remote.process.argv[0]
AtomLauncherPath = path.join(__dirname, "..", "helpers", "atom-launcher.sh")
ChromedriverPath = path.resolve(__dirname, '..', '..', '..', 'electron', 'chromedriver', 'chromedriver')
ChromedriverPath = path.resolve(__dirname, '..', '..', '..', 'script', 'node_modules', 'electron-chromedriver', 'bin', 'chromedriver')
SocketPath = path.join(os.tmpdir(), "atom-integration-test-#{Date.now()}.sock")
ChromedriverPort = 9515
ChromedriverURLBase = "/wd/hub"