Skip to content

Commit

Permalink
Merge pull request #371 from brave/touch_overridden_files
Browse files Browse the repository at this point in the history
Introduce --touch_overridden_files option to build command
  • Loading branch information
simonhong authored Jun 19, 2018
2 parents 09eb9b7 + ec43cdd commit 9d39f79
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions build/lib/build.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,58 @@
const config = require('../lib/config')
const util = require('../lib/util')
const path = require('path')
const fs = require('fs-extra')

const touchOverriddenFiles = (filter) => {
console.log('touch original files overridden by chromium_src...')

// Return true when original file of |file| should be touched.
const applyFileFilter = (file) => {
// Exclude test files
if (file.indexOf('browsertest') > -1 || file.indexOf('unittest') > -1) { return false }

// Only includes cc and h files.
const ext = path.extname(file)
if (ext !== '.cc' && ext !== '.h') { return false }

// Touch all overridden files.
if (filter === '*') { return true }

return file.match(filter)
}

const walkSync = (dir, filelist = []) => {
fs.readdirSync(dir).forEach(file => {
if (fs.statSync(path.join(dir, file)).isDirectory()) {
filelist = walkSync(path.join(dir, file), filelist)
} else if (applyFileFilter(file)) {
filelist = filelist.concat(path.join(dir, file))
}
})
return filelist
}

const chromiumSrcDir = path.join(config.srcDir, 'brave', 'chromium_src')
var sourceFiles = walkSync(chromiumSrcDir)

// Touch original files by updating mtime.
const chromiumSrcDirLen = chromiumSrcDir.length
sourceFiles.forEach(file => {
const targetOriginalFile = path.join(config.srcDir, file.slice(chromiumSrcDirLen))
const date = new Date()
fs.utimesSync(targetOriginalFile, date, date)
console.log(targetOriginalFile + ' is touched.')
})
}

const build = (buildConfig = config.defaultBuildConfig, options) => {
config.buildConfig = buildConfig
config.update(options)

if (options.touch_overridden_files) {
touchOverriddenFiles(options.touch_overridden_files)
}

if (!options.no_branding_update) {
util.updateBranding()
}
Expand Down
1 change: 1 addition & 0 deletions build/scripts/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ program
.option('--brave_google_api_endpoint <brave_google_api_endpoint>')
.option('--no_branding_update', 'don\'t copy BRANDING to the chrome theme dir')
.option('--channel <target_chanel>', 'target channel to build', /^(beta|canary|dev|release)$/i, 'release')
.option('--touch_overridden_files <target filter>', 'touch original files overridden by chromium_src. Pass '*' to touch all files')
.arguments('[build_config]')
.action(build)

Expand Down

0 comments on commit 9d39f79

Please sign in to comment.