forked from brave/brave-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
118 lines (100 loc) · 4.27 KB
/
build.js
File metadata and controls
118 lines (100 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const config = require('../lib/config')
const util = require('../lib/util')
const path = require('path')
const fs = require('fs-extra')
const touchOverriddenFiles = () => {
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' && ext !== '.mm') { return false }
return true
}
const chromiumSrcDir = path.join(config.srcDir, 'brave', 'chromium_src')
var sourceFiles = util.walkSync(chromiumSrcDir, applyFileFilter)
// Touch original files by updating mtime.
const chromiumSrcDirLen = chromiumSrcDir.length
sourceFiles.forEach(chromiumSrcFile => {
var overriddenFile = path.join(config.srcDir, chromiumSrcFile.slice(chromiumSrcDirLen))
if (!fs.existsSync(overriddenFile)) {
// Try to check that original file is in gen dir.
overriddenFile = path.join(config.outputDir, 'gen', chromiumSrcFile.slice(chromiumSrcDirLen))
}
if (fs.existsSync(overriddenFile)) {
// If overriddenFile is older than file in chromium_src, touch it to trigger rebuild.
if (fs.statSync(chromiumSrcFile).mtimeMs - fs.statSync(overriddenFile).mtimeMs > 0) {
const date = new Date()
fs.utimesSync(overriddenFile, date, date)
console.log(overriddenFile + ' is touched.')
}
}
})
}
const touchOverriddenVectorIconFiles = () => {
console.log('touch original vector icon files overridden by brave/vector_icons...')
// Return true when original file of |file| should be touched.
const applyFileFilter = (file) => {
// Only includes icon files.
const ext = path.extname(file)
if (ext !== '.icon') { return false }
return true
}
const braveVectorIconsDir = path.join(config.srcDir, 'brave', 'vector_icons')
var braveVectorIconFiles = util.walkSync(braveVectorIconsDir, applyFileFilter)
// Touch original files by updating mtime.
const braveVectorIconsDirLen = braveVectorIconsDir.length
braveVectorIconFiles.forEach(braveVectorIconFile => {
var overriddenFile = path.join(config.srcDir, braveVectorIconFile.slice(braveVectorIconsDirLen))
if (fs.existsSync(overriddenFile)) {
// If overriddenFile is older than file in vector_icons, touch it to trigger rebuild.
if (fs.statSync(braveVectorIconFile).mtimeMs - fs.statSync(overriddenFile).mtimeMs > 0) {
const date = new Date()
fs.utimesSync(overriddenFile, date, date)
console.log(overriddenFile + ' is touched.')
}
}
})
}
/**
* Checks to make sure the src/chrome/VERSION matches brave-browser's package.json version
*/
const checkVersionsMatch = () => {
const srcChromeVersionDir = path.resolve(path.join(__dirname, '..', 'src', 'chrome', 'VERSION'))
const versionData = fs.readFileSync(srcChromeVersionDir, 'utf8')
const re = /MAJOR=(\d+)\s+MINOR=(\d+)\s+BUILD=(\d+)\s+PATCH=(\d+)/
const found = versionData.match(re)
const braveVersionFromChromeFile = `${found[2]}.${found[3]}.${found[4]}`
if (braveVersionFromChromeFile !== config.braveVersion) {
// Only a warning. The CI environment will choose to proceed or not within its own script.
console.warn(`Version files do not match!\nsrc/chrome/VERSION: ${braveVersionFromChromeFile}\nbrave-browser package.json version: ${config.braveVersion}`)
}
}
const build = (buildConfig = config.defaultBuildConfig, options) => {
config.buildConfig = buildConfig
config.update(options)
checkVersionsMatch()
touchOverriddenFiles()
touchOverriddenVectorIconFiles()
util.updateBranding()
if (config.xcode_gen_target) {
util.generateXcodeWorkspace()
} else {
util.buildTarget()
if (config.shouldSign()) {
util.signApp()
}
if (process.platform === 'win32') {
// Sign only binaries for widevine sig generation.
// Other binaries will be done during the create_dist.
// Then, both are merged whenarchive for installer is created.
util.signWinBinaries()
if (config.brave_enable_cdm_host_verification) {
util.generateWidevineSigFiles()
}
}
}
}
module.exports = build