tesseract v5.3.3.20231005
fuse_gmock_files Namespace Reference

Functions

def GetGTestRootDir (gmock_root)
 
def ValidateGMockRootDir (gmock_root)
 
def ValidateOutputDir (output_dir)
 
def FuseGMockH (gmock_root, output_dir)
 
def FuseGMockAllCcToFile (gmock_root, output_file)
 
def FuseGMockGTestAllCc (gmock_root, output_dir)
 
def FuseGMock (gmock_root, output_dir)
 
def main ()
 

Variables

 DEFAULT_GMOCK_ROOT_DIR = os.path.join(os.path.dirname(__file__), '..')
 
 INCLUDE_GMOCK_FILE_REGEX = re.compile(r'^\s*#\s*include\s*"(gmock/.+)"')
 
string GMOCK_H_SEED = 'include/gmock/gmock.h'
 
string GMOCK_ALL_CC_SEED = 'src/gmock-all.cc'
 
string GTEST_H_OUTPUT = 'gtest/gtest.h'
 
string GMOCK_H_OUTPUT = 'gmock/gmock.h'
 
string GMOCK_GTEST_ALL_CC_OUTPUT = 'gmock-gtest-all.cc'
 

Function Documentation

◆ FuseGMock()

def fuse_gmock_files.FuseGMock (   gmock_root,
  output_dir 
)
Fuses gtest.h, gmock.h, and gmock-gtest-all.h.

Definition at line 231 of file fuse_gmock_files.py.

231def FuseGMock(gmock_root, output_dir):
232 """Fuses gtest.h, gmock.h, and gmock-gtest-all.h."""
233
234 ValidateGMockRootDir(gmock_root)
235 ValidateOutputDir(output_dir)
236
237 gtest.FuseGTestH(GetGTestRootDir(gmock_root), output_dir)
238 FuseGMockH(gmock_root, output_dir)
239 FuseGMockGTestAllCc(gmock_root, output_dir)
240
241
def FuseGMockGTestAllCc(gmock_root, output_dir)
def ValidateOutputDir(output_dir)
def GetGTestRootDir(gmock_root)
def ValidateGMockRootDir(gmock_root)
def FuseGMockH(gmock_root, output_dir)
def FuseGMock(gmock_root, output_dir)

◆ FuseGMockAllCcToFile()

def fuse_gmock_files.FuseGMockAllCcToFile (   gmock_root,
  output_file 
)
Scans folder gmock_root to fuse gmock-all.cc into output_file.

Definition at line 170 of file fuse_gmock_files.py.

170def FuseGMockAllCcToFile(gmock_root, output_file):
171 """Scans folder gmock_root to fuse gmock-all.cc into output_file."""
172
173 processed_files = set()
174
175 def ProcessFile(gmock_source_file):
176 """Processes the given gmock source file."""
177
178 # We don't process the same #included file twice.
179 if gmock_source_file in processed_files:
180 return
181
182 processed_files.add(gmock_source_file)
183
184 # Reads each line in the given gmock source file.
185
186 with open(os.path.join(gmock_root, gmock_source_file), 'r') as fh:
187 for line in fh:
188 m = INCLUDE_GMOCK_FILE_REGEX.match(line)
189 if m:
190 # '#include "gmock/foo.h"'
191 # We treat it as '#include "gmock/gmock.h"', as all other gmock
192 # headers are being fused into gmock.h and cannot be
193 # included directly. No need to
194 # #include "gmock/gmock.h"
195 # more than once.
196
197 if GMOCK_H_SEED not in processed_files:
198 processed_files.add(GMOCK_H_SEED)
199 output_file.write('#include "%s"\n' % (GMOCK_H_OUTPUT,))
200 else:
201 m = gtest.INCLUDE_GTEST_FILE_REGEX.match(line)
202 if m:
203 # '#include "gtest/..."'
204 # There is no need to #include gtest.h as it has been
205 # #included by gtest-all.cc.
206
207 pass
208 else:
209 m = gtest.INCLUDE_SRC_FILE_REGEX.match(line)
210 if m:
211 # It's '#include "src/foo"' - let's process it recursively.
212 ProcessFile(m.group(1))
213 else:
214 # Otherwise we copy the line unchanged to the output file.
215 output_file.write(line)
216
217 ProcessFile(GMOCK_ALL_CC_SEED)
218
219
def FuseGMockAllCcToFile(gmock_root, output_file)

◆ FuseGMockGTestAllCc()

def fuse_gmock_files.FuseGMockGTestAllCc (   gmock_root,
  output_dir 
)
Scans folder gmock_root to generate gmock-gtest-all.cc in output_dir.

Definition at line 220 of file fuse_gmock_files.py.

220def FuseGMockGTestAllCc(gmock_root, output_dir):
221 """Scans folder gmock_root to generate gmock-gtest-all.cc in output_dir."""
222
223 with open(os.path.join(output_dir, GMOCK_GTEST_ALL_CC_OUTPUT),
224 'w') as output_file:
225 # First, fuse gtest-all.cc into gmock-gtest-all.cc.
226 gtest.FuseGTestAllCcToFile(GetGTestRootDir(gmock_root), output_file)
227 # Next, append fused gmock-all.cc to gmock-gtest-all.cc.
228 FuseGMockAllCcToFile(gmock_root, output_file)
229
230

◆ FuseGMockH()

def fuse_gmock_files.FuseGMockH (   gmock_root,
  output_dir 
)
Scans folder gmock_root to generate gmock/gmock.h in output_dir.

Definition at line 127 of file fuse_gmock_files.py.

127def FuseGMockH(gmock_root, output_dir):
128 """Scans folder gmock_root to generate gmock/gmock.h in output_dir."""
129
130 output_file = open(os.path.join(output_dir, GMOCK_H_OUTPUT), 'w')
131 processed_files = set() # Holds all gmock headers we've processed.
132
133 def ProcessFile(gmock_header_path):
134 """Processes the given gmock header file."""
135
136 # We don't process the same header twice.
137 if gmock_header_path in processed_files:
138 return
139
140 processed_files.add(gmock_header_path)
141
142 # Reads each line in the given gmock header.
143
144 with open(os.path.join(gmock_root, gmock_header_path), 'r') as fh:
145 for line in fh:
146 m = INCLUDE_GMOCK_FILE_REGEX.match(line)
147 if m:
148 # '#include "gmock/..."'
149 # - let's process it recursively.
150 ProcessFile('include/' + m.group(1))
151 else:
152 m = gtest.INCLUDE_GTEST_FILE_REGEX.match(line)
153 if m:
154 # '#include "gtest/foo.h"'
155 # We translate it to "gtest/gtest.h", regardless of what foo is,
156 # since all gtest headers are fused into gtest/gtest.h.
157
158 # There is no need to #include gtest.h twice.
159 if gtest.GTEST_H_SEED not in processed_files:
160 processed_files.add(gtest.GTEST_H_SEED)
161 output_file.write('#include "%s"\n' % (gtest.GTEST_H_OUTPUT,))
162 else:
163 # Otherwise we copy the line unchanged to the output file.
164 output_file.write(line)
165
166 ProcessFile(GMOCK_H_SEED)
167 output_file.close()
168
169

◆ GetGTestRootDir()

def fuse_gmock_files.GetGTestRootDir (   gmock_root)
Returns the root directory of Google Test.

Definition at line 93 of file fuse_gmock_files.py.

93def GetGTestRootDir(gmock_root):
94 """Returns the root directory of Google Test."""
95
96 return os.path.join(gmock_root, '../googletest')
97
98

◆ main()

def fuse_gmock_files.main ( )

Definition at line 242 of file fuse_gmock_files.py.

242def main():
243 argc = len(sys.argv)
244 if argc == 2:
245 # fuse_gmock_files.py OUTPUT_DIR
246 FuseGMock(DEFAULT_GMOCK_ROOT_DIR, sys.argv[1])
247 elif argc == 3:
248 # fuse_gmock_files.py GMOCK_ROOT_DIR OUTPUT_DIR
249 FuseGMock(sys.argv[1], sys.argv[2])
250 else:
251 print(__doc__)
252 sys.exit(1)
253
254

◆ ValidateGMockRootDir()

def fuse_gmock_files.ValidateGMockRootDir (   gmock_root)
Makes sure gmock_root points to a valid gmock root directory.

The function aborts the program on failure.

Args:
  gmock_root: A string with the mock root directory.

Definition at line 99 of file fuse_gmock_files.py.

99def ValidateGMockRootDir(gmock_root):
100 """Makes sure gmock_root points to a valid gmock root directory.
101
102 The function aborts the program on failure.
103
104 Args:
105 gmock_root: A string with the mock root directory.
106 """
107
108 gtest.ValidateGTestRootDir(GetGTestRootDir(gmock_root))
109 gtest.VerifyFileExists(gmock_root, GMOCK_H_SEED)
110 gtest.VerifyFileExists(gmock_root, GMOCK_ALL_CC_SEED)
111
112

◆ ValidateOutputDir()

def fuse_gmock_files.ValidateOutputDir (   output_dir)
Makes sure output_dir points to a valid output directory.

The function aborts the program on failure.

Args:
  output_dir: A string representing the output directory.

Definition at line 113 of file fuse_gmock_files.py.

113def ValidateOutputDir(output_dir):
114 """Makes sure output_dir points to a valid output directory.
115
116 The function aborts the program on failure.
117
118 Args:
119 output_dir: A string representing the output directory.
120 """
121
122 gtest.VerifyOutputFile(output_dir, gtest.GTEST_H_OUTPUT)
123 gtest.VerifyOutputFile(output_dir, GMOCK_H_OUTPUT)
124 gtest.VerifyOutputFile(output_dir, GMOCK_GTEST_ALL_CC_OUTPUT)
125
126

Variable Documentation

◆ DEFAULT_GMOCK_ROOT_DIR

fuse_gmock_files.DEFAULT_GMOCK_ROOT_DIR = os.path.join(os.path.dirname(__file__), '..')

Definition at line 73 of file fuse_gmock_files.py.

◆ GMOCK_ALL_CC_SEED

string fuse_gmock_files.GMOCK_ALL_CC_SEED = 'src/gmock-all.cc'

Definition at line 85 of file fuse_gmock_files.py.

◆ GMOCK_GTEST_ALL_CC_OUTPUT

string fuse_gmock_files.GMOCK_GTEST_ALL_CC_OUTPUT = 'gmock-gtest-all.cc'

Definition at line 90 of file fuse_gmock_files.py.

◆ GMOCK_H_OUTPUT

string fuse_gmock_files.GMOCK_H_OUTPUT = 'gmock/gmock.h'

Definition at line 89 of file fuse_gmock_files.py.

◆ GMOCK_H_SEED

string fuse_gmock_files.GMOCK_H_SEED = 'include/gmock/gmock.h'

Definition at line 84 of file fuse_gmock_files.py.

◆ GTEST_H_OUTPUT

string fuse_gmock_files.GTEST_H_OUTPUT = 'gtest/gtest.h'

Definition at line 88 of file fuse_gmock_files.py.

◆ INCLUDE_GMOCK_FILE_REGEX

fuse_gmock_files.INCLUDE_GMOCK_FILE_REGEX = re.compile(r'^\s*#\s*include\s*"(gmock/.+)"')

Definition at line 81 of file fuse_gmock_files.py.