4
4
import os
5
5
import re
6
6
7
+
7
8
def main ():
8
9
p = argparse .ArgumentParser ()
9
10
p .add_argument ('name' , help = 'The name of the new benchmark to be created' )
@@ -18,6 +19,7 @@ def main():
18
19
# registers the benchmark with the driver in `main.swift`
19
20
add_register_benchmark (args .name )
20
21
22
+
21
23
def update_cmakelists (name ):
22
24
"""Adds a new entry to the `CMakeLists.txt` file with the given
23
25
benchmark name.
@@ -38,11 +40,12 @@ def update_cmakelists(name):
38
40
for line in file_new_contents :
39
41
f .write (line )
40
42
43
+
41
44
def create_benchmark_file (name ):
42
45
"""Creates a new Swift file with the given name based on the template
43
46
and places it in the `single-source` directory.
44
47
"""
45
-
48
+
46
49
template_path = create_relative_path ('Template.swift' )
47
50
benchmark_template = ''
48
51
with open (template_path , 'r' ) as f :
@@ -56,6 +59,7 @@ def create_benchmark_file(name):
56
59
with open (source_file_path , 'w' ) as f :
57
60
f .write (formatted_template )
58
61
62
+
59
63
def add_import_benchmark (name ):
60
64
"""Adds an `import` statement to the `main.swift` file for the new
61
65
benchmark.
@@ -80,8 +84,8 @@ def add_import_benchmark(name):
80
84
benchmark_name = match .group (1 )
81
85
# find where to insert the new benchmark in the right alphabetical
82
86
# order.
83
- if (( name < benchmark_name and previous_benchmark_name is None ) or
84
- ( name < benchmark_name and name > previous_benchmark_name ) ):
87
+ if (name < benchmark_name and previous_benchmark_name is None or
88
+ name < benchmark_name and name > previous_benchmark_name ):
85
89
if read_test_dependencies :
86
90
file_new_contents .append ('import ' + name + '\n ' + line )
87
91
else :
@@ -98,6 +102,7 @@ def add_import_benchmark(name):
98
102
for line in file_new_contents :
99
103
f .write (line )
100
104
105
+
101
106
def add_register_benchmark (name ):
102
107
"""Adds an `import` statement to the `main.swift` file for the new
103
108
benchmark.
@@ -118,9 +123,10 @@ def add_register_benchmark(name):
118
123
for line in file_new_contents :
119
124
f .write (line )
120
125
126
+
121
127
def insert_line_alphabetically (name , new_line , lines , regex ):
122
- """Iterates through the given lines and executes the regex on each line
123
- to find where the new benchmark should be inserted with the given `new_line`.
128
+ """Iterates through the given lines and executes the regex on each line to
129
+ find where the new benchmark should be inserted with the given `new_line`.
124
130
"""
125
131
# the name of the previous seen benchmark in order to insert the new
126
132
# one at the correct position
@@ -134,8 +140,8 @@ def insert_line_alphabetically(name, new_line, lines, regex):
134
140
benchmark_name = match .group (1 )
135
141
# check if we're at the line where we have to insert the new
136
142
# benchmark in the correct alphabetical order
137
- if (( name < benchmark_name and previous_benchmark_name is None ) or
138
- ( name < benchmark_name and name > previous_benchmark_name ) ):
143
+ if (name < benchmark_name and previous_benchmark_name is None or
144
+ name < benchmark_name and name > previous_benchmark_name ):
139
145
updated_lines .append (new_line + line )
140
146
else :
141
147
updated_lines .append (line )
@@ -144,8 +150,10 @@ def insert_line_alphabetically(name, new_line, lines, regex):
144
150
updated_lines .append (line )
145
151
return updated_lines
146
152
153
+
147
154
def create_relative_path (file_path ):
148
155
return os .path .join (os .path .dirname (__file__ ), file_path )
149
156
157
+
150
158
if __name__ == "__main__" :
151
159
main ()
0 commit comments