Skip to content

Commit

Permalink
Fix chromium tools/git/move_source_file.py (#13579)
Browse files Browse the repository at this point in the history
* Fix chromium tools/git/move_source_file.py

* Add npm run mass-rename

* Add a comment

* Review fixes

* mass-rename => mass_rename

* More review fixes
  • Loading branch information
atuchin-m authored Jun 22, 2022
1 parent cb98721 commit ea7f739
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
5 changes: 5 additions & 0 deletions build/commands/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,11 @@ const util = {
util.run(cmd, args, cmd_options)
},

massRename: (options = {}) => {
let cmd_options = config.defaultOptions
cmd_options.cwd = config.braveCoreDir
util.run('python3', [path.join(config.srcDir, 'tools', 'git', 'mass-rename.py')], cmd_options)
},

shouldUpdateChromium: (chromiumRef = config.getProjectRef('chrome')) => {
const headSHA = util.runGit(config.srcDir, ['rev-parse', 'HEAD'], true)
Expand Down
4 changes: 4 additions & 0 deletions build/commands/scripts/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,9 @@ program
'enables formatting of Swift file types using swift-format')
.action(util.format)

program
.command('mass_rename')
.action(util.massRename)

program
.parse(process.argv)
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"lint": "node ./build/commands/scripts/commands.js lint",
"presubmit": "node ./build/commands/scripts/commands.js presubmit",
"format": "node ./build/commands/scripts/commands.js format",
"mass_rename": "node ./build/commands/scripts/commands.js mass_rename",
"test": "node ./build/commands/scripts/commands.js test",
"test:scripts": "jest build/commands/lib build/commands/scripts",
"test-security": "npm run check_security && npm run audit_deps && npm run network-audit",
Expand Down
36 changes: 36 additions & 0 deletions patches/tools-git-move_source_file.py.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/tools/git/move_source_file.py b/tools/git/move_source_file.py
index ab57ae721179f77bb92b808e65dfe1ced8cf605f..ef3fb8f06b312609cf86e0c088e7c4804c9eef8e 100755
--- a/tools/git/move_source_file.py
+++ b/tools/git/move_source_file.py
@@ -91,6 +91,7 @@ def UpdatePostMove(from_path, to_path):
to update references in .gyp(i) files using a heuristic.
"""
# Include paths always use forward slashes.
+ from move_source_fille_utils import to_src_relative_path; from_path, to_path = to_src_relative_path(from_path, to_path)
from_path = from_path.replace('\\', '/')
to_path = to_path.replace('\\', '/')
extension = os.path.splitext(from_path)[1]
@@ -115,6 +116,7 @@ def UpdatePostMove(from_path, to_path):
mffr.MultiFileFindReplace(
r'(//.*)%s' % re.escape(from_path),
r'\1%s' % to_path,
+ ['*.gni', '*.gn'] + # Brave uses full paths (start with //) to add files
['*.cc', '*.h', '*.m', '*.mm', '*.cpp'])

# Update references in GYP and BUILD.gn files.
@@ -150,6 +152,7 @@ def UpdatePostMove(from_path, to_path):
return (parts[0], '')

visiting_directory = ''
+ from move_source_fille_utils import to_cwd_relative_path; from_path, to_path = to_cwd_relative_path(from_path, to_path)
from_rest = from_path
to_rest = to_path
while True:
@@ -186,6 +189,7 @@ def UpdateIncludeGuard(old_path, new_path):
old_guard = MakeIncludeGuardName(old_path)
new_guard = MakeIncludeGuardName(new_path)

+ from move_source_fille_utils import to_cwd_relative_path; [new_path] = to_cwd_relative_path(new_path)
with open(new_path) as f:
contents = f.read()

25 changes: 25 additions & 0 deletions script/move_source_fille_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2022 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/. */

"""This utils is used in chromium tools/git/move_source_file.py."""

import os

BRAVE_DIR_NAME = 'brave'

def _is_in_brave_dir():
return BRAVE_DIR_NAME == os.path.basename(os.getcwd())


def to_src_relative_path(*args):
if _is_in_brave_dir():
return tuple(os.path.join(BRAVE_DIR_NAME, d) for d in args)
return args


def to_cwd_relative_path(*args):
if _is_in_brave_dir():
return tuple(os.path.relpath(d, BRAVE_DIR_NAME) for d in args)
return args

0 comments on commit ea7f739

Please sign in to comment.