Reimplement script/bootstrap

This commit is contained in:
Antonio Scandurra 2016-08-02 14:04:45 +02:00
parent 9def97fe9c
commit cf85bd032d
12 changed files with 179 additions and 17 deletions

View File

@ -23,8 +23,8 @@ install:
- source /tmp/.nvm/nvm.sh
- nvm install $NODE_VERSION
- nvm use --delete-prefix $NODE_VERSION
- script/bootstrap
- node build/build.js
- script/bootstrap.js
- script/build.js
script:
- echo 'Run tests at some point.'
@ -34,7 +34,7 @@ cache:
- cache
- node_modules
- apm/node_modules
- build/node_modules
- script/node_modules
notifications:
email:

View File

@ -24,7 +24,7 @@ install:
build_script:
- cd %APPVEYOR_BUILD_FOLDER%
- script\bootstrap.cmd
- node build\build.js
- script\build.cmd
test: off
deploy: off
@ -35,7 +35,7 @@ artifacts:
name: AtomSetup.msi
cache:
- '%APPVEYOR_BUILD_FOLDER%\build\node_modules'
- '%APPVEYOR_BUILD_FOLDER%\script\node_modules'
- '%APPVEYOR_BUILD_FOLDER%\apm\node_modules'
- '%APPVEYOR_BUILD_FOLDER%\node_modules'
- '%APPVEYOR_BUILD_FOLDER%\cache'

View File

@ -27,8 +27,8 @@ dependencies:
- npm install -g npm
override:
- script/bootstrap
- build/build.js --code-sign
- script/bootstrap.js
- script/build.js --code-sign
post:
- cd out/Atom-darwin-x64 && zip -r ../atom-mac.zip ./Atom.app && cd -
@ -37,9 +37,9 @@ dependencies:
cache_directories:
- cache
- apm/node_modules
- build/node_modules
- script/node_modules
- node_modules
test:
override:
- build/test.js
- script/test.js

6
script/bootstrap.cmd Normal file
View File

@ -0,0 +1,6 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\bootstrap" %*
) ELSE (
node "%~dp0\bootstrap" %*
)

15
script/bootstrap.js vendored Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env node
'use strict'
const path = require('path')
const installApm = require('./lib/install-apm')
const installAtomDependencies = require('./lib/install-atom-dependencies')
const installScriptDependencies = require('./lib/install-script-dependencies')
const verifyMachineRequirements = require('./lib/verify-machine-requirements')
verifyMachineRequirements()
installScriptDependencies()
installApm()
installAtomDependencies()

5
script/build.cmd Normal file
View File

@ -0,0 +1,5 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\build" %*
) ELSE (
node "%~dp0\build" %*
)

View File

@ -3,24 +3,30 @@
'use strict'
const fs = require('fs')
const path = require('path')
const appMetadata = require('../package.json')
const apmMetadata = require('../apm/node_modules/atom-package-manager/package.json')
const channel = getChannel()
const repositoryRootPath = path.resolve(__dirname, '..')
const apmRootPath = path.join(repositoryRootPath, 'apm')
const scriptRootPath = path.join(repositoryRootPath, 'script')
const buildOutputPath = path.join(repositoryRootPath, 'out')
const intermediateAppPath = path.join(buildOutputPath, 'app')
const symbolsPath = path.join(buildOutputPath, 'symbols')
const cachePath = path.join(repositoryRootPath, 'cache')
const homeDirPath = process.env.HOME || process.env.USERPROFILE
const appMetadata = require(path.join(repositoryRootPath, 'package.json'))
const apmMetadata = require(path.join(apmRootPath, 'package.json'))
const channel = getChannel()
const apmBinPath = getApmBinPath()
const npmBinPath = getNpmBinPath()
module.exports = {
appMetadata, apmMetadata, channel,
repositoryRootPath, buildOutputPath, intermediateAppPath, symbolsPath,
cachePath, homeDirPath
repositoryRootPath, apmRootPath, scriptRootPath, buildOutputPath, intermediateAppPath, symbolsPath,
cachePath, homeDirPath,
apmBinPath, npmBinPath
}
function getChannel () {
@ -40,3 +46,14 @@ function isBuildingPR () {
process.env.CI_PULL_REQUEST
)
}
function getApmBinPath () {
const apmBinName = process.platform === 'win32' ? 'apm.cmd' : 'apm'
return path.join(apmRootPath, 'node_modules', '.bin', apmBinName)
}
function getNpmBinPath () {
const npmBinName = process.platform === 'win32' ? 'npm.cmd' : 'npm'
const localNpmBinPath = path.resolve(repositoryRootPath, 'script', 'node_modules', '.bin', npmBinName)
return fs.existsSync(localNpmBinPath) ? localNpmBinPath : npmBinName
}

View File

@ -19,7 +19,7 @@ exports.fingerprintMatches = function () {
function computeFingerprint () {
//Include the electron minor version in the fingerprint since that changing requires a re-install
const electronVersion = CONFIG.appMetadata.electronVersion.replace(/\.\d+$/, '')
const apmVersion = CONFIG.apmMetadata.version
const apmVersion = CONFIG.apmMetadata.dependencies['atom-package-manager']
const body = electronVersion + apmVersion + process.platform + process.version
return crypto.createHash('sha1').update(body).digest('hex')

15
script/lib/install-apm.js Normal file
View File

@ -0,0 +1,15 @@
'use strict'
const childProcess = require('child_process')
const path = require('path')
const CONFIG = require('../config')
module.exports = function () {
console.log('Installing apm...')
childProcess.execFileSync(
CONFIG.npmBinPath,
['--global-style', '--loglevel=error', 'install'],
{env: process.env, cwd: CONFIG.apmRootPath}
)
}

View File

@ -0,0 +1,22 @@
'use strict'
const childProcess = require('child_process')
const path = require('path')
const CONFIG = require('../config')
module.exports = function () {
const installEnv = Object.assign({}, process.env)
// Set our target (Electron) version so that node-pre-gyp can download the
// proper binaries.
installEnv.npm_config_target = CONFIG.appMetadata.electronVersion;
// Force 32-bit modules on Windows. (Ref.: https://github.com/atom/atom/issues/10450)
if (process.platform === 'win32') {
installEnv.npm_config_target_arch = 'ia32'
}
childProcess.execFileSync(
CONFIG.apmBinPath,
['--loglevel=error', 'install'],
{env: installEnv, cwd: CONFIG.repositoryRootPath, stdio: 'inherit'}
)
}

View File

@ -0,0 +1,15 @@
'use strict'
const childProcess = require('child_process')
const path = require('path')
const CONFIG = require('../config')
module.exports = function () {
console.log('Installing script dependencies...')
childProcess.execFileSync(
CONFIG.npmBinPath,
['--loglevel=error', 'install'],
{env: process.env, cwd: CONFIG.scriptRootPath}
)
}

View File

@ -0,0 +1,67 @@
'use strict'
const childProcess = require('child_process')
const fs = require('fs')
const path = require('path')
const CONFIG = require('../config')
module.exports = function () {
verifyNode()
verifyNpm()
if (process.platform === 'win32') {
verifyPython()
}
}
function verifyNode () {
const fullVersion = process.versions.node
const majorVersion = fullVersion.split('.')[0]
if (majorVersion >= 4) {
console.log(`Node:\tv${fullVersion}`)
} else {
throw new Error(`node v4+ is required to build Atom. node v${fullVersion} is installed.`)
}
}
function verifyNpm () {
const stdout = childProcess.execFileSync(CONFIG.npmBinPath, ['--version'], {env: process.env})
const fullVersion = stdout.toString().trim()
const majorVersion = fullVersion.split('.')[0]
if (majorVersion >= 3) {
console.log(`Npm:\tv${fullVersion}`)
} else {
throw new Error(`npm v3+ is required to build Atom. npm v${fullVersion} was detected.`)
}
}
function verifyPython () {
const systemDrive = process.env.SystemDrive || 'C:\\'
let pythonExecutable
if (process.env.PYTHON) {
pythonExecutable = process.env.PYTHON
} else {
const pythonBinPath = path.join(systemDrive, 'Python27', 'python.exe')
if (fs.existsSync(pythonBinPath)) {
pythonExecutable = pythonBinPath
} else {
pythonExecutable = 'python'
}
}
const stdout = childProcess.execFileSync(pythonExecutable, ['-c', 'import platform\nprint(platform.python_version())'], {env: process.env})
if (stdout.indexOf('+') !== -1) stdout = stdout.replace(/\+/g, '')
if (stdout.indexOf('rc') !== -1) stdout = stdout.replace(/rc(.*)$/ig, '')
const fullVersion = stdout.toString().trim()
const versionComponents = fullVersion.split('.')
const majorVersion = Number(versionComponents[0])
const minorVersion = Number(versionComponents[1])
if (majorVersion === 2 && minorVersion === 7) {
console.log(`Python:\tv${fullVersion}`)
} else {
throw new Error(
`Python 2.7 is required to build Atom. ${pythonExecutable} returns version ${fullVersion}.\n` +
`Set the PYTHON env var to '/path/to/Python27/python.exe' if your python is installed in a non-default location.`
)
}
}