Skip to content

Commit

Permalink
Make check_gn_headers.py run on Windows
Browse files Browse the repository at this point in the history
BUG=661774

Review-Url: https://codereview.chromium.org/2914323002
Cr-Commit-Position: refs/heads/master@{#478848}
  • Loading branch information
wychen authored and Commit Bot committed Jun 13, 2017
1 parent 4d8a7c1 commit 97580de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
18 changes: 12 additions & 6 deletions build/check_gn_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def ParseNinjaDepsOutput(ninja_out, out_dir):
"""Parse ninja output and get the header files"""
all_headers = set()

prefix = '..' + os.sep + '..' + os.sep
# Ninja always uses "/", even on Windows.
prefix = '../../'

is_valid = False
for line in ninja_out:
Expand Down Expand Up @@ -82,12 +83,15 @@ def GetHeadersFromGN(out_dir, q):
tmp = None
ans, err = set(), None
try:
tmp = tempfile.mkdtemp()
# Argument |dir| is needed to make sure it's on the same drive on Windows.
# dir='' means dir='.', but doesn't introduce an unneeded prefix.
tmp = tempfile.mkdtemp(dir='')
shutil.copy2(os.path.join(out_dir, 'args.gn'),
os.path.join(tmp, 'args.gn'))
# Do "gn gen" in a temp dir to prevent dirtying |out_dir|.
gn_exe = 'gn.bat' if sys.platform == 'win32' else 'gn'
subprocess.check_call([
os.path.join(DEPOT_TOOLS_DIR, 'gn'), 'gen', tmp, '--ide=json', '-q'])
os.path.join(DEPOT_TOOLS_DIR, gn_exe), 'gen', tmp, '--ide=json', '-q'])
gn_json = json.load(open(os.path.join(tmp, 'project.json')))
ans = ParseGNProjectJSON(gn_json, out_dir, tmp)
except Exception as e:
Expand Down Expand Up @@ -123,10 +127,12 @@ def GetDepsPrefixes(q):
"""Return all the folders controlled by DEPS file"""
prefixes, err = set(), None
try:
gclient_exe = 'gclient.bat' if sys.platform == 'win32' else 'gclient'
gclient_out = subprocess.check_output([
os.path.join(DEPOT_TOOLS_DIR, 'gclient'),
'recurse', '--no-progress', '-j1',
'python', '-c', 'import os;print os.environ["GCLIENT_DEP_PATH"]'])
os.path.join(DEPOT_TOOLS_DIR, gclient_exe),
'recurse', '--no-progress', '-j1',
'python', '-c', 'import os;print os.environ["GCLIENT_DEP_PATH"]'],
universal_newlines=True)
for i in gclient_out.split('\n'):
if i.startswith('src/'):
i = i[4:]
Expand Down
17 changes: 0 additions & 17 deletions build/check_gn_headers_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
../../dir3/path/b.h
../../c3.hh
'''
ninja_input_win = ninja_input.replace('/', '\\')


gn_input = json.loads(r'''
Expand Down Expand Up @@ -75,22 +74,6 @@ def testNinja(self):
])
self.assertEquals(headers, expected)

def testNinjaWin(self):
old_sep = os.sep
os.sep = '\\'

headers = check_gn_headers.ParseNinjaDepsOutput(
ninja_input_win.split('\n'), 'out\\Release')
expected = set([
'dir\\path\\b.h',
'c.hh',
'dir3\\path\\b.h',
'c3.hh',
])
self.assertEquals(headers, expected)

os.sep = old_sep

def testGn(self):
headers = check_gn_headers.ParseGNProjectJSON(gn_input,
'out/Release', 'tmp')
Expand Down

0 comments on commit 97580de

Please sign in to comment.