Skip to content

Commit 9b8d070

Browse files
committed
add support for building/running signed app in development
fix brave#2794
1 parent 05acd52 commit 9b8d070

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

lib/build.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ const build = (buildConfig = config.defaultBuildConfig, options) => {
9797
util.updateBranding()
9898

9999
util.buildTarget()
100+
if (config.shouldSign()) {
101+
util.signApp()
102+
}
100103
}
101104

102105
module.exports = build

lib/config.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const Config = function () {
2020
this.buildConfig = this.defaultBuildConfig
2121
this.projectNames = []
2222
this.projects = {}
23+
this.signTarget = 'sign_app'
2324
this.buildTarget = 'brave'
2425
this.rootDir = path.join(path.dirname(__filename), '..')
2526
this.scriptDir = path.join(this.rootDir, 'scripts')
@@ -45,6 +46,7 @@ const Config = function () {
4546
this.mac_signing_identifier = getNPMConfig(['mac_signing_identifier']) || ''
4647
this.mac_installer_signing_identifier = getNPMConfig(['mac_installer_signing_identifier']) || ''
4748
this.mac_signing_keychain = getNPMConfig(['mac_signing_keychain']) || 'login'
49+
this.mac_signing_output_prefix = 'signing'
4850
this.channel = ''
4951
this.sccache = getNPMConfig(['sccache'])
5052
this.braveReferralsApiKey = getNPMConfig(['brave_referrals_api_key']) || ''
@@ -93,6 +95,7 @@ Config.prototype.buildArgs = function () {
9395
args.mac_signing_identifier = this.mac_signing_identifier
9496
args.mac_installer_signing_identifier = this.mac_installer_signing_identifier
9597
args.mac_signing_keychain = this.mac_signing_keychain
98+
args.mac_signing_output_prefix = this.mac_signing_output_prefix
9699
}
97100

98101
if (process.platform === 'win32' && this.build_omaha) {
@@ -132,6 +135,12 @@ Config.prototype.buildArgs = function () {
132135
return args
133136
}
134137

138+
Config.prototype.shouldSign = function () {
139+
// it doesn't make sense to sign debug builds because the restrictions on loading
140+
// dynamic libs prevents them from working anyway
141+
return this.mac_signing_identifier !== '' && this.buildConfig === 'Release'
142+
}
143+
135144
Config.prototype.prependPath = function (oldPath, addPath) {
136145
let newPath = oldPath.split(path.delimiter)
137146
newPath.unshift(addPath)
@@ -310,17 +319,6 @@ Config.prototype.update = function (options) {
310319
})
311320
}
312321

313-
if (process.platform === 'darwin') {
314-
Config.prototype.macAppName = function () {
315-
let app_name = 'Brave\\ Browser'
316-
if (this.channel) {
317-
// Capitalize channel name and append it to make app name like Brave Browser Beta
318-
app_name = app_name + '\\ ' + this.channel.charAt(0).toUpperCase() + this.channel.slice(1)
319-
}
320-
return app_name
321-
}
322-
}
323-
324322
Object.defineProperty(Config.prototype, 'defaultOptions', {
325323
get: function () {
326324
let env = Object.assign({}, process.env)

lib/start.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,13 @@ const start = (passthroughArgs, buildConfig = config.defaultBuildConfig, options
9797
let outputPath = options.output_path
9898
if (!outputPath) {
9999
if (process.platform === 'darwin') {
100-
outputPath = path.join(config.outputDir, config.macAppName() + '.app', 'Contents', 'MacOS', config.macAppName())
100+
let outputDir = config.outputDir
101+
if (config.shouldSign()) {
102+
outputDir = path.join(outputDir, config.mac_signing_output_prefix)
103+
}
104+
outputPath = path.join(outputDir,
105+
'Brave\\ Browser\\ Development.app', 'Contents', 'MacOS',
106+
'Brave\\ Browser\\ Development')
101107
} else if (process.platform === 'win32') {
102108
outputPath = path.join(config.outputDir, 'brave.exe')
103109
} else {

lib/util.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ const util = {
182182
fs.copySync(srcDir, dstDir)
183183
},
184184

185+
signApp: (options = config.defaultOptions) => {
186+
console.log('signing ...')
187+
188+
util.run('ninja', ['-C', config.outputDir, config.signTarget], options)
189+
},
190+
185191
buildTarget: (options = config.defaultOptions) => {
186192
console.log('building ' + config.buildTarget + '...')
187193

0 commit comments

Comments
 (0)