chromium-src-build/check_gn_headers_unittest.py

102 строки
2.2 KiB
Python
Исходник Обычный вид История

#!/usr/bin/env python
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
import json
import unittest
import check_gn_headers
ninja_input = r'''
obj/a.o: #deps 1, deps mtime 123 (VALID)
../../a.cc
../../dir/path/b.h
../../c.hh
obj/b.o: #deps 1, deps mtime 123 (STALE)
../../b.cc
../../dir2/path/b.h
../../c2.hh
obj/c.o: #deps 1, deps mtime 123 (VALID)
../../c.cc
../../build/a.h
gen/b.h
../../out/Release/gen/no.h
../../dir3/path/b.h
../../c3.hh
'''
gn_input = json.loads(r'''
{
"others": [],
"targets": {
"//:All": {
},
"//:base": {
"public": [ "//base/p.h" ],
"sources": [ "//base/a.cc", "//base/a.h", "//base/b.hh" ],
"visibility": [ "*" ]
},
"//:star_public": {
"public": "*",
Reland of Add helpful error messages to check_gn_headers.py (patchset #1 id:1 of https://codereview.chromium.org/2905863002/ ) Reason for revert: The real culprit is https://crrev.com/2903733004/, which was reverted. This CL (https://crrev.com/2891363004) made it fail more gracefully, and should be kept. Original issue's description: > Revert of Add helpful error messages to check_gn_headers.py (patchset #3 id:40001 of https://codereview.chromium.org/2891363004/ ) > > Reason for revert: > This CL is likely causing massive failures: > > https://build.chromium.org/p/chromium.linux/builders/Linux%20Builder/builds/84473 > to > https://build.chromium.org/p/chromium.linux/builders/Linux%20Builder/builds/84498 > > and > > https://build.chromium.org/p/chromium.linux/builders/Linux%20Builder%20%28dbg%29/builds/111528 > to > https://build.chromium.org/p/chromium.linux/builders/Linux%20Builder%20%28dbg%29/builds/111542 > > Original issue's description: > > Add helpful error messages to check_gn_headers.py > > > > Before running check_gn_headers.py, it is necessary to build all > > in order to get the dependency info from the compiler. Directly > > checking whether rebuilding is needed by running a build dry run > > takes too long, so some heuristics are used instead. > > > > BUG=661774 > > > > Review-Url: https://codereview.chromium.org/2891363004 > > Cr-Commit-Position: refs/heads/master@{#474588} > > Committed: https://chromium.googlesource.com/chromium/src/+/0ceaba5ef538ce1780578d5e948641bc27f5829b > > TBR=dpranke@chromium.org,tfarina@chromium.org,wychen@chromium.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=661774 > > Review-Url: https://codereview.chromium.org/2905863002 > Cr-Commit-Position: refs/heads/master@{#474649} > Committed: https://chromium.googlesource.com/chromium/src/+/d3c2681426db53550547f2bc115c3f72ba40f276 TBR=dpranke@chromium.org,tfarina@chromium.org,mahmadi@chromium.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=661774 Review-Url: https://codereview.chromium.org/2907683002 Cr-Original-Commit-Position: refs/heads/master@{#474786} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 0362911661559a7edca7d4ca9c36f1091a527b04
2017-05-25 23:37:18 +03:00
"sources": [ "//base/c.h", "//tmp/gen/a.h" ],
"visibility": [ "*" ]
}
}
}
''')
whitelist = r'''
white-front.c
a/b/c/white-end.c # comment
dir/white-both.c #more comment
# empty line above
a/b/c
'''
class CheckGnHeadersTest(unittest.TestCase):
def testNinja(self):
headers = check_gn_headers.ParseNinjaDepsOutput(
ninja_input.split('\n'), 'out/Release', False)
expected = {
'dir/path/b.h': ['obj/a.o'],
'c.hh': ['obj/a.o'],
'dir3/path/b.h': ['obj/c.o'],
'c3.hh': ['obj/c.o'],
}
self.assertEquals(headers, expected)
def testGn(self):
Reland of Add helpful error messages to check_gn_headers.py (patchset #1 id:1 of https://codereview.chromium.org/2905863002/ ) Reason for revert: The real culprit is https://crrev.com/2903733004/, which was reverted. This CL (https://crrev.com/2891363004) made it fail more gracefully, and should be kept. Original issue's description: > Revert of Add helpful error messages to check_gn_headers.py (patchset #3 id:40001 of https://codereview.chromium.org/2891363004/ ) > > Reason for revert: > This CL is likely causing massive failures: > > https://build.chromium.org/p/chromium.linux/builders/Linux%20Builder/builds/84473 > to > https://build.chromium.org/p/chromium.linux/builders/Linux%20Builder/builds/84498 > > and > > https://build.chromium.org/p/chromium.linux/builders/Linux%20Builder%20%28dbg%29/builds/111528 > to > https://build.chromium.org/p/chromium.linux/builders/Linux%20Builder%20%28dbg%29/builds/111542 > > Original issue's description: > > Add helpful error messages to check_gn_headers.py > > > > Before running check_gn_headers.py, it is necessary to build all > > in order to get the dependency info from the compiler. Directly > > checking whether rebuilding is needed by running a build dry run > > takes too long, so some heuristics are used instead. > > > > BUG=661774 > > > > Review-Url: https://codereview.chromium.org/2891363004 > > Cr-Commit-Position: refs/heads/master@{#474588} > > Committed: https://chromium.googlesource.com/chromium/src/+/0ceaba5ef538ce1780578d5e948641bc27f5829b > > TBR=dpranke@chromium.org,tfarina@chromium.org,wychen@chromium.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=661774 > > Review-Url: https://codereview.chromium.org/2905863002 > Cr-Commit-Position: refs/heads/master@{#474649} > Committed: https://chromium.googlesource.com/chromium/src/+/d3c2681426db53550547f2bc115c3f72ba40f276 TBR=dpranke@chromium.org,tfarina@chromium.org,mahmadi@chromium.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=661774 Review-Url: https://codereview.chromium.org/2907683002 Cr-Original-Commit-Position: refs/heads/master@{#474786} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 0362911661559a7edca7d4ca9c36f1091a527b04
2017-05-25 23:37:18 +03:00
headers = check_gn_headers.ParseGNProjectJSON(gn_input,
'out/Release', 'tmp')
expected = set([
'base/a.h',
'base/b.hh',
'base/c.h',
'base/p.h',
Reland of Add helpful error messages to check_gn_headers.py (patchset #1 id:1 of https://codereview.chromium.org/2905863002/ ) Reason for revert: The real culprit is https://crrev.com/2903733004/, which was reverted. This CL (https://crrev.com/2891363004) made it fail more gracefully, and should be kept. Original issue's description: > Revert of Add helpful error messages to check_gn_headers.py (patchset #3 id:40001 of https://codereview.chromium.org/2891363004/ ) > > Reason for revert: > This CL is likely causing massive failures: > > https://build.chromium.org/p/chromium.linux/builders/Linux%20Builder/builds/84473 > to > https://build.chromium.org/p/chromium.linux/builders/Linux%20Builder/builds/84498 > > and > > https://build.chromium.org/p/chromium.linux/builders/Linux%20Builder%20%28dbg%29/builds/111528 > to > https://build.chromium.org/p/chromium.linux/builders/Linux%20Builder%20%28dbg%29/builds/111542 > > Original issue's description: > > Add helpful error messages to check_gn_headers.py > > > > Before running check_gn_headers.py, it is necessary to build all > > in order to get the dependency info from the compiler. Directly > > checking whether rebuilding is needed by running a build dry run > > takes too long, so some heuristics are used instead. > > > > BUG=661774 > > > > Review-Url: https://codereview.chromium.org/2891363004 > > Cr-Commit-Position: refs/heads/master@{#474588} > > Committed: https://chromium.googlesource.com/chromium/src/+/0ceaba5ef538ce1780578d5e948641bc27f5829b > > TBR=dpranke@chromium.org,tfarina@chromium.org,wychen@chromium.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=661774 > > Review-Url: https://codereview.chromium.org/2905863002 > Cr-Commit-Position: refs/heads/master@{#474649} > Committed: https://chromium.googlesource.com/chromium/src/+/d3c2681426db53550547f2bc115c3f72ba40f276 TBR=dpranke@chromium.org,tfarina@chromium.org,mahmadi@chromium.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=661774 Review-Url: https://codereview.chromium.org/2907683002 Cr-Original-Commit-Position: refs/heads/master@{#474786} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 0362911661559a7edca7d4ca9c36f1091a527b04
2017-05-25 23:37:18 +03:00
'out/Release/gen/a.h',
])
self.assertEquals(headers, expected)
def testWhitelist(self):
output = check_gn_headers.ParseWhiteList(whitelist)
expected = set([
'white-front.c',
'a/b/c/white-end.c',
'dir/white-both.c',
'a/b/c',
])
self.assertEquals(output, expected)
if __name__ == '__main__':
logging.getLogger().setLevel(logging.DEBUG)
unittest.main(verbosity=2)