Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / build / check_common.py
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import os
6
7 from trace_viewer import trace_viewer_project
8
9
10 FILE_GROUPS = ["tracing_css_files",
11                "tracing_js_html_files",
12                "tracing_img_files"]
13
14 def GetFileGroupFromFileName(filename):
15    extension = os.path.splitext(filename)[1]
16    return {
17      '.css': 'tracing_css_files',
18      '.html': 'tracing_js_html_files',
19      '.js': 'tracing_js_html_files',
20      '.png': 'tracing_img_files'
21    }[extension]
22
23 def CheckListedFilesSorted(src_file, group_name, listed_files):
24   sorted_files = sorted(listed_files)
25   if sorted_files != listed_files:
26     mismatch = ''
27     for i in range(len(listed_files)):
28       if listed_files[i] != sorted_files[i]:
29         mismatch = listed_files[i]
30         break
31     what_is = '  ' + '\n  '.join(listed_files)
32     what_should_be = '  ' + '\n  '.join(sorted_files)
33     return '''In group {0} from file {1}, filenames aren't sorted.
34
35 First mismatch:
36   {2}
37
38 Current listing:
39 {3}
40
41 Correct listing:
42 {4}\n\n'''.format(group_name, src_file, mismatch, what_is, what_should_be)
43   else:
44     return ''
45
46 def GetKnownFiles():
47   p = trace_viewer_project.TraceViewerProject()
48   m = p.loader.LoadModule(module_name='about_tracing')
49   absolute_filenames = m.GetAllDependentFilenamesRecursive(
50       include_raw_scripts=False)
51
52   return list(set([os.path.relpath(f, p.trace_viewer_path)
53                    for f in absolute_filenames]))
54
55 def CheckCommon(file_name, listed_files):
56   project = trace_viewer_project.TraceViewerProject()
57   build_dir = os.path.join(project.src_path, 'build')
58
59   known_files = GetKnownFiles()
60   u = set(listed_files).union(set(known_files))
61   i = set(listed_files).intersection(set(known_files))
62   diff = list(u - i)
63
64   if len(diff) == 0:
65     return ''
66
67   error = 'Entries in ' + file_name + ' do not match files on disk:\n'
68   in_file_only = list(set(listed_files) - set(known_files))
69   in_known_only = list(set(known_files) - set(listed_files))
70
71   if len(in_file_only) > 0:
72     error += '  In file only:\n    ' + '\n    '.join(sorted(in_file_only))
73   if len(in_known_only) > 0:
74     if len(in_file_only) > 0:
75       error += '\n\n'
76     error += '  On disk only:\n    ' + '\n    '.join(sorted(in_known_only))
77
78   return error