2016-11-09 21:02:49 -07:00
const path = require ( 'path' )
2019-01-24 12:37:34 -08:00
const { spawn , spawnSync } = require ( 'child_process' )
2016-11-09 21:02:49 -07:00
const config = require ( './config' )
2017-01-18 19:03:26 -07:00
const fs = require ( 'fs-extra' )
2018-09-07 11:42:47 -07:00
const crypto = require ( 'crypto' )
2018-07-22 19:40:55 -04:00
const autoGeneratedBraveToChromiumMapping = Object . assign ( { } , require ( './l10nUtil' ) . autoGeneratedBraveToChromiumMapping )
2019-09-12 18:13:54 -04:00
const os = require ( 'os' )
2016-11-09 21:02:49 -07:00
2019-12-11 17:37:11 -05:00
const fixPywin32 = ( options = { } ) => {
if ( process . platform !== 'win32' ) {
return
}
console . log ( "Manually installing pywin32 python module" )
util . run ( 'python' , [ '-m' , 'pip' , 'install' , 'pywin32' ] , options )
}
2016-11-09 21:02:49 -07:00
const runGClient = ( args , options = { } ) => {
2018-06-06 17:54:19 -05:00
if ( config . gClientVerbose ) args . push ( '--verbose' )
2016-11-09 21:02:49 -07:00
options . cwd = options . cwd || config . rootDir
options = mergeWithDefault ( options )
options . env . GCLIENT _FILE = config . gClientFile
util . run ( 'gclient' , args , options )
2019-12-11 17:37:11 -05:00
fixPywin32 ( options )
2016-11-09 21:02:49 -07:00
}
const mergeWithDefault = ( options ) => {
return Object . assign ( { } , config . defaultOptions , options )
}
const util = {
run : ( cmd , args = [ ] , options = { } ) => {
2019-06-18 15:11:27 -04:00
console . log ( options . cwd + ':' , cmd , args . join ( ' ' ) )
2017-07-05 10:05:32 -07:00
const continueOnFail = options . continueOnFail
delete options . continueOnFail
2016-11-09 21:02:49 -07:00
const prog = spawnSync ( cmd , args , options )
if ( prog . status !== 0 ) {
2017-07-05 10:05:32 -07:00
if ( ! continueOnFail ) {
console . log ( prog . stdout && prog . stdout . toString ( ) )
console . error ( prog . stderr && prog . stderr . toString ( ) )
process . exit ( 1 )
}
2016-11-09 21:02:49 -07:00
}
2016-11-16 13:01:25 -07:00
return prog
2016-11-09 21:02:49 -07:00
} ,
2019-01-24 12:37:34 -08:00
runAsync : ( cmd , args = [ ] , options = { } ) => {
2019-06-19 16:54:40 -07:00
let { continueOnFail , verbose , ... cmdOptions } = options
if ( verbose ) {
console . log ( cmd , args . join ( ' ' ) )
}
2019-01-24 12:37:34 -08:00
return new Promise ( ( resolve , reject ) => {
2019-06-19 16:54:40 -07:00
const prog = spawn ( cmd , args , cmdOptions )
2019-01-24 12:37:34 -08:00
let stderr = ''
let stdout = ''
prog . stderr . on ( 'data' , data => {
stderr += data
} )
prog . stdout . on ( 'data' , data => {
stdout += data
} )
prog . on ( 'close' , statusCode => {
const hasFailed = statusCode !== 0
2019-06-19 16:54:40 -07:00
if ( verbose && ( ! hasFailed || continueOnFail ) ) {
2019-01-24 12:37:34 -08:00
console . log ( stdout )
2019-06-19 16:54:40 -07:00
if ( stderr ) {
console . error ( stderr )
}
}
if ( hasFailed ) {
const err = new Error ( ` Program ${ cmd } exited with error code ${ statusCode } . ` )
err . stderr = stderr
err . stdout = stdout
reject ( err )
if ( ! continueOnFail ) {
console . log ( err . message )
console . log ( stdout )
console . error ( stderr )
process . exit ( 1 )
}
return
2019-01-24 12:37:34 -08:00
}
resolve ( stdout )
} )
} )
} ,
2019-06-19 16:54:40 -07:00
runGitAsync : function ( repoPath , gitArgs , verbose = false , logError = false ) {
return util . runAsync ( 'git' , gitArgs , { cwd : repoPath , verbose , continueOnFail : true } )
. catch ( err => {
if ( logError ) {
console . error ( err . message )
console . error ( ` Git arguments were: ${ gitArgs . join ( ' ' ) } ` )
console . log ( err . stdout )
console . error ( err . stderr )
}
return Promise . reject ( err )
} )
} ,
2016-11-10 01:14:33 -07:00
buildGClientConfig : ( ) => {
function replacer ( key , value ) {
return value ;
}
2016-12-14 17:04:43 -07:00
let solutions = config . projectNames . filter ( ( projectName ) => config . projects [ projectName ] . ref ) . map ( ( projectName ) => {
2016-11-10 01:14:33 -07:00
let project = config . projects [ projectName ]
return {
managed : "%False%" ,
name : project . gclientName ,
url : project . url ,
custom _deps : project . custom _deps
}
} )
2019-04-16 10:44:05 +01:00
let cache _dir = process . env . GIT _CACHE _PATH ? ( '\ncache_dir = "' + process . env . GIT _CACHE _PATH + '"\n' ) : '\n'
2019-05-06 15:01:22 -07:00
let out = 'solutions = ' + JSON . stringify ( solutions , replacer , 2 )
2019-04-16 10:44:05 +01:00
. replace ( /"%None%"/g , "None" ) . replace ( /"%False%"/g , "False" ) + cache _dir
2019-05-30 15:34:50 -07:00
if ( config . targetOS === 'android' ) {
2019-05-06 15:01:22 -07:00
out = out + "target_os = [ 'android' ]"
2019-05-30 15:34:50 -07:00
} else if ( config . targetOS === 'ios' ) {
out = out + "target_os = [ 'ios' ]"
}
2019-05-06 15:01:22 -07:00
2016-11-10 01:14:33 -07:00
fs . writeFileSync ( config . defaultGClientFile , out )
} ,
2018-09-07 11:42:47 -07:00
calculateFileChecksum : ( filename ) => {
// adapted from https://github.com/roryrjb/md5-file
const BUFFER _SIZE = 8192
const fd = fs . openSync ( filename , 'r' )
const buffer = Buffer . alloc ( BUFFER _SIZE )
const md5 = crypto . createHash ( 'md5' )
try {
let bytesRead
do {
bytesRead = fs . readSync ( fd , buffer , 0 , BUFFER _SIZE )
md5 . update ( buffer . slice ( 0 , bytesRead ) )
} while ( bytesRead === BUFFER _SIZE )
} finally {
fs . closeSync ( fd )
}
return md5 . digest ( 'hex' )
} ,
2017-01-16 08:14:51 -07:00
updateBranding : ( ) => {
console . log ( 'update branding...' )
2018-02-18 19:24:57 -05:00
const chromeComponentsDir = path . join ( config . srcDir , 'components' )
2018-07-10 17:32:39 -07:00
const braveComponentsDir = path . join ( config . projects [ 'brave-core' ] . dir , 'components' )
2017-11-16 12:27:28 -07:00
const chromeAppDir = path . join ( config . srcDir , 'chrome' , 'app' )
2018-03-24 21:57:33 -04:00
const braveAppDir = path . join ( config . projects [ 'brave-core' ] . dir , 'app' )
2018-10-26 13:35:48 +09:00
const chromeBrowserResourcesDir = path . join ( config . srcDir , 'chrome' , 'browser' , 'resources' )
const braveBrowserResourcesDir = path . join ( config . projects [ 'brave-core' ] . dir , 'browser' , 'resources' )
2018-07-10 17:31:59 -07:00
const braveAppVectorIconsDir = path . join ( config . projects [ 'brave-core' ] . dir , 'vector_icons' , 'chrome' , 'app' )
2019-12-04 15:12:12 -05:00
const chromeAndroidJavaStringsTranslationsDir = path . join ( config . srcDir , 'chrome' , 'browser' , 'ui' , 'android' , 'strings' , 'translations' )
const braveAndroidJavaStringsTranslationsDir = path . join ( config . projects [ 'brave-core' ] . dir , 'browser' , 'ui' , 'android' , 'strings' , 'translations' )
2018-06-20 15:27:42 -07:00
2018-09-08 21:02:14 +09:00
let fileMap = new Set ( ) ;
// 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' )
2019-11-08 16:27:47 +09:00
autoGeneratedBraveToChromiumMapping [ path . join ( braveComponentsDir , 'components_brave_strings.grd' ) ] = path . join ( chromeComponentsDir , 'components_brave_strings.grd' )
2019-11-13 17:17:25 -05:00
2018-09-08 21:02:14 +09:00
Object . entries ( autoGeneratedBraveToChromiumMapping ) . forEach ( mapping => fileMap . add ( mapping ) )
2018-07-22 19:40:55 -04:00
// Copy xtb files for:
// brave/app/resources/chromium_strings*.xtb
// brave/app/resources/generated_resoruces*.xtb
2019-11-13 21:00:30 -05:00
// brave/components/strings/components_chromium_strings*.xtb
2019-12-04 15:12:12 -05:00
// brave/browser/ui/android/strings/translations/android_chrome_strings*.xtb
2018-09-08 21:02:14 +09:00
fileMap . add ( [ path . join ( braveAppDir , 'resources' ) , path . join ( chromeAppDir , 'resources' ) ] )
2019-11-13 21:00:30 -05:00
fileMap . add ( [ path . join ( braveComponentsDir , 'strings' ) , path . join ( chromeComponentsDir , 'strings' ) ] )
2019-11-21 21:37:29 -05:00
fileMap . add ( [ braveAndroidJavaStringsTranslationsDir , chromeAndroidJavaStringsTranslationsDir ] )
2018-06-22 13:44:48 +09:00
// By overwriting, we don't need to modify some grd files.
2018-09-08 21:02:14 +09:00
fileMap . add ( [ path . join ( braveAppDir , 'theme' , 'brave' ) , path . join ( chromeAppDir , 'theme' , 'brave' ) ] )
fileMap . add ( [ path . join ( braveAppDir , 'theme' , 'brave' ) , path . join ( chromeAppDir , 'theme' , 'chromium' ) ] )
2019-08-20 14:06:29 -07:00
fileMap . add ( [ path . join ( braveAppDir , 'theme' , 'default_100_percent' , 'brave' ) , path . join ( chromeAppDir , 'theme' , 'default_100_percent' , 'brave' ) ] )
fileMap . add ( [ path . join ( braveAppDir , 'theme' , 'default_200_percent' , 'brave' ) , path . join ( chromeAppDir , 'theme' , 'default_200_percent' , 'brave' ) ] )
2018-09-08 21:02:14 +09:00
fileMap . add ( [ path . join ( braveAppDir , 'theme' , 'default_100_percent' , 'brave' ) , path . join ( chromeAppDir , 'theme' , 'default_100_percent' , 'chromium' ) ] )
fileMap . add ( [ path . join ( braveAppDir , 'theme' , 'default_200_percent' , 'brave' ) , path . join ( chromeAppDir , 'theme' , 'default_200_percent' , 'chromium' ) ] )
2019-08-20 14:06:29 -07:00
fileMap . add ( [ path . join ( braveAppDir , 'theme' , 'default_100_percent' , 'common' ) , path . join ( chromeAppDir , 'theme' , 'default_100_percent' , 'common' ) ] )
fileMap . add ( [ path . join ( braveAppDir , 'theme' , 'default_200_percent' , 'common' ) , path . join ( chromeAppDir , 'theme' , 'default_200_percent' , 'common' ) ] )
2018-09-08 21:02:14 +09:00
fileMap . add ( [ path . join ( braveComponentsDir , 'resources' , 'default_100_percent' , 'brave' ) , path . join ( chromeComponentsDir , 'resources' , 'default_100_percent' , 'chromium' ) ] )
fileMap . add ( [ path . join ( braveComponentsDir , 'resources' , 'default_200_percent' , 'brave' ) , path . join ( chromeComponentsDir , 'resources' , 'default_200_percent' , 'chromium' ) ] )
fileMap . add ( [ path . join ( braveAppVectorIconsDir , 'vector_icons' , 'brave' ) , path . join ( chromeAppDir , 'vector_icons' , 'brave' ) ] )
2018-10-26 13:35:48 +09:00
// Copy chrome-logo-faded.png for replacing chrome logo of welcome page with brave's on Win8.
fileMap . add ( [ path . join ( braveBrowserResourcesDir , 'chrome-logo-faded.png' ) , path . join ( chromeBrowserResourcesDir , 'chrome-logo-faded.png' ) ] )
2019-08-15 22:08:36 +09:00
fileMap . add ( [ path . join ( braveBrowserResourcesDir , 'downloads' , 'images' , 'incognito_marker.svg' ) , path . join ( chromeBrowserResourcesDir , 'downloads' , 'images' , 'incognito_marker.svg' ) ] )
2018-11-02 16:27:13 +09:00
// Copy to make our ${branding_path_component}_behaviors.cc
fileMap . add ( [ path . join ( config . projects [ 'brave-core' ] . dir , 'chromium_src' , 'chrome' , 'installer' , 'setup' , 'brave_behaviors.cc' ) ,
path . join ( config . srcDir , 'chrome' , 'installer' , 'setup' , 'brave_behaviors.cc' ) ] )
2018-09-08 21:02:14 +09:00
for ( const [ source , output ] of fileMap ) {
2019-08-22 14:10:23 -07:00
if ( ! fs . existsSync ( source ) ) {
console . warn ( ` Warning: The following file-system entry was not found for copying contents to a chromium destination: ${ source } . Consider removing the entry from the file-map, or investigating whether the correct source code reference is checked out. ` )
continue
}
2018-09-06 12:48:27 -07:00
let sourceFiles = [ ]
// get all the files if source if a directory
if ( fs . statSync ( source ) . isDirectory ( ) ) {
sourceFiles = util . walkSync ( source )
} else {
sourceFiles = [ source ]
}
2018-09-08 21:02:14 +09:00
for ( const sourceFile of sourceFiles ) {
let destinationFile = path . join ( output , path . relative ( source , sourceFile ) )
2018-09-06 12:48:27 -07:00
// The destination file might be newer when updating chromium so
// we check for an exact match on the timestamp. We use seconds instead
// of ms because utimesSync doesn't set the times with ms precision
if ( ! fs . existsSync ( destinationFile ) ||
Math . floor ( new Date ( fs . statSync ( sourceFile ) . mtimeMs ) . getTime ( ) / 1000 ) !=
Math . floor ( new Date ( fs . statSync ( destinationFile ) . mtimeMs ) . getTime ( ) / 1000 ) ) {
fs . copySync ( sourceFile , destinationFile )
// can't set the date in the past so update the source file
// to match the newly copied destionation file
const date = fs . statSync ( destinationFile ) . mtime
fs . utimesSync ( sourceFile , date , date )
console . log ( sourceFile + ' copied to ' + destinationFile )
}
}
2018-07-27 10:32:32 +09:00
}
2018-09-08 21:02:14 +09:00
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.
const iconSource = path . join ( braveAppDir , 'theme' , 'brave' , 'mac' , config . channel , 'app.icns' )
const iconDest = path . join ( chromeAppDir , 'theme' , 'brave' , 'mac' , 'app.icns' )
if ( ! fs . existsSync ( iconDest ) ||
util . calculateFileChecksum ( iconSource ) != util . calculateFileChecksum ( iconDest ) ) {
console . log ( 'copy app icon' )
fs . copySync ( iconSource , iconDest )
}
// Copy branding file
let branding _file _name = 'BRANDING'
if ( config . channel )
branding _file _name = branding _file _name + '.' + config . channel
const brandingSource = path . join ( braveAppDir , 'theme' , 'brave' , branding _file _name )
const brandingDest = path . join ( chromeAppDir , 'theme' , 'brave' , 'BRANDING' )
if ( ! fs . existsSync ( brandingDest ) ||
util . calculateFileChecksum ( brandingSource ) != util . calculateFileChecksum ( brandingDest ) ) {
console . log ( 'copy branding file' )
fs . copySync ( brandingSource , brandingDest )
}
}
2019-05-30 15:34:50 -07:00
if ( config . targetOS === 'android' ) {
2019-11-15 10:25:52 -05:00
let androidIconSet = ''
if ( config . channel === 'development' ) {
androidIconSet = 'res_brave_default'
} else if ( config . channel === '' ) {
androidIconSet = 'res_brave'
} else if ( config . channel === 'beta' ) {
androidIconSet = 'res_brave_beta'
} else if ( config . channel === 'dev' ) {
androidIconSet = 'res_brave_dev'
} else if ( config . channel === 'nightly' ) {
androidIconSet = 'res_brave_nightly'
}
2019-05-24 12:05:13 -04:00
const androidIconSource = path . join ( braveAppDir , 'theme' , 'brave' , 'android' , androidIconSet )
const androidIconDest = path . join ( config . srcDir , 'chrome' , 'android' , 'java' , 'res_chromium' )
2020-04-08 13:00:50 +09:00
const androidResSource = path . join ( config . projects [ 'brave-core' ] . dir , 'android' , 'java' , 'res' )
const androidResDest = path . join ( config . srcDir , 'chrome' , 'android' , 'java' , 'res' )
const androidResNightSource = path . join ( config . projects [ 'brave-core' ] . dir , 'android' , 'java' , 'res_night' )
const androidResNightDest = path . join ( config . srcDir , 'chrome' , 'android' , 'java' , 'res_night' )
2020-01-13 09:02:59 -05:00
const androidNtpTilesResSource = path . join ( config . projects [ 'brave-core' ] . dir , 'components' , 'ntp_tiles' , 'resources' )
const androidNtpTilesResDest = path . join ( config . srcDir , 'components' , 'ntp_tiles' , 'resources' )
2020-01-15 16:08:24 +02:00
const androidResTemplateSource = path . join ( config . projects [ 'brave-core' ] . dir , 'android' , 'java' , 'res_template' )
const androidResTemplateDest = path . join ( config . srcDir , 'chrome' , 'android' , 'java' , 'res_template' )
2020-02-26 15:03:45 -05:00
const androidContentPublicResSource = path . join ( config . projects [ 'brave-core' ] . dir , 'content' , 'public' , 'android' , 'java' , 'res' )
const androidContentPublicResDest = path . join ( config . srcDir , 'content' , 'public' , 'android' , 'java' , 'res' )
2019-11-20 17:21:29 -08:00
// Mapping for copying Brave's Android resource into chromium folder.
const copyAndroidResourceMapping = {
2020-03-16 08:22:00 -04:00
[ androidIconSource ] : [ androidIconDest ] ,
2020-04-08 13:00:50 +09:00
[ androidResSource ] : [ androidResDest ] ,
[ androidResNightSource ] : [ androidResNightDest ] ,
2020-02-10 16:09:14 -05:00
[ androidNtpTilesResSource ] : [ androidNtpTilesResDest ] ,
2020-02-26 15:03:45 -05:00
[ androidResTemplateSource ] : [ androidResTemplateDest ] ,
[ androidContentPublicResSource ] : [ androidContentPublicResDest ]
2019-05-24 12:05:13 -04:00
}
2019-11-20 17:21:29 -08:00
console . log ( 'copy Android app icons and app resources' )
2020-02-10 16:09:14 -05:00
Object . entries ( copyAndroidResourceMapping ) . map ( ( [ sourcePath , destPaths ] ) => {
2019-11-20 17:21:29 -08:00
let androidSourceFiles = [ ]
if ( fs . statSync ( sourcePath ) . isDirectory ( ) ) {
androidSourceFiles = util . walkSync ( sourcePath )
} else {
androidSourceFiles = [ sourcePath ]
2019-05-24 12:05:13 -04:00
}
2019-07-22 09:58:02 -04:00
2020-02-10 16:09:14 -05:00
for ( const destPath of destPaths ) {
for ( const androidSourceFile of androidSourceFiles ) {
let destinationFile = path . join ( destPath , path . relative ( sourcePath , androidSourceFile ) )
if ( ! fs . existsSync ( destinationFile ) || util . calculateFileChecksum ( androidSourceFile ) != util . calculateFileChecksum ( destinationFile ) ) {
fs . copySync ( androidSourceFile , destinationFile )
}
2019-11-20 17:21:29 -08:00
}
2019-07-22 09:58:02 -04:00
}
2019-11-20 17:21:29 -08:00
} )
2019-05-24 12:05:13 -04:00
}
2017-01-16 08:14:51 -07:00
} ,
2018-06-26 09:20:30 +09:00
// 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 )
} ,
2019-02-11 12:59:00 +09:00
// To build w/o much modification of upstream file, bundling mode is used. To build with this mode,
// widevine header file and cdm lib is needed. So, we use fake cdm lib. It only used by gn checking.
// Real cdm lib is only donwloaded and installed when user accepts via content settings bubble
// because we don't ship cdm lib by default.
// Latest version and download url are inserted to cdm header file and brave-core refers it.
prepareWidevineCdmBuild : ( ) => {
const widevineDir = path . join ( config . srcDir , 'third_party' , 'widevine' , 'cdm' , 'linux' , 'x64' )
fs . ensureDirSync ( widevineDir )
const widevineConfig = {
widevineDir ,
headerFileContent : '' ,
configuredVersion : config . widevineVersion ,
widevineCdmHeaderFilePath : path . join ( widevineDir , 'widevine_cdm_version.h' ) ,
2019-10-07 09:33:34 -07:00
fakeWidevineCdmLibFilePath : path . join ( widevineDir , 'libwidevinecdm.so' ) ,
fakeManifestJson : path . join ( widevineDir , 'manifest.json' )
2019-02-11 12:59:00 +09:00
}
widevineConfig . headerFileContent =
` #ifndef WIDEVINE_CDM_VERSION_H_
# define WIDEVINE _CDM _VERSION _H _
# define WIDEVINE _CDM _VERSION _STRING \ "${widevineConfig.configuredVersion}\"
# define WIDEVINE _CDM _DOWNLOAD _URL _STRING \ "https://redirector.gvt1.com/edgedl/widevine-cdm/${widevineConfig.configuredVersion}-linux-x64.zip\"
# endif // WIDEVINE_CDM_VERSION_H_`
// If version file or fake lib file aren't existed, create them.
2019-10-14 21:54:27 +02:00
if ( ! fs . existsSync ( widevineConfig . widevineCdmHeaderFilePath ) ||
2019-10-07 09:33:34 -07:00
! fs . existsSync ( widevineConfig . fakeWidevineCdmLibFilePath ) ||
! fs . existsSync ( widevineConfig . fakeManifestJson ) ) {
2019-02-11 12:59:00 +09:00
util . doPrepareWidevineCdmBuild ( widevineConfig )
return
}
// Check version file has latest version. If not create it.
// This can prevent unnecessary build by touched version file.
const installedHeaderFileContent = fs . readFileSync ( widevineConfig . widevineCdmHeaderFilePath , 'utf8' )
if ( installedHeaderFileContent !== widevineConfig . headerFileContent ) {
console . log ( "Current version file includes different version with latest" )
util . doPrepareWidevineCdmBuild ( widevineConfig )
}
} ,
doPrepareWidevineCdmBuild : ( widevineConfig ) => {
console . log ( 'prepare widevine cdm build in linux' )
fs . writeFileSync ( widevineConfig . widevineCdmHeaderFilePath , widevineConfig . headerFileContent )
fs . writeFileSync ( widevineConfig . fakeWidevineCdmLibFilePath , '' )
2019-10-07 09:33:34 -07:00
fs . writeFileSync ( widevineConfig . fakeManifestJson , '{}' )
2019-02-11 12:59:00 +09:00
// During the create_dist, /usr/lib/rpm/elfdeps requires that binaries have an exectuable bit set.
fs . chmodSync ( widevineConfig . fakeWidevineCdmLibFilePath , 0o755 )
} ,
2019-01-02 16:05:30 -07:00
signApp : ( options = config . defaultOptions ) => {
console . log ( 'signing ...' )
2020-01-05 23:33:42 +09:00
if ( process . platform === 'win32' ) {
// Sign binaries used for widevine sig file generation.
// Other binaries will be done during the create_dist.
// Then, both are merged when archive for installer is created.
util . signWinBinaries ( )
} else {
util . run ( 'ninja' , [ '-C' , config . outputDir , config . signTarget ] , options )
}
2019-01-02 16:05:30 -07:00
} ,
2020-01-05 23:33:42 +09:00
// TODO(bridiver) - this should move to gn and windows should call signApp like other platforms
2019-06-12 14:04:03 +09:00
signWinBinaries : ( ) => {
2019-12-30 11:56:57 -07:00
// Copy & sign only binaries for widevine sig file generation.
2019-06-12 14:04:03 +09:00
// With this, create_dist doesn't trigger rebuild because original binaries is not modified.
const dir = path . join ( config . outputDir , 'signed_binaries' )
if ( ! fs . existsSync ( dir ) )
fs . mkdirSync ( dir ) ;
2019-06-13 07:08:36 +09:00
fs . copySync ( path . join ( config . outputDir , 'brave.exe' ) , path . join ( dir , 'brave.exe' ) ) ;
2019-06-12 14:04:03 +09:00
fs . copySync ( path . join ( config . outputDir , 'chrome.dll' ) , path . join ( dir , 'chrome.dll' ) ) ;
const core _dir = config . projects [ 'brave-core' ] . dir
util . run ( 'python' , [ path . join ( core _dir , 'script' , 'sign_binaries.py' ) , '--build_dir=' + dir ] )
} ,
2019-06-13 07:08:36 +09:00
generateWidevineSigFiles : ( ) => {
2020-01-05 23:33:42 +09:00
if ( process . platform !== 'win32' )
return
2019-06-12 14:04:03 +09:00
const cert = config . sign _widevine _cert
const key = config . sign _widevine _key
const passwd = config . sign _widevine _passwd
const sig _generator = config . signature _generator
2019-06-13 07:08:36 +09:00
let src _dir = path . join ( config . outputDir , 'signed_binaries' )
2019-06-12 14:04:03 +09:00
2019-06-13 07:08:36 +09:00
if ( config . skip _signing || process . env . CERT === undefined || process . env . SIGNTOOL _ARGS === undefined )
src _dir = config . outputDir
2019-06-12 14:04:03 +09:00
2019-06-13 07:08:36 +09:00
console . log ( 'generate Widevine sig files...' )
util . run ( 'python' , [ sig _generator , '--input_file=' + path . join ( src _dir , 'brave.exe' ) ,
2019-06-12 14:04:03 +09:00
'--flags=1' ,
'--certificate=' + cert ,
'--private_key=' + key ,
'--output_file=' + path . join ( config . outputDir , 'brave.exe.sig' ) ,
'--private_key_passphrase=' + passwd ] )
2019-06-13 07:08:36 +09:00
util . run ( 'python' , [ sig _generator , '--input_file=' + path . join ( src _dir , 'chrome.dll' ) ,
2019-06-12 14:04:03 +09:00
'--flags=0' ,
'--certificate=' + cert ,
'--private_key=' + key ,
'--output_file=' + path . join ( config . outputDir , 'chrome.dll.sig' ) ,
'--private_key_passphrase=' + passwd ] )
} ,
2018-06-06 17:54:19 -05:00
buildTarget : ( options = config . defaultOptions ) => {
console . log ( 'building ' + config . buildTarget + '...' )
2017-01-16 08:14:51 -07:00
2018-06-28 09:37:37 +09:00
if ( process . platform === 'win32' ) util . updateOmahaMidlFiles ( )
2019-02-11 12:59:00 +09:00
if ( process . platform === 'linux' ) util . prepareWidevineCdmBuild ( )
2018-06-26 09:20:30 +09:00
2018-09-20 16:51:46 +09:00
let num _compile _failure = 1
if ( config . ignore _compile _failure )
2018-10-08 13:37:11 +02:00
num _compile _failure = 0
2018-09-20 16:51:46 +09:00
2017-01-16 08:14:51 -07:00
const args = util . buildArgsToString ( config . buildArgs ( ) )
util . run ( 'gn' , [ 'gen' , config . outputDir , '--args="' + args + '"' ] , options )
2019-06-26 21:38:09 -07:00
let ninjaOpts = [
'-C' , config . outputDir , config . buildTarget ,
'-k' , num _compile _failure ,
... config . extraNinjaOpts
]
util . run ( 'ninja' , ninjaOpts , options )
2017-01-16 08:14:51 -07:00
} ,
2019-06-18 15:11:27 -04:00
generateXcodeWorkspace : ( options = config . defaultOptions ) => {
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 genArgs = [
'gen' , config . outputDir + "_Xcode" ,
'--args="' + args + '"' ,
'--ide=json' ,
'--json-ide-script="' + genScript + '"' ,
'--filters="' + config . xcode _gen _target + '"'
]
util . run ( 'gn' , genArgs , options )
} ,
2019-03-04 18:10:36 -08:00
lint : ( options = { } ) => {
if ( ! options . base ) {
options . base = 'origin/master' ;
2019-02-27 15:36:08 -08:00
}
2018-12-26 16:43:02 -07:00
let cmd _options = config . defaultOptions
cmd _options . cwd = config . projects [ 'brave-core' ] . dir
2019-10-28 10:41:46 -07:00
util . run ( 'vpython' , [ path . join ( config . rootDir , 'scripts' , 'lint.py' ) ,
2019-02-27 15:36:08 -08:00
'--project_root=' + config . srcDir ,
2019-03-04 18:10:36 -08:00
'--base_branch=' + options . base ] , cmd _options )
2018-12-26 16:43:02 -07:00
} ,
2019-09-12 18:13:54 -04:00
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
2019-11-23 22:02:55 -05:00
// file transitioning from untracked to a committed file. When
2019-09-12 18:13:54 -04:00
// 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 )
} ,
2018-05-26 19:59:44 -05:00
submoduleSync : ( options = { } ) => {
if ( ! options . cwd ) options . cwd = config . rootDir // default cwd `./src` may not exist yet
2016-11-09 21:02:49 -07:00
options = mergeWithDefault ( options )
util . run ( 'git' , [ 'submodule' , 'sync' ] , options )
util . run ( 'git' , [ 'submodule' , 'update' , '--init' , '--recursive' ] , options )
2019-09-12 18:13:54 -04:00
util . fixDepotTools ( options )
2016-11-09 21:02:49 -07:00
} ,
2018-10-17 19:45:00 -07:00
gclientSync : ( reset = false , options = { } ) => {
2020-04-10 17:41:02 -07:00
let args = [ 'sync' , '--force' , '--nohooks' , '--with_tags' , '--reset' ,
'--revision' , 'src/brave@' + config . getProjectRef ( 'brave-core' ) ]
2018-10-17 19:45:00 -07:00
if ( reset )
2020-04-10 17:41:02 -07:00
args = args . concat ( [ '--revision' , 'src@' + config . getProjectRef ( 'chrome' ) ] )
2018-10-17 19:45:00 -07:00
runGClient ( args , options )
2016-11-09 21:02:49 -07:00
} ,
gclientRunhooks : ( options = { } ) => {
runGClient ( [ 'runhooks' ] , options )
} ,
2016-11-27 19:29:59 -07:00
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 , '\\"' )
2018-09-06 12:48:27 -07:00
} ,
walkSync : ( dir , filter = null , filelist = [ ] ) => {
fs . readdirSync ( dir ) . forEach ( file => {
if ( fs . statSync ( path . join ( dir , file ) ) . isDirectory ( ) ) {
filelist = util . walkSync ( path . join ( dir , file ) , filter , filelist )
} else if ( ! filter || filter . call ( null , file ) ) {
filelist = filelist . concat ( path . join ( dir , file ) )
}
} )
return filelist
2016-11-27 19:29:59 -07:00
}
2016-11-09 21:02:49 -07:00
}
module . exports = util