diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000000..37ac743d552 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/depot_tools"] + path = vendor/depot_tools + url = https://chromium.googlesource.com/chromium/tools/depot_tools.git diff --git a/DEPS b/DEPS index cebf312a7c1..f28e986c743 100644 --- a/DEPS +++ b/DEPS @@ -15,6 +15,7 @@ deps = { "vendor/bat-native-tweetnacl": "https://github.com/brave-intl/bat-native-tweetnacl.git@800f9d40b7409239ff192e0be634764e747c7a75", "vendor/bat-native-usermodel": "https://github.com/brave-intl/bat-native-usermodel.git@02b8c81c94072c67fe00108feb90786e088d4d26", "vendor/challenge_bypass_ristretto_ffi": "https://github.com/brave-intl/challenge-bypass-ristretto-ffi.git@c396fb4eb9e9bf63b89ae5a0ec0b5f201d43c7c5", + "vendor/gn-project-generators": "https://github.com/brave/gn-project-generators.git@b76e14b162aa0ce40f11920ec94bfc12da29e5d0", } hooks = [ diff --git a/build/commands/lib/config.js b/build/commands/lib/config.js index e138693c1b5..ba0d64316a8 100755 --- a/build/commands/lib/config.js +++ b/build/commands/lib/config.js @@ -68,7 +68,6 @@ const Config = function () { this.buildTarget = 'brave' this.rootDir = rootDir this.scriptDir = path.join(this.rootDir, 'scripts') - this.depotToolsDir = path.join(this.rootDir, 'vendor', 'depot_tools') this.srcDir = path.join(this.rootDir, 'src') this.chromeVersion = this.getProjectVersion('chrome') this.chromiumRepo = getNPMConfig(['projects', 'chrome', 'repository', 'url']) @@ -76,6 +75,7 @@ const Config = function () { this.braveCoreRepo = getNPMConfig(['projects', 'brave-core', 'repository', 'url']) this.buildToolsDir = path.join(this.srcDir, 'build') this.resourcesDir = path.join(this.rootDir, 'resources') + this.depotToolsDir = path.join(this.braveCoreDir, 'vendor', 'depot_tools') this.defaultGClientFile = path.join(this.rootDir, '.gclient') this.gClientFile = process.env.BRAVE_GCLIENT_FILE || this.defaultGClientFile this.gClientVerbose = getNPMConfig(['gclient_verbose']) || false diff --git a/build/commands/lib/util.js b/build/commands/lib/util.js index 4e97518e8da..6f9653aaf0a 100755 --- a/build/commands/lib/util.js +++ b/build/commands/lib/util.js @@ -533,7 +533,7 @@ const util = { console.log('generating Xcode workspace for "' + config.xcode_gen_target + '"...') const args = util.buildArgsToString(config.buildArgs()) - const genScript = path.join(config.rootDir, 'vendor', 'gn-project-generators', 'xcode.py') + const genScript = path.join(config.braveCoreDir, 'vendor', 'gn-project-generators', 'xcode.py') const genArgs = [ 'gen', config.outputDir + "_Xcode", @@ -558,52 +558,6 @@ const util = { '--base_branch=' + options.base], cmd_options) }, - fixDepotTools: (options = {}) => { - if (process.platform !== 'win32') { - util.run('git', ['-C', config.depotToolsDir, 'clean', '-fxd'], options) - util.run('git', ['-C', config.depotToolsDir, 'reset', '--hard', 'HEAD'], options) - return - } - // On Windows: - // When depot_tools are already installed they redirect git to their own - // version which resides in a bootstrap-*_bin directory. So when we try to - // do git clean -fxd we fail because the git executable is in use in that - // directory. Get around that by using regular git. - let git_exes = util.run('where', ['git'], {shell: true}) - let git_exe = '"' + git_exes.stdout.toString().split(os.EOL)[0] + '"' - if (git_exe === '""') git_exe = 'git' - util.run(git_exe, ['-C', config.depotToolsDir, 'clean', '-fxd'], options) - util.run(git_exe, ['-C', config.depotToolsDir, 'reset', '--hard', 'HEAD'], options) - - // Get around the error in updating depot_tools on windows due to pylint.bat - // file transitioning from untracked to a committed file. When - // update_depot_tools script tries to use git rebase it errors out. This is - // already fixed upstream, but we need a workaround for - // now. See https://bugs.chromium.org/p/chromium/issues/detail?id=996359 - // The commit id in git merge-base command below is when pylint.bat was - // added to git. - let cmd_options = Object.assign({}, options) - cmd_options.continueOnFail = true - let is_fixed = util.run('git', - ['-C', config.depotToolsDir, 'merge-base', '--is-ancestor', '53297790de09e48c91678367b48528afbc9f71c1', 'HEAD'], cmd_options) - // If merge-base succeeds the exit code is 0. - if (!is_fixed.status) return - console.log("Manually updating depot_tools as a workaround for https://crbug.com/996359") - util.run('git', ['-C', config.depotToolsDir, 'fetch', 'origin'], options) - util.run('git', ['-C', config.depotToolsDir, 'checkout', 'origin/master'], options) - util.run('git', ['-C', config.depotToolsDir, 'reset', '--hard', 'origin/master'], options) - }, - - submoduleSync: (options = {}) => { - Log.progress('Updating submodules...') - if (!options.cwd) options.cwd = config.rootDir // default cwd `./src` may not exist yet - options = mergeWithDefault(options) - util.run('git', ['submodule', 'sync'], options) - util.run('git', ['submodule', 'update', '--init', '--recursive'], options) - util.fixDepotTools(options) - Log.progress('Done updating submodules...') - }, - shouldUpdateChromium: (chromiumRef = config.getProjectRef('chrome')) => { const headSHA = util.runGit(config.srcDir, ['rev-parse', 'HEAD'], true) const targetSHA = util.runGit(config.srcDir, ['rev-parse', chromiumRef], true) diff --git a/build/commands/scripts/sync.js b/build/commands/scripts/sync.js index 2c1f43f65ed..c29cca62416 100644 --- a/build/commands/scripts/sync.js +++ b/build/commands/scripts/sync.js @@ -3,6 +3,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this file, // you can obtain one at http://mozilla.org/MPL/2.0/. +const fs = require('fs') const program = require('commander') const config = require('../lib/config') const util = require('../lib/util') @@ -18,12 +19,53 @@ program .option('--target_os ', 'target OS') .option('--target_arch ', 'target architecture') .option('--target_apk_base ', 'target Android OS apk (classic, modern, mono)') - .option('--submodule_sync', 'run submodule sync') .option('--init', 'initialize all dependencies') .option('--all', 'This flag is deprecated and no longer has any effect') .option('--force', 'force reset all projects to origin/ref') .option('--create', 'create a new branch if needed for [ref]') +const installDepotTools = (options = config.defaultOptions) => { + options.cwd = config.braveCoreDir + + util.run('git', ['submodule', 'sync'], options) + util.run('git', ['submodule', 'update', '--init', '--recursive'], options) + + // fixup depot tools after update + if (process.platform !== 'win32') { + util.run('git', ['-C', config.depotToolsDir, 'clean', '-fxd'], options) + util.run('git', ['-C', config.depotToolsDir, 'reset', '--hard', 'HEAD'], options) + return + } + // On Windows: + // When depot_tools are already installed they redirect git to their own + // version which resides in a bootstrap-*_bin directory. So when we try to + // do git clean -fxd we fail because the git executable is in use in that + // directory. Get around that by using regular git. + let git_exes = util.run('where', ['git'], {shell: true}) + let git_exe = '"' + git_exes.stdout.toString().split(os.EOL)[0] + '"' + if (git_exe === '""') git_exe = 'git' + util.run(git_exe, ['-C', config.depotToolsDir, 'clean', '-fxd'], options) + util.run(git_exe, ['-C', config.depotToolsDir, 'reset', '--hard', 'HEAD'], options) + + // Get around the error in updating depot_tools on windows due to pylint.bat + // file transitioning from untracked to a committed file. When + // update_depot_tools script tries to use git rebase it errors out. This is + // already fixed upstream, but we need a workaround for + // now. See https://bugs.chromium.org/p/chromium/issues/detail?id=996359 + // The commit id in git merge-base command below is when pylint.bat was + // added to git. + let cmd_options = Object.assign({}, options) + cmd_options.continueOnFail = true + let is_fixed = util.run('git', + ['-C', config.depotToolsDir, 'merge-base', '--is-ancestor', '53297790de09e48c91678367b48528afbc9f71c1', 'HEAD'], cmd_options) + // If merge-base succeeds the exit code is 0. + if (!is_fixed.status) return + console.log("Manually updating depot_tools as a workaround for https://crbug.com/996359") + util.run('git', ['-C', config.depotToolsDir, 'fetch', 'origin'], options) + util.run('git', ['-C', config.depotToolsDir, 'checkout', 'origin/master'], options) + util.run('git', ['-C', config.depotToolsDir, 'reset', '--hard', 'origin/master'], options) +} + async function RunCommand () { program.parse(process.argv) config.update(program) @@ -32,8 +74,10 @@ async function RunCommand () { Log.warn('--all, --run_hooks and --run_sync are deprecated. Will behave as if flag was not passed. Please update your command to `npm run sync` in the future.') } - if (program.init || program.submodule_sync) { - util.submoduleSync() + if (program.init || !fs.existsSync(config.depotTooldDir)) { + Log.progress('Updating submodules...') + installDepotTools() + Log.progress('Done updating submodules...') } if (program.init) { diff --git a/vendor/depot_tools b/vendor/depot_tools new file mode 160000 index 00000000000..343f63643b4 --- /dev/null +++ b/vendor/depot_tools @@ -0,0 +1 @@ +Subproject commit 343f63643b432ace2d2d4c253c6c327bb18c03ea