forked from brave/brave-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
184 lines (158 loc) · 8.6 KB
/
util.js
File metadata and controls
184 lines (158 loc) · 8.6 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
const path = require('path')
const spawnSync = require('child_process').spawnSync
const config = require('./config')
const fs = require('fs-extra')
const autoGeneratedBraveToChromiumMapping = Object.assign({}, require('./l10nUtil').autoGeneratedBraveToChromiumMapping)
const runGClient = (args, options = {}) => {
if (config.gClientVerbose) args.push('--verbose')
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(' '))
const continueOnFail = options.continueOnFail
delete options.continueOnFail
const prog = spawnSync(cmd, args, options)
if (prog.status !== 0) {
if (!continueOnFail) {
console.log(prog.stdout && prog.stdout.toString())
console.error(prog.stderr && prog.stderr.toString())
process.exit(1)
}
}
return prog
},
buildGClientConfig: () => {
function replacer(key, value) {
return value;
}
let solutions = config.projectNames.filter((projectName) => config.projects[projectName].ref).map((projectName) => {
let project = config.projects[projectName]
return {
managed: "%False%",
name: project.gclientName,
url: project.url,
custom_deps: project.custom_deps
}
})
const out = 'solutions = ' + JSON.stringify(solutions, replacer, 2)
.replace(/"%None%"/g, "None")
.replace(/"%False%"/g, "False")
fs.writeFileSync(config.defaultGClientFile, out)
},
updateBranding: () => {
console.log('update branding...')
const chromeComponentsDir = path.join(config.srcDir, 'components')
const braveComponentsDir = path.join(config.projects['brave-core'].dir, 'components')
const chromeAppDir = path.join(config.srcDir, 'chrome', 'app')
const braveAppDir = path.join(config.projects['brave-core'].dir, 'app')
const chromeResourcesDir = path.join(config.srcDir, 'chrome', 'browser', 'resources')
const braveResourcesDir = path.join(config.projects['brave-core'].dir, 'browser', 'resources')
const chromeBrowserDir = path.join(config.srcDir, 'chrome', 'browser')
const braveBrowserDir = path.join(config.projects['brave-core'].dir, 'browser')
const braveAppVectorIconsDir = path.join(config.projects['brave-core'].dir, 'vector_icons', 'chrome', 'app')
// 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'))
fs.copySync(path.join(braveAppDir, 'theme', 'brave'), path.join(chromeAppDir, 'theme', 'brave'))
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'))
// By overwriting, we don't need to modify some grd files.
fs.copySync(path.join(braveAppDir, 'theme', 'brave'), path.join(chromeAppDir, 'theme', 'chromium'))
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'))
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'))
fs.copySync(path.join(braveAppVectorIconsDir, 'vector_icons', 'brave'), path.join(chromeAppDir, 'vector_icons', 'brave'))
fs.copySync(path.join(braveResourcesDir, 'settings', 'brave_page_visibility.js'), path.join(chromeResourcesDir, 'settings', 'brave_page_visibility.js'))
if (process.platform === 'darwin') {
// Copy proper mac app icon for channel to chrome/app/theme/mac/app.icns.
// Each channel's app icons are stored in brave/app/theme/$channel/app.icns.
// With this copying, we don't need to modify chrome/BUILD.gn for this.
fs.copySync(path.join(braveAppDir, 'theme', 'brave', 'mac', config.channel, 'app.icns'),
path.join(chromeAppDir, 'theme', 'brave', 'mac', 'app.icns'))
// Copy branding file
let branding_file_name = 'BRANDING'
if (config.channel)
branding_file_name = branding_file_name + '.' + config.channel
fs.copySync(path.join(braveAppDir, 'theme', 'brave', branding_file_name), path.join(chromeAppDir, 'theme', 'brave', 'BRANDING'))
}
},
// 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)
},
buildTarget: (options = config.defaultOptions) => {
console.log('building ' + config.buildTarget + '...')
if (process.platform === 'win32') util.updateOmahaMidlFiles()
const args = util.buildArgsToString(config.buildArgs())
util.run('gn', ['gen', config.outputDir, '--args="' + args + '"'], options)
util.run('ninja', ['-C', config.outputDir, config.buildTarget], options)
},
submoduleSync: (options = {}) => {
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.run('git', ['-C', config.depotToolsDir, 'clean', '-fxd'], options)
util.run('git', ['-C', config.depotToolsDir, 'reset', '--hard', 'HEAD'], options)
},
gclientSync: (options = {}) => {
runGClient(['sync', '--force', '--nohooks', '--with_branch_heads'], options)
},
gclientRunhooks: (options = {}) => {
runGClient(['runhooks'], options)
},
fetch: (options = {}) => {
if (!options.cwd) options.cwd = config.rootDir
options = mergeWithDefault(options)
util.run('git', ['-C', options.git_cwd, 'fetch', '--all', '--tags'], options)
},
setVersion: (version, options = {}) => {
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)
},
setDepVersion: (dir, version) => {
const options = { git_cwd: dir }
util.fetch(options)
util.setVersion(version, options)
},
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,'\\"')
}
}
module.exports = util