]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/tools/quickbook/test/python/output-deps.py
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / tools / quickbook / test / python / output-deps.py
CommitLineData
7c673cae
FG
1#!/usr/bin/env python
2
3# Copyright 2012-2013 Daniel James
4# Distributed under the Boost Software License, Version 1.0.
5# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
6
7import sys, os, subprocess, tempfile, re
8
9def main(args, directory):
10 if len(args) != 1:
11 print "Usage: output-deps.py quickbook-command"
12 exit(1)
13 quickbook_command = args[0]
14
15 failures = 0
16 failures += run_quickbook(quickbook_command, 'svg_missing.qbk',
17 deps_gold = 'svg_missing_deps.txt')
18 failures += run_quickbook(quickbook_command, 'svg_missing.qbk',
19 locations_gold = 'svg_missing_locs.txt')
20 failures += run_quickbook(quickbook_command, 'missing_relative.qbk',
21 deps_gold = 'missing_relative_deps.txt',
22 locations_gold = 'missing_relative_locs.txt')
23 failures += run_quickbook(quickbook_command, 'include_path.qbk',
24 deps_gold = 'include_path_deps.txt',
25 locations_gold = 'include_path_locs.txt',
26 input_path = ['sub1', 'sub2'])
27 failures += run_quickbook(quickbook_command, 'include_glob.qbk',
28 deps_gold = 'include_glob_deps.txt',
29 locations_gold = 'include_glob_locs.txt',
30 input_path = ['sub1', 'sub2'])
31
32 if failures == 0:
33 print "Success"
34 else:
35 print "Failures:",failures
36 exit(failures)
37
38def run_quickbook(quickbook_command, filename, output_gold = None,
39 deps_gold = None, locations_gold = None, input_path = []):
40 failures = 0
41
42 command = [quickbook_command, '--debug', filename]
43
44 output_filename = None
45 if output_gold:
46 output_filename = temp_filename('.qbk')
47 command.extend(['--output-file', output_filename])
48
49 deps_filename = None
50 if deps_gold:
51 deps_filename = temp_filename('.txt')
52 command.extend(['--output-deps', deps_filename])
53
54 locations_filename = None
55 if locations_gold:
56 locations_filename = temp_filename('.txt')
57 command.extend(['--output-checked-locations', locations_filename])
58
59 try:
60 for path in input_path:
61 command.extend(['-I', path])
62 print 'Running: ' + ' '.join(command)
63 print
64 exit_code = subprocess.call(command)
65 print
66 success = not exit_code
67
68 if output_filename:
69 output = load_file(output_filename)
70 else:
71 output = None
72
73 if deps_filename:
74 deps = load_dependencies(deps_filename)
75 else:
76 deps = None
77
78 if locations_filename:
79 locations = load_locations(locations_filename)
80 else:
81 locations = None
82 finally:
83 if output_filename: os.unlink(output_filename)
84 if deps_filename: os.unlink(deps_filename)
85
86 if deps_gold:
87 gold = load_dependencies(deps_gold, adjust_paths = True)
88 if deps != gold:
89 failures = failures + 1
90 print "Dependencies don't match:"
91 print "Gold:", gold
92 print "Result:", deps
93 print
94
95 if locations_gold:
96 gold = load_locations(locations_gold, adjust_paths = True)
97 if locations != gold:
98 failures = failures + 1
99 print "Dependencies don't match:"
100 print "Gold:", gold
101 print "Result:", locations
102 print
103
104 if output_gold:
105 gold = load_file(output_gold)
106 if gold != output:
107 failures = failures + 1
108 print "Output doesn't match:"
109 print
110 print gold
111 print
112 print output
113 print
114
115 return failures
116
117def load_dependencies(filename, adjust_paths = False):
118 dependencies = set()
119 f = open(filename, 'r')
120 for path in f:
121 if path[0] == '#': continue
122 if adjust_paths:
123 path = os.path.realpath(path)
124 if path in dependencies:
125 raise Exception("Duplicate path (%1s) in %2s" % (path, filename))
126 dependencies.add(path)
127 return dependencies
128
129def load_locations(filename, adjust_paths = False):
130 line_matcher = re.compile("^([+-g]) (.*)$")
131 dependencies = {}
132 f = open(filename, 'r')
133 glob = None
134 globs = {}
135 for line in f:
136 if line[0] == '#': continue
137 m = line_matcher.match(line)
138
139 path = m.group(2)
140 if adjust_paths:
141 path = os.path.realpath(path)
142
143 if not m:
144 raise Exception("Invalid dependency file: %1s" % filename)
145 if m.group(1) == 'g':
146 globs[path] = []
147 glob = path
148 elif glob:
149 if m.group(1) != '+':
150 raise Exception("Negative match in glob.")
151 globs[glob].append(path)
152 else:
153 found = m.group(1) == '+'
154 if path in dependencies:
155 raise Exception("Duplicate path (%1s) in %2s" % (path, filename))
156 dependencies[path] = found
157 return { 'dependencies': dependencies, 'globs': globs }
158
159def temp_filename(extension):
160 file = tempfile.mkstemp(suffix = extension)
161 os.close(file[0])
162 return file[1]
163
164def load_file(filename):
165 f = open(filename, 'r')
166 try:
167 return f.read()
168 finally:
169 f.close()
170
171 return None
172
173main(sys.argv[1:], os.path.dirname(sys.argv[0]))