Skip to content

Commit 38856f7

Browse files
hujiajierogerwang
authored andcommitted
tools: upgrade patcher.py
Patches which add new files cannot be handled by patcher.py correctly, so check in an updated version of this tool from Chromium Embedded Framework (https://bitbucket.org/chromiumembedded/cef) as of commmit id 5b12134a4585f4d2f9e40c8d29292b4eb99c5ad8. Two changes were made for proper NW.js integration: 1. Fix path definition near the beginning of patcher.py in accordance with the layout of NW.js source tree. 2. Temporarily add a no-op option '--patch-config' for compatibility. The option is still needed until I remove it from chromium.src/DEPS in a follow-up patch. After that, this workaround will be removed.
1 parent 1c6e8b1 commit 38856f7

File tree

5 files changed

+236
-641
lines changed

5 files changed

+236
-641
lines changed

patch/patch.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
patches = [
22
{
33
'name': 'selenium',
4-
'path': 'src/third_party/webdriver/pylib/',
4+
'path': 'third_party/webdriver/pylib/',
55
},
66
{
77
'name': 'ffmpeg',
8-
'path': 'src/third_party/ffmpeg/',
8+
'path': 'third_party/ffmpeg/',
99
},
1010
]

tools/exec_util.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
2+
# reserved. Use of this source code is governed by a BSD-style license that
3+
# can be found in the LICENSE file
4+
5+
from subprocess import Popen, PIPE
6+
import sys
7+
8+
9+
def exec_cmd(cmd, path, input_string=None):
10+
""" Execute the specified command and return the result. """
11+
out = ''
12+
err = ''
13+
parts = cmd.split()
14+
try:
15+
if input_string is None:
16+
process = Popen(
17+
parts,
18+
cwd=path,
19+
stdout=PIPE,
20+
stderr=PIPE,
21+
shell=(sys.platform == 'win32'))
22+
out, err = process.communicate()
23+
else:
24+
process = Popen(
25+
parts,
26+
cwd=path,
27+
stdin=PIPE,
28+
stdout=PIPE,
29+
stderr=PIPE,
30+
shell=(sys.platform == 'win32'))
31+
out, err = process.communicate(input=input_string)
32+
except IOError, (errno, strerror):
33+
raise
34+
except:
35+
raise
36+
return {'out': out, 'err': err}

tools/git_util.py

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
2+
# reserved. Use of this source code is governed by a BSD-style license that
3+
# can be found in the LICENSE file
4+
5+
from exec_util import exec_cmd
6+
import os
7+
import sys
8+
9+
if sys.platform == 'win32':
10+
# Force use of the git version bundled with depot_tools.
11+
git_exe = 'git.bat'
12+
else:
13+
git_exe = 'git'
14+
15+
16+
def is_checkout(path):
17+
""" Returns true if the path represents a git checkout. """
18+
return os.path.isdir(os.path.join(path, '.git'))
19+
20+
21+
def get_hash(path='.', branch='HEAD'):
22+
""" Returns the git hash for the specified branch/tag/hash. """
23+
cmd = "%s rev-parse %s" % (git_exe, branch)
24+
result = exec_cmd(cmd, path)
25+
if result['out'] != '':
26+
return result['out'].strip()
27+
return 'Unknown'
28+
29+
30+
def get_url(path='.'):
31+
""" Returns the origin url for the specified path. """
32+
cmd = "%s config --get remote.origin.url" % git_exe
33+
result = exec_cmd(cmd, path)
34+
if result['out'] != '':
35+
return result['out'].strip()
36+
return 'Unknown'
37+
38+
39+
def get_commit_number(path='.', branch='HEAD'):
40+
""" Returns the number of commits in the specified branch/tag/hash. """
41+
cmd = "%s rev-list --count %s" % (git_exe, branch)
42+
result = exec_cmd(cmd, path)
43+
if result['out'] != '':
44+
return result['out'].strip()
45+
return '0'
46+
47+
48+
def get_changed_files(path, hash):
49+
""" Retrieves the list of changed files. """
50+
if hash == 'unstaged':
51+
cmd = "%s diff --name-only" % git_exe
52+
elif hash == 'staged':
53+
cmd = "%s diff --name-only --cached" % git_exe
54+
else:
55+
cmd = "%s diff-tree --no-commit-id --name-only -r %s" % (git_exe, hash)
56+
result = exec_cmd(cmd, path)
57+
if result['out'] != '':
58+
files = result['out']
59+
if sys.platform == 'win32':
60+
# Convert to Unix line endings.
61+
files = files.replace('\r\n', '\n')
62+
return files.strip().split("\n")
63+
return []
64+
65+
66+
def write_indented_output(output):
67+
""" Apply a fixed amount of intent to lines before printing. """
68+
if output == '':
69+
return
70+
for line in output.split('\n'):
71+
line = line.strip()
72+
if len(line) == 0:
73+
continue
74+
sys.stdout.write('\t%s\n' % line)
75+
76+
77+
def git_apply_patch_file(patch_path, patch_dir):
78+
""" Apply |patch_path| to files in |patch_dir|. """
79+
patch_name = os.path.basename(patch_path)
80+
sys.stdout.write('\nApply %s in %s\n' % (patch_name, patch_dir))
81+
82+
if not os.path.isfile(patch_path):
83+
sys.stdout.write('... patch file does not exist.\n')
84+
return 'fail'
85+
86+
patch_string = open(patch_path, 'rb').read()
87+
if sys.platform == 'win32':
88+
# Convert the patch to Unix line endings. This is necessary to avoid
89+
# whitespace errors with git apply.
90+
patch_string = patch_string.replace('\r\n', '\n')
91+
92+
# Git apply fails silently if not run relative to a respository root.
93+
if not is_checkout(patch_dir):
94+
sys.stdout.write('... patch directory is not a repository root.\n')
95+
return 'fail'
96+
97+
# Output patch contents.
98+
cmd = '%s apply -p0 --numstat' % git_exe
99+
result = exec_cmd(cmd, patch_dir, patch_string)
100+
write_indented_output(result['out'].replace('<stdin>', patch_name))
101+
102+
# Reverse check to see if the patch has already been applied.
103+
cmd = '%s apply -p0 --reverse --check' % git_exe
104+
result = exec_cmd(cmd, patch_dir, patch_string)
105+
if result['err'].find('error:') < 0:
106+
sys.stdout.write('... already applied (skipping).\n')
107+
return 'skip'
108+
109+
# Normal check to see if the patch can be applied cleanly.
110+
cmd = '%s apply -p0 --check' % git_exe
111+
result = exec_cmd(cmd, patch_dir, patch_string)
112+
if result['err'].find('error:') >= 0:
113+
sys.stdout.write('... failed to apply:\n')
114+
write_indented_output(result['err'].replace('<stdin>', patch_name))
115+
return 'fail'
116+
117+
# Apply the patch file. This should always succeed because the previous
118+
# command succeeded.
119+
cmd = '%s apply -p0' % git_exe
120+
result = exec_cmd(cmd, patch_dir, patch_string)
121+
if result['err'] == '':
122+
sys.stdout.write('... successfully applied.\n')
123+
else:
124+
sys.stdout.write('... successfully applied (with warnings):\n')
125+
write_indented_output(result['err'].replace('<stdin>', patch_name))
126+
return 'apply'

0 commit comments

Comments
 (0)