Skip to content

Commit

Permalink
Fix missing files during resource copying
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhong committed Sep 9, 2018
1 parent b915275 commit 6cef6c6
Showing 1 changed file with 49 additions and 52 deletions.
101 changes: 49 additions & 52 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,59 +87,34 @@ const util = {
const braveBrowserDir = path.join(config.projects['brave-core'].dir, 'browser')
const braveAppVectorIconsDir = path.join(config.projects['brave-core'].dir, 'vector_icons', 'chrome', 'app')

let fileMap = {}
fileMap[path.join(braveAppDir, 'brave_strings.grd')] = path.join(chromeAppDir, 'brave_strings.grd')
fileMap[path.join(braveAppDir, 'settings_brave_strings.grdp')] = path.join(chromeAppDir, 'settings_brave_strings.grdp')
fileMap[path.join(braveAppDir, 'components_brave_strings.grd')] = path.join(config.srcDir, 'components', 'components_brave_strings.grd')

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')
autoGeneratedBraveToChromiumMapping[path.join(braveAppDir, 'components_brave_strings.grd')] = path.join(config.srcDir, 'components', 'components_brave_strings.grd')
Object.entries(autoGeneratedBraveToChromiumMapping).forEach(mapping => fileMap.add(mapping))

// Copy xtb files for:
// brave/app/resources/chromium_strings*.xtb
// brave/app/strings/components_chromium_strings*.xtb
// brave/app/resources/generated_resoruces*.xtb
fileMap[path.join(braveAppDir, 'resources')] = path.join(chromeAppDir, 'resources')
fileMap[path.join(braveAppDir, 'strings')] = path.join(chromeComponentsDir, 'strings')

fileMap[path.join(braveAppDir, 'theme', 'brave')] = path.join(chromeAppDir, 'theme', 'brave')
fileMap[path.join(braveAppDir, 'theme', 'default_100_percent', 'brave')] = path.join(chromeAppDir, 'theme', 'default_100_percent', 'brave')
fileMap[path.join(braveAppDir, 'theme', 'default_200_percent', 'brave')] = path.join(chromeAppDir, 'theme', 'default_200_percent', 'brave')
fileMap.add([path.join(braveAppDir, 'resources'), path.join(chromeAppDir, 'resources')])
fileMap.add([path.join(braveAppDir, 'strings'), path.join(chromeComponentsDir, 'strings')])
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')])
// By overwriting, we don't need to modify some grd files.
fileMap[path.join(braveAppDir, 'theme', 'brave')] = path.join(chromeAppDir, 'theme', 'chromium')
fileMap[path.join(braveAppDir, 'theme', 'default_100_percent', 'brave')] = path.join(chromeAppDir, 'theme', 'default_100_percent', 'chromium')
fileMap[path.join(braveAppDir, 'theme', 'default_200_percent', 'brave')] = path.join(chromeAppDir, 'theme', 'default_200_percent', 'chromium')
fileMap[path.join(braveComponentsDir, 'resources', 'default_100_percent', 'brave')] = path.join(chromeComponentsDir, 'resources', 'default_100_percent', 'chromium')
fileMap[path.join(braveComponentsDir, 'resources', 'default_200_percent', 'brave')] = path.join(chromeComponentsDir, 'resources', 'default_200_percent', 'chromium')
fileMap[path.join(braveAppVectorIconsDir, 'vector_icons', 'brave')] = path.join(chromeAppDir, 'vector_icons', 'brave')
fileMap[path.join(braveResourcesDir, 'settings', 'brave_page_visibility.js')] = path.join(chromeResourcesDir, 'settings', 'brave_page_visibility.js')
fileMap[path.join(braveResourcesDir, 'settings', 'brave_appearance_page')] = path.join(chromeResourcesDir, 'settings', 'brave_appearance_page')

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 (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 (util.calculateFileChecksum(brandingSource) != util.calculateFileChecksum(brandingDest)) {
console.log('copy branding file')
fs.copySync(brandingSource, brandingDest)
}
}

for (source in fileMap) {
fileMap.add([path.join(braveAppDir, 'theme', 'brave'), path.join(chromeAppDir, 'theme', 'brave')])
fileMap.add([path.join(braveAppDir, 'theme', 'brave'), path.join(chromeAppDir, 'theme', 'chromium')])
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')])
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')])
fileMap.add([path.join(braveResourcesDir, 'settings', 'brave_page_visibility.js'), path.join(chromeResourcesDir, 'settings', 'brave_page_visibility.js')])
fileMap.add([path.join(braveResourcesDir, 'settings', 'brave_appearance_page'), path.join(chromeResourcesDir, 'settings', 'brave_appearance_page')])

for (const [source, output] of fileMap) {
let sourceFiles = []
const output = fileMap[source]

// get all the files if source if a directory
if (fs.statSync(source).isDirectory()) {
Expand All @@ -148,12 +123,8 @@ const util = {
sourceFiles = [source]
}

for (var i in sourceFiles) {
const sourceFile = sourceFiles[i]
let destinationFile = output
if (fs.existsSync(destinationFile) && fs.statSync(destinationFile).isDirectory()) {
destinationFile = path.join(destinationFile, path.basename(sourceFile))
}
for (const sourceFile of sourceFiles) {
let destinationFile = path.join(output, path.relative(source, sourceFile))

// The destination file might be newer when updating chromium so
// we check for an exact match on the timestamp. We use seconds instead
Expand All @@ -170,6 +141,32 @@ const util = {
}
}
}

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)
}
}
},

// Chromium compares pre-installed midl files and generated midl files from IDL during the build to check integrity.
Expand Down

0 comments on commit 6cef6c6

Please sign in to comment.