• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2016 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# Resort order of object files in libcef.ninja file.
6#
7# See: https://bitbucket.org/chromiumembedded/cef/issues/1999
8#
9# Usage:
10#   import issue_1999
11#   issue_1999.apply(output_path)
12#
13from __future__ import absolute_import
14from __future__ import print_function
15from io import open
16import sys
17import os
18
19module_order = [
20    "_sse",
21    "-sse",
22    "_ssse",
23    "-ssse",
24    "_sse2",
25    "-sse2",
26    "_ssse2",
27    "-ssse2",
28    "_sse3",
29    "-sse3",
30    "_ssse3",
31    "-ssse3",
32    "_sse4",
33    "-sse4",
34    "_ssse4",
35    "-ssse4",
36    "_avx",
37    "-avx",
38    "_savx",
39    "-savx",
40    "_avx1",
41    "-avx1",
42    "_savx1",
43    "-savx1",
44    "_avx2",
45    "-avx2",
46    "_savx2",
47    "-savx2",
48]
49
50
51def get_obj_class(item):
52  item = item.lower()
53  for i in range(len(module_order) - 1, -1, -1):
54    x = module_order[i]
55    if x in item:
56      return 1 + i
57  return 0
58
59
60def obj_compare(x, y):
61  xc = get_obj_class(x)
62  yc = get_obj_class(y)
63  if xc < yc:
64    return -1
65  elif xc > yc:
66    return 1
67  else:
68    return 0
69
70
71def process_line(line):
72  if line.startswith("build ./libcef.dll ./libcef.dll.lib: solink "):
73    index = line.find("solink")
74    if index >= 0:
75      part1 = line[0:index + 6]
76      part2 = line[index + 6:]
77      stampsIndex = part2.find("||")
78      stamps = part2[stampsIndex:]
79      objects = part2[:stampsIndex]
80
81      objects_list = objects.split()
82      objects_list = sorted(objects_list, cmp=obj_compare)
83      return part1 + " " + " ".join(objects_list) + " " + stamps
84  return line
85
86
87def process_file(path):
88  print("Applying issue #1999 fix to " + path)
89
90  with open(path, 'r', encoding='utf-8') as f:
91    content = f.read().splitlines()
92
93  result = []
94
95  for line in content:
96    result.append(process_line(line))
97
98  with open(path, 'w', encoding='utf-8') as fp:
99    str = "\n".join(result) + "\n"
100    if sys.version_info.major == 2:
101      fp.write(str.decode('utf-8'))
102    else:
103      fp.write(str)
104
105
106def apply(confpath):
107  process_file(os.path.join(confpath, "obj", "cef", "libcef.ninja"))
108