2016-11-09 21:02:49 -07:00
|
|
|
const path = require('path')
|
|
|
|
const spawnSync = require('child_process').spawnSync
|
|
|
|
const config = require('./config')
|
2017-01-18 19:03:26 -07:00
|
|
|
const fs = require('fs-extra')
|
2018-07-22 19:40:55 -04:00
|
|
|
const autoGeneratedBraveToChromiumMapping = Object.assign({}, require('./l10nUtil').autoGeneratedBraveToChromiumMapping)
|
2016-11-09 21:02:49 -07:00
|
|
|
|
|
|
|
const runGClient = (args, options = {}) => {
|
2018-06-06 17:54:19 -05:00
|
|
|
if (config.gClientVerbose) args.push('--verbose')
|
2016-11-09 21:02:49 -07:00
|
|
|
options.cwd = options.cwd || config.rootDir
|
|
|
|
options = mergeWithDefault(options)
|
|
|
|
options.env.GCLIENT_FILE = config.gClientFile
|
|
|
|
util.run('gclient', args, options)
|
|
|
|
}
|
|
|
|
|
|
|
|
const mergeWithDefault = (options) => {
|
|
|
|
return Object.assign({}, config.defaultOptions, options)
|
|
|
|
}
|
|
|
|
|
|
|
|
const util = {
|
|
|
|
run: (cmd, args = [], options = {}) => {
|
|
|
|
console.log(cmd, args.join(' '))
|
2017-07-05 10:05:32 -07:00
|
|
|
const continueOnFail = options.continueOnFail
|
|
|
|
delete options.continueOnFail
|
|
|
|
|
2016-11-09 21:02:49 -07:00
|
|
|
const prog = spawnSync(cmd, args, options)
|
|
|
|
if (prog.status !== 0) {
|
2017-07-05 10:05:32 -07:00
|
|
|
if (!continueOnFail) {
|
|
|
|
console.log(prog.stdout && prog.stdout.toString())
|
|
|
|
console.error(prog.stderr && prog.stderr.toString())
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2016-11-09 21:02:49 -07:00
|
|
|
}
|
2016-11-16 13:01:25 -07:00
|
|
|
return prog
|
2016-11-09 21:02:49 -07:00
|
|
|
},
|
|
|
|
|
2016-11-10 01:14:33 -07:00
|
|
|
buildGClientConfig: () => {
|
|
|
|
function replacer(key, value) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2016-12-14 17:04:43 -07:00
|
|
|
let solutions = config.projectNames.filter((projectName) => config.projects[projectName].ref).map((projectName) => {
|
2016-11-10 01:14:33 -07:00
|
|
|
let project = config.projects[projectName]
|
|
|
|
return {
|
|
|
|
managed: "%False%",
|
|
|
|
name: project.gclientName,
|
|
|
|
url: project.url,
|
|
|
|
custom_deps: project.custom_deps
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-06-29 13:28:59 -07:00
|
|
|
const out = 'solutions = ' + JSON.stringify(solutions, replacer, 2)
|
2016-11-10 01:14:33 -07:00
|
|
|
.replace(/"%None%"/g, "None")
|
|
|
|
.replace(/"%False%"/g, "False")
|
|
|
|
fs.writeFileSync(config.defaultGClientFile, out)
|
|
|
|
},
|
|
|
|
|
2017-01-16 08:14:51 -07:00
|
|
|
updateBranding: () => {
|
|
|
|
console.log('update branding...')
|
2018-02-18 19:24:57 -05:00
|
|
|
const chromeComponentsDir = path.join(config.srcDir, 'components')
|
2018-07-10 17:32:39 -07:00
|
|
|
const braveComponentsDir = path.join(config.projects['brave-core'].dir, 'components')
|
2017-11-16 12:27:28 -07:00
|
|
|
const chromeAppDir = path.join(config.srcDir, 'chrome', 'app')
|
2018-03-24 21:57:33 -04:00
|
|
|
const braveAppDir = path.join(config.projects['brave-core'].dir, 'app')
|
2018-06-20 15:27:42 -07:00
|
|
|
const chromeResourcesDir = path.join(config.srcDir, 'chrome', 'browser', 'resources')
|
|
|
|
const braveResourcesDir = path.join(config.projects['brave-core'].dir, 'browser', 'resources')
|
2018-07-01 10:23:40 -07:00
|
|
|
const chromeBrowserDir = path.join(config.srcDir, 'chrome', 'browser')
|
|
|
|
const braveBrowserDir = path.join(config.projects['brave-core'].dir, 'browser')
|
2018-07-10 17:31:59 -07:00
|
|
|
const braveAppVectorIconsDir = path.join(config.projects['brave-core'].dir, 'vector_icons', 'chrome', 'app')
|
2018-06-20 15:27:42 -07:00
|
|
|
|
2018-07-22 19:40:55 -04:00
|
|
|
// The following 3 entries we map to the same name, not the chromium equivalent name for copying back
|
|
|
|
autoGeneratedBraveToChromiumMapping[path.join(braveAppDir, 'brave_strings.grd')] = path.join(chromeAppDir, 'brave_strings.grd')
|
|
|
|
autoGeneratedBraveToChromiumMapping[path.join(braveAppDir, 'settings_brave_strings.grdp')] = path.join(chromeAppDir, 'settings_brave_strings.grdp')
|
|
|
|
autoGeneratedBraveToChromiumMapping[path.join(braveAppDir, 'components_brave_strings.grd')] = path.join(config.srcDir, 'components', 'components_brave_strings.grd')
|
|
|
|
|
|
|
|
// Copy each grd back to Chromium src dir
|
|
|
|
Object.entries(autoGeneratedBraveToChromiumMapping).forEach(([bravePath, chromiumPath]) =>
|
|
|
|
fs.copySync(bravePath, chromiumPath))
|
|
|
|
|
|
|
|
// Copy xtb files for:
|
|
|
|
// brave/app/resources/chromium_strings*.xtb
|
|
|
|
// brave/app/strings/components_chromium_strings*.xtb
|
|
|
|
// brave/app/resources/generated_resoruces*.xtb
|
|
|
|
fs.copySync(path.join(braveAppDir, 'resources'), path.join(chromeAppDir, 'resources'))
|
|
|
|
fs.copySync(path.join(braveAppDir, 'strings'), path.join(chromeComponentsDir, 'strings'))
|
2018-06-18 18:56:27 -07:00
|
|
|
|
2017-11-18 18:47:33 -07:00
|
|
|
fs.copySync(path.join(braveAppDir, 'theme', 'brave'), path.join(chromeAppDir, 'theme', 'brave'))
|
2017-11-16 12:27:28 -07:00
|
|
|
fs.copySync(path.join(braveAppDir, 'theme', 'default_100_percent', 'brave'), path.join(chromeAppDir, 'theme', 'default_100_percent', 'brave'))
|
|
|
|
fs.copySync(path.join(braveAppDir, 'theme', 'default_200_percent', 'brave'), path.join(chromeAppDir, 'theme', 'default_200_percent', 'brave'))
|
2018-06-22 13:44:48 +09:00
|
|
|
// By overwriting, we don't need to modify some grd files.
|
2018-06-30 10:40:57 +09:00
|
|
|
fs.copySync(path.join(braveAppDir, 'theme', 'brave'), path.join(chromeAppDir, 'theme', 'chromium'))
|
2018-06-22 13:44:48 +09:00
|
|
|
fs.copySync(path.join(braveAppDir, 'theme', 'default_100_percent', 'brave'), path.join(chromeAppDir, 'theme', 'default_100_percent', 'chromium'))
|
|
|
|
fs.copySync(path.join(braveAppDir, 'theme', 'default_200_percent', 'brave'), path.join(chromeAppDir, 'theme', 'default_200_percent', 'chromium'))
|
2018-07-10 17:32:39 -07:00
|
|
|
fs.copySync(path.join(braveComponentsDir, 'resources', 'default_100_percent', 'brave'), path.join(chromeComponentsDir, 'resources', 'default_100_percent', 'chromium'))
|
|
|
|
fs.copySync(path.join(braveComponentsDir, 'resources', 'default_200_percent', 'brave'), path.join(chromeComponentsDir, 'resources', 'default_200_percent', 'chromium'))
|
2018-07-10 17:31:59 -07:00
|
|
|
fs.copySync(path.join(braveAppVectorIconsDir, 'vector_icons', 'brave'), path.join(chromeAppDir, 'vector_icons', 'brave'))
|
2018-06-29 21:27:57 -07:00
|
|
|
fs.copySync(path.join(braveResourcesDir, 'settings', 'brave_page_visibility.js'), path.join(chromeResourcesDir, 'settings', 'brave_page_visibility.js'))
|
2017-01-16 08:14:51 -07:00
|
|
|
},
|
|
|
|
|
2018-06-26 09:20:30 +09:00
|
|
|
// Chromium compares pre-installed midl files and generated midl files from IDL during the build to check integrity.
|
|
|
|
// Generated files during the build time and upstream pre-installed files are different because we use different IDL file.
|
|
|
|
// So, we should copy our pre-installed files to overwrite upstream pre-installed files.
|
|
|
|
// After checking, pre-installed files are copied to gen dir and they are used to compile.
|
|
|
|
// So, this copying in every build doesn't affect compile performance.
|
|
|
|
updateOmahaMidlFiles: () => {
|
|
|
|
console.log('update omaha midl files...')
|
|
|
|
const srcDir = path.join(config.projects['brave-core'].dir, 'win_build_output', 'midl', 'google_update')
|
|
|
|
const dstDir = path.join(config.srcDir, 'third_party', 'win_build_output', 'midl', 'google_update')
|
|
|
|
fs.copySync(srcDir, dstDir)
|
|
|
|
},
|
|
|
|
|
2018-06-06 17:54:19 -05:00
|
|
|
buildTarget: (options = config.defaultOptions) => {
|
|
|
|
console.log('building ' + config.buildTarget + '...')
|
2017-01-16 08:14:51 -07:00
|
|
|
|
2018-06-28 09:37:37 +09:00
|
|
|
if (process.platform === 'win32') util.updateOmahaMidlFiles()
|
2018-06-26 09:20:30 +09:00
|
|
|
|
2017-01-16 08:14:51 -07:00
|
|
|
const args = util.buildArgsToString(config.buildArgs())
|
|
|
|
util.run('gn', ['gen', config.outputDir, '--args="' + args + '"'], options)
|
2018-06-06 17:54:19 -05:00
|
|
|
util.run('ninja', ['-C', config.outputDir, config.buildTarget], options)
|
2017-01-16 08:14:51 -07:00
|
|
|
},
|
|
|
|
|
2018-05-26 19:59:44 -05:00
|
|
|
submoduleSync: (options = {}) => {
|
|
|
|
if (!options.cwd) options.cwd = config.rootDir // default cwd `./src` may not exist yet
|
2016-11-09 21:02:49 -07:00
|
|
|
options = mergeWithDefault(options)
|
|
|
|
util.run('git', ['submodule', 'sync'], options)
|
|
|
|
util.run('git', ['submodule', 'update', '--init', '--recursive'], options)
|
2018-05-26 19:59:44 -05:00
|
|
|
util.run('git', ['-C', config.depotToolsDir, 'clean', '-fxd'], options)
|
|
|
|
util.run('git', ['-C', config.depotToolsDir, 'reset', '--hard', 'HEAD'], options)
|
2016-11-09 21:02:49 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
gclientSync: (options = {}) => {
|
2018-06-29 13:28:59 -07:00
|
|
|
runGClient(['sync', '--force', '--nohooks', '--with_branch_heads'], options)
|
2016-11-09 21:02:49 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
gclientRunhooks: (options = {}) => {
|
|
|
|
runGClient(['runhooks'], options)
|
|
|
|
},
|
|
|
|
|
|
|
|
fetch: (options = {}) => {
|
2018-05-26 19:59:44 -05:00
|
|
|
if (!options.cwd) options.cwd = config.rootDir
|
2016-11-09 21:02:49 -07:00
|
|
|
options = mergeWithDefault(options)
|
2018-05-26 19:59:44 -05:00
|
|
|
util.run('git', ['-C', options.git_cwd, 'fetch', '--all', '--tags'], options)
|
2016-11-09 21:02:49 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
setVersion: (version, options = {}) => {
|
2018-05-26 19:59:44 -05:00
|
|
|
if (!options.cwd) options.cwd = config.rootDir
|
|
|
|
util.run('git', ['-C', options.git_cwd, 'clean', '-f'], options)
|
|
|
|
util.run('git', ['-C', options.git_cwd, 'reset', '--hard', version], options)
|
2016-11-09 21:02:49 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
setDepVersion: (dir, version) => {
|
2018-05-26 19:59:44 -05:00
|
|
|
const options = { git_cwd: dir }
|
2016-11-09 21:02:49 -07:00
|
|
|
util.fetch(options)
|
|
|
|
util.setVersion(version, options)
|
|
|
|
},
|
2016-11-27 19:29:59 -07:00
|
|
|
|
|
|
|
buildArgsToString: (buildArgs) => {
|
|
|
|
let args = ''
|
|
|
|
for (let arg in buildArgs) {
|
|
|
|
let val = buildArgs[arg]
|
|
|
|
if (typeof val === 'string') {
|
|
|
|
val = '"' + val + '"'
|
|
|
|
} else {
|
|
|
|
val = JSON.stringify(val)
|
|
|
|
}
|
|
|
|
args += arg + '=' + val + ' '
|
|
|
|
}
|
|
|
|
return args.replace(/"/g,'\\"')
|
|
|
|
}
|
2016-11-09 21:02:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = util
|