Skip to content

Commit

Permalink
Merge pull request #7179 from brave/79.0.3945.56-1.2.x
Browse files Browse the repository at this point in the history
Upgrade from Chromium 78.0.3904.108 to Chromium 79.0.3945.56 (1.2.x)
  • Loading branch information
bsclifton authored Dec 4, 2019
2 parents 1b1d410 + 4e34397 commit c8458c6
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 61 deletions.
15 changes: 9 additions & 6 deletions lib/chromiumRebaseL10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@
const path = require('path')
const config = require('../lib/config')
const util = require('../lib/util')
const {rebaseBraveStringFilesOnChromiumL10nFiles, braveAutoGeneratedPaths} = require('./l10nUtil')
const {rebaseBraveStringFilesOnChromiumL10nFiles, braveAutoGeneratedPaths, logRemovedGRDParts} = require('./l10nUtil')

const resetChromeStringFiles = () => {
// Revert to original before string replacement for android_chrome_strings.grd
// because original grd is overwritten with replaced one in ./src/brave.
// Revert to originals before string replacement because original grd(p)s are
// overwritten with modified versions from ./src/brave during build.
const srcDir = config.projects['chrome'].dir
const androidChromeStringsPath = path.resolve(path.join(srcDir, 'chrome', 'android', 'java', 'strings', 'android_chrome_strings.grd'))
util.run('git', ['checkout', androidChromeStringsPath], { cwd: srcDir })
const targetFilesForReset = [ "*.grd", "*.grdp" ]
targetFilesForReset.forEach((targetFile) => {
util.run('git', ['checkout', '--', targetFile], { cwd: srcDir })
})
}

const chromiumRebaseL10n = async (options) => {
resetChromeStringFiles()
await rebaseBraveStringFilesOnChromiumL10nFiles()
const removed = await rebaseBraveStringFilesOnChromiumL10nFiles()
braveAutoGeneratedPaths.forEach((sourceStringPath) => {
const cmdOptions = config.defaultOptions
cmdOptions.cwd = config.projects['brave-core'].dir
util.run('python', ['script/chromium-rebase-l10n.py', '--source_string_path', sourceStringPath], cmdOptions)
})
logRemovedGRDParts(removed)
}

module.exports = chromiumRebaseL10n
150 changes: 102 additions & 48 deletions lib/l10nUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

const path = require('path')
const fs = require('fs')
const { JSDOM } = require("jsdom")

const srcDir = path.resolve(path.join(__dirname, '..', 'src'))

Expand All @@ -29,42 +30,19 @@ const braveAndroidChromeStringsPath = path.resolve(path.join(srcDir, 'brave', 'a
// component_chromium_strings.grd and any of its parts files that we track localization for in transifex
// These map to brave/app/strings/components_chromium_strings*.xtb
const chromiumComponentsChromiumStringsPath = path.resolve(path.join(srcDir, 'components', 'components_chromium_strings.grd'))
const braveComponentsBraveStringsPath = path.resolve(path.join(srcDir, 'brave', 'app', 'components_brave_strings.grd'))
const braveComponentsBraveStringsPath = path.resolve(path.join(srcDir, 'brave', 'components', 'components_brave_strings.grd'))

// component_strings.grd and any of its parts files that we track localization for in transifex
// These map to brave/app/strings/components_strings*.xtb
// components/component_strings.grd and any of its parts files that we track localization for in transifex
// These map to brave/components/component_strings*.xtb
const chromiumComponentsStringsPath = path.resolve(path.join(srcDir, 'components', 'components_strings.grd'))
const braveComponentsStringsPath = path.resolve(path.join(srcDir, 'brave', 'app', 'components_strings.grd'))
const chromiumBookmarksBarStringsPartPath = path.resolve(path.join(srcDir, 'components', 'bookmark_bar_strings.grdp'))
const braveBookmarksBarStringsPartPath = path.resolve(path.join(srcDir, 'brave', 'app', 'bookmark_bar_strings.grdp'))
const braveComponentsStringsPath = path.resolve(path.join(srcDir, 'brave', 'components', 'components_strings.grd'))

// generated_resources.grd and any of its parts files that we track localization for in transifex
// There is also chromeos_strings.grdp but we don't need to track it here
// There is also chromeos_strings.grdp, but we don't need to track it here because it is explicitly skipped in transifex.py
// These map to brave/app/resources/generated_resoruces*.xtb
const chromiumGeneratedResourcesPath = path.resolve(path.join(srcDir, 'chrome', 'app', 'generated_resources.grd'))
const braveGeneratedResourcesPath = path.resolve(path.join(srcDir, 'brave', 'app', 'generated_resources.grd'))
const chromiumBookmarksPartPath = path.resolve(path.join(srcDir, 'chrome', 'app', 'bookmarks_strings.grdp'))
const braveBookmarksPartPath = path.resolve(path.join(srcDir, 'brave', 'app', 'bookmarks_strings.grdp'))
const chromiumMediaRouterPartPath = path.resolve(path.join(srcDir, 'chrome', 'app', 'media_router_strings.grdp'))
const braveMediaRouterPartPath = path.resolve(path.join(srcDir, 'brave', 'app', 'media_router_strings.grdp'))
const chromiumSettingsStringsPartPath = path.resolve(path.join(srcDir, 'chrome', 'app', 'settings_strings.grdp'))
const braveSettingsStringsPartPath = path.resolve(path.join(srcDir, 'brave', 'app', 'settings_strings.grdp'))
const chromiumExtensionsPartPath = path.resolve(path.join(srcDir, 'chrome', 'app', 'extensions_strings.grdp'))
const braveExtensionsPartPath = path.resolve(path.join(srcDir, 'brave', 'app', 'extensions_strings.grdp'))
const chromiumPrintingStringsPartPath = path.resolve(path.join(srcDir, 'chrome', 'app', 'printing_strings.grdp'))
const bravePrintingStringsPartPath = path.resolve(path.join(srcDir, 'brave', 'app', 'printing_strings.grdp'))
const chromiumProfileSettingsPartPath = path.resolve(path.join(srcDir, 'chrome', 'app', 'profiles_strings.grdp'))
const braveProfileSettingsPartPath = path.resolve(path.join(srcDir, 'brave', 'app', 'profiles_strings.grdp'))
const chromiumVRStringsPartPath = path.resolve(path.join(srcDir, 'chrome', 'app', 'vr_strings.grdp'))
const braveVRStringsPartPath = path.resolve(path.join(srcDir, 'brave', 'app', 'vr_strings.grdp'))
const chromiumWelcomeStringsPartPath = path.resolve(path.join(srcDir, 'chrome', 'app', 'welcome_strings.grdp'))
const braveWelcomeStringsPartPath = path.resolve(path.join(srcDir, 'brave', 'app', 'welcome_strings.grdp'))
const chromiumAppManagementStringsPartPath = path.resolve(path.join(srcDir, 'chrome', 'app', 'app_management_strings.grdp'))
const braveAppManagementStringsPartPath = path.resolve(path.join(srcDir, 'brave', 'app', 'app_management_strings.grdp'))
const chromiumGlobalMediaControlsStringsPartPath = path.resolve(path.join(srcDir, 'chrome', 'app', 'global_media_controls_strings.grdp'))
const braveGlobalMediaControlsStringsPartPath = path.resolve(path.join(srcDir, 'brave', 'app', 'global_media_controls_strings.grdp'))
const chromiumSupervisedUserErrorPageStringsPartPath = path.resolve(path.join(srcDir, 'chrome', 'app', 'supervised_user_error_page_strings.grdp'))
const braveSupervisedUserErrorPageStringsPartPath = path.resolve(path.join(srcDir, 'brave', 'app', 'supervised_user_error_page_strings.grdp'))
const chromiumGeneratedResourcesExcludes = new Set(["chromeos_strings.grdp"])

// The following are not generated files but still need to be tracked so they get sent to transifex
// These xtb files don't need to be copied anywhere.
Expand All @@ -76,30 +54,67 @@ const braveResourcesComponentsStringsPath = path.resolve(path.join(srcDir, 'brav
const braveExtensionMessagesPath = path.resolve(path.join(srcDir, 'brave', 'components', 'brave_extension', 'extension', 'brave_extension', '_locales', 'en_US', 'messages.json'))
const braveRewardsExtensionMessagesPath = path.resolve(path.join(srcDir, 'brave', 'components', 'brave_rewards', 'resources', 'extension', 'brave_rewards', '_locales', 'en_US', 'messages.json'))

// When adding new grd or grd files, never add a grdp part path without a parent grd path.
// Group them with a leading and trailing newline to keep this file organized.
const srcGit = path.resolve(path.join(srcDir, '.git'))

// Helper function to find all grdp parts in a grd.
function getGrdPartsFromGrd(path) {
const grd = new JSDOM(fs.readFileSync(path, 'utf8'))
const partTags = grd.window.document.getElementsByTagName("part")
let parts = new Array()
for (const partTag of partTags) {
parts.push(partTag.getAttribute('file'));
}
return parts
}

// Helper function to create a mapping for grd and all of its grdp parts.
function AddGrd(chromiumPath, bravePath, exclude = new Set()) {
if (!fs.existsSync(srcGit)) {
// Chromium repository has not been initialized yet.
return
}
console.log("Adding mappings for GRD: " + chromiumPath)
let mapping = {
[chromiumPath]: bravePath
}
if (!fs.existsSync(chromiumPath)) {
console.log(" - Error: File not found.")
// Keep going to cause an exception.
}
const grdps = getGrdPartsFromGrd(chromiumPath)
if (grdps.length) {
const chromiumDir = path.dirname(chromiumPath)
const braveDir = path.dirname(bravePath)
for (const grdp of grdps) {
if (exclude.has(grdp)) {
continue
}
mapping[path.resolve(path.join(chromiumDir, grdp))] = path.resolve(path.join(braveDir, grdp))
}
console.log(" - Added " + (Object.keys(mapping).length - 1) + " GRDP.")
}
return mapping
}

// Add all GRD mappings here.
// Brave specific only grd and grdp files should NOT be added.
// Using AddGrd will add GRD and all of its GRDPs.
const grdsWithAutoAddedGrdps = {
...AddGrd(chromiumComponentsStringsPath, braveComponentsStringsPath),
...AddGrd(chromiumGeneratedResourcesPath, braveGeneratedResourcesPath, chromiumGeneratedResourcesExcludes),
...AddGrd(androidChromeStringsPath, braveAndroidChromeStringsPath)
}

// Add all mappings here whether it is a GRD or a GRDP.
// Brave specific only grd and grdp files should not be added here.
// When adding new grd or grdp files, never add a grdp part path without a parent grd path.
// Group them with a leading and trailing newline to keep this file organized.
// The first 3 are added explicitly because we change the file names.
const chromiumToAutoGeneratedBraveMapping = {
[chromiumStringsPath]: braveStringsPath,
[chromiumSettingsPartPath]: braveSettingsPartPath,

[chromiumComponentsChromiumStringsPath]: braveComponentsBraveStringsPath,
[chromiumComponentsStringsPath]: braveComponentsStringsPath,
[chromiumBookmarksBarStringsPartPath]: braveBookmarksBarStringsPartPath,
[chromiumGeneratedResourcesPath]: braveGeneratedResourcesPath,
[chromiumBookmarksPartPath]: braveBookmarksPartPath,
[chromiumMediaRouterPartPath]: braveMediaRouterPartPath,
[chromiumSettingsStringsPartPath]: braveSettingsStringsPartPath,
[chromiumExtensionsPartPath]: braveExtensionsPartPath,
[chromiumPrintingStringsPartPath]: bravePrintingStringsPartPath,
[chromiumProfileSettingsPartPath]: braveProfileSettingsPartPath,
[chromiumVRStringsPartPath]: braveVRStringsPartPath,
[chromiumWelcomeStringsPartPath]: braveWelcomeStringsPartPath,
[chromiumAppManagementStringsPartPath]: braveAppManagementStringsPartPath,
[chromiumGlobalMediaControlsStringsPartPath]: braveGlobalMediaControlsStringsPartPath,
[chromiumSupervisedUserErrorPageStringsPartPath]: braveSupervisedUserErrorPageStringsPartPath,
[androidChromeStringsPath]: braveAndroidChromeStringsPath

...grdsWithAutoAddedGrdps
}

// Same as with chromiumToAutoGeneratedBraveMapping but maps in the opposite direction
Expand Down Expand Up @@ -130,11 +145,49 @@ module.exports.ethereumRemoteClientPaths = [
'../../../ethereum-remote-client/brave/app/_locales/en/messages.json'
]

// Helper functions that's, for a given pair of chromium to brave GRD mapping
// from the supplied map, determines which GRDP parts are no longer present in
// the chromium GRD file.
function getRemovedGRDParts(mapping) {
let removedMap = new Map()
for (const [sourcePath, destPath] of Object.entries(mapping)) {
if (path.extname(destPath) === ".grd") {
const braveGRDPs = getGrdPartsFromGrd(destPath)
const chromiumGRDPs = getGrdPartsFromGrd(sourcePath)
let removed = new Set()
for (i = 0; i < braveGRDPs.length; i++) {
if (!chromiumGRDPs.includes(braveGRDPs[i])) {
removed.add(braveGRDPs[i])
}
}
if (removed.size) {
removedMap.set(destPath, removed)
}
}
}
return removedMap
}

// Helper function to pretty print removed GRDP file names.
module.exports.logRemovedGRDParts = function (mapping) {
if (mapping.size) {
console.log("\n**************************************************************************")
console.log("The following GRDP files are no longer in the corresponding Chromium GRDs:\n")
for (const [grd, grdps] of mapping.entries()) {
console.log(" From " + grd + ":")
for (const grdp of grdps) {
console.log(" - " + grdp)
}
}
}
}

// This simply reads Chromium files that are passed to it and replaces branding strings
// with Brave specific branding strings.
// Do not use this for filtering XML, instead use chromium-rebase-l10n.py.
// Only add idempotent replacements here (i.e. don't append replace A with AX here)
module.exports.rebaseBraveStringFilesOnChromiumL10nFiles = async function (path) {
const removedMap = getRemovedGRDParts(grdsWithAutoAddedGrdps)
const ops = Object.entries(chromiumToAutoGeneratedBraveMapping).map(async ([sourcePath, destPath]) => {
let contents = await new Promise(resolve => fs.readFile(sourcePath, 'utf8', (err, data) => resolve(data)))
for (const replacement of defaultReplacements) {
Expand All @@ -143,6 +196,7 @@ module.exports.rebaseBraveStringFilesOnChromiumL10nFiles = async function (path)
await new Promise(resolve => fs.writeFile(destPath, contents, 'utf8', resolve))
})
await Promise.all(ops)
return removedMap
}

// Straight-forward string replacement list.
Expand Down
14 changes: 8 additions & 6 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,25 @@ const util = {
const chromeBrowserResourcesDir = path.join(config.srcDir, 'chrome', 'browser', 'resources')
const braveBrowserResourcesDir = path.join(config.projects['brave-core'].dir, 'browser', 'resources')
const braveAppVectorIconsDir = path.join(config.projects['brave-core'].dir, 'vector_icons', 'chrome', 'app')
const chromeAndroidDir = path.join(config.srcDir, 'chrome', 'android')
const braveAndroidDir = path.join(config.projects['brave-core'].dir, 'android')
const chromeAndroidJavaStringsTranslationsDir = path.join(config.srcDir, 'chrome', 'android', 'java', 'strings', 'translations')
const braveAndroidJavaStringsTranslationsDir = path.join(config.projects['brave-core'].dir, 'android', 'java', 'strings', 'translations')

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')
autoGeneratedBraveToChromiumMapping[path.join(braveAndroidDir, 'java', 'strings', 'android_chrome_strings.grd')] = path.join(chromeAndroidDir, 'java', 'strings', 'android_chrome_strings.grd')
autoGeneratedBraveToChromiumMapping[path.join(braveComponentsDir, 'components_brave_strings.grd')] = path.join(chromeComponentsDir, '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
// brave/components/strings/components_chromium_strings*.xtb
// brave/android/java/strings/translations/android_chrome_strings*.xtb
fileMap.add([path.join(braveAppDir, 'resources'), path.join(chromeAppDir, 'resources')])
fileMap.add([path.join(braveAppDir, 'strings'), path.join(chromeComponentsDir, 'strings')])
fileMap.add([path.join(braveComponentsDir, 'strings'), path.join(chromeComponentsDir, 'strings')])
fileMap.add([braveAndroidJavaStringsTranslationsDir, chromeAndroidJavaStringsTranslationsDir])
// By overwriting, we don't need to modify some grd files.
fileMap.add([path.join(braveAppDir, 'theme', 'brave'), path.join(chromeAppDir, 'theme', 'brave')])
fileMap.add([path.join(braveAppDir, 'theme', 'brave'), path.join(chromeAppDir, 'theme', 'chromium')])
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"projects": {
"chrome": {
"dir": "src",
"tag": "78.0.3904.108",
"tag": "79.0.3945.56",
"repository": {
"url": "https://chromium.googlesource.com/chromium/src.git"
},
Expand Down

0 comments on commit c8458c6

Please sign in to comment.