proxygen
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

string __author__ = 'wan@google.com (Zhanyong Wan)'
 
 DEFAULT_GMOCK_ROOT_DIR = os.path.join(os.path.dirname(__file__), '..')
 
 gtest = fuse_gtest_files
 
 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

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

Definition at line 215 of file fuse_gmock_files.py.

References FuseGMockGTestAllCc(), FuseGMockH(), GetGTestRootDir(), ValidateGMockRootDir(), and ValidateOutputDir().

Referenced by main().

215 def FuseGMock(gmock_root, output_dir):
216  """Fuses gtest.h, gmock.h, and gmock-gtest-all.h."""
217 
218  ValidateGMockRootDir(gmock_root)
219  ValidateOutputDir(output_dir)
220 
221  gtest.FuseGTestH(GetGTestRootDir(gmock_root), output_dir)
222  FuseGMockH(gmock_root, output_dir)
223  FuseGMockGTestAllCc(gmock_root, output_dir)
224 
225 
def FuseGMockGTestAllCc(gmock_root, output_dir)
def FuseGMockH(gmock_root, output_dir)
def ValidateGMockRootDir(gmock_root)
def FuseGMock(gmock_root, output_dir)
def ValidateOutputDir(output_dir)
def GetGTestRootDir(gmock_root)
def fuse_gmock_files.FuseGMockAllCcToFile (   gmock_root,
  output_file 
)
Scans folder gmock_root to fuse gmock-all.cc into output_file.

Definition at line 159 of file fuse_gmock_files.py.

Referenced by FuseGMockGTestAllCc().

159 def FuseGMockAllCcToFile(gmock_root, output_file):
160  """Scans folder gmock_root to fuse gmock-all.cc into output_file."""
161 
162  processed_files = sets.Set()
163 
164  def ProcessFile(gmock_source_file):
165  """Processes the given gmock source file."""
166 
167  # We don't process the same #included file twice.
168  if gmock_source_file in processed_files:
169  return
170 
171  processed_files.add(gmock_source_file)
172 
173  # Reads each line in the given gmock source file.
174  for line in file(os.path.join(gmock_root, gmock_source_file), 'r'):
175  m = INCLUDE_GMOCK_FILE_REGEX.match(line)
176  if m:
177  # It's '#include "gmock/foo.h"'. We treat it as '#include
178  # "gmock/gmock.h"', as all other gmock headers are being fused
179  # into gmock.h and cannot be #included directly.
180 
181  # There is no need to #include "gmock/gmock.h" more than once.
182  if not GMOCK_H_SEED in processed_files:
183  processed_files.add(GMOCK_H_SEED)
184  output_file.write('#include "%s"\n' % (GMOCK_H_OUTPUT,))
185  else:
186  m = gtest.INCLUDE_GTEST_FILE_REGEX.match(line)
187  if m:
188  # It's '#include "gtest/..."'.
189  # There is no need to #include gtest.h as it has been
190  # #included by gtest-all.cc.
191  pass
192  else:
193  m = gtest.INCLUDE_SRC_FILE_REGEX.match(line)
194  if m:
195  # It's '#include "src/foo"' - let's process it recursively.
196  ProcessFile(m.group(1))
197  else:
198  # Otherwise we copy the line unchanged to the output file.
199  output_file.write(line)
200 
201  ProcessFile(GMOCK_ALL_CC_SEED)
202 
203 
def FuseGMockAllCcToFile(gmock_root, output_file)
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 204 of file fuse_gmock_files.py.

References FuseGMockAllCcToFile(), and GetGTestRootDir().

Referenced by FuseGMock().

204 def FuseGMockGTestAllCc(gmock_root, output_dir):
205  """Scans folder gmock_root to generate gmock-gtest-all.cc in output_dir."""
206 
207  output_file = file(os.path.join(output_dir, GMOCK_GTEST_ALL_CC_OUTPUT), 'w')
208  # First, fuse gtest-all.cc into gmock-gtest-all.cc.
209  gtest.FuseGTestAllCcToFile(GetGTestRootDir(gmock_root), output_file)
210  # Next, append fused gmock-all.cc to gmock-gtest-all.cc.
211  FuseGMockAllCcToFile(gmock_root, output_file)
212  output_file.close()
213 
214 
def FuseGMockAllCcToFile(gmock_root, output_file)
def FuseGMockGTestAllCc(gmock_root, output_dir)
def GetGTestRootDir(gmock_root)
def fuse_gmock_files.FuseGMockH (   gmock_root,
  output_dir 
)
Scans folder gmock_root to generate gmock/gmock.h in output_dir.

Definition at line 119 of file fuse_gmock_files.py.

Referenced by FuseGMock().

119 def FuseGMockH(gmock_root, output_dir):
120  """Scans folder gmock_root to generate gmock/gmock.h in output_dir."""
121 
122  output_file = file(os.path.join(output_dir, GMOCK_H_OUTPUT), 'w')
123  processed_files = sets.Set() # Holds all gmock headers we've processed.
124 
125  def ProcessFile(gmock_header_path):
126  """Processes the given gmock header file."""
127 
128  # We don't process the same header twice.
129  if gmock_header_path in processed_files:
130  return
131 
132  processed_files.add(gmock_header_path)
133 
134  # Reads each line in the given gmock header.
135  for line in file(os.path.join(gmock_root, gmock_header_path), 'r'):
136  m = INCLUDE_GMOCK_FILE_REGEX.match(line)
137  if m:
138  # It's '#include "gmock/..."' - let's process it recursively.
139  ProcessFile('include/' + m.group(1))
140  else:
141  m = gtest.INCLUDE_GTEST_FILE_REGEX.match(line)
142  if m:
143  # It's '#include "gtest/foo.h"'. We translate it to
144  # "gtest/gtest.h", regardless of what foo is, since all
145  # gtest headers are fused into gtest/gtest.h.
146 
147  # There is no need to #include gtest.h twice.
148  if not gtest.GTEST_H_SEED in processed_files:
149  processed_files.add(gtest.GTEST_H_SEED)
150  output_file.write('#include "%s"\n' % (gtest.GTEST_H_OUTPUT,))
151  else:
152  # Otherwise we copy the line unchanged to the output file.
153  output_file.write(line)
154 
155  ProcessFile(GMOCK_H_SEED)
156  output_file.close()
157 
158 
def FuseGMockH(gmock_root, output_dir)
def fuse_gmock_files.GetGTestRootDir (   gmock_root)
Returns the root directory of Google Test.

Definition at line 91 of file fuse_gmock_files.py.

Referenced by FuseGMock(), FuseGMockGTestAllCc(), and ValidateGMockRootDir().

91 def GetGTestRootDir(gmock_root):
92  """Returns the root directory of Google Test."""
93 
94  return os.path.join(gmock_root, '../googletest')
95 
96 
def GetGTestRootDir(gmock_root)
def fuse_gmock_files.main ( void  )

Definition at line 226 of file fuse_gmock_files.py.

References FuseGMock().

226 def main():
227  argc = len(sys.argv)
228  if argc == 2:
229  # fuse_gmock_files.py OUTPUT_DIR
230  FuseGMock(DEFAULT_GMOCK_ROOT_DIR, sys.argv[1])
231  elif argc == 3:
232  # fuse_gmock_files.py GMOCK_ROOT_DIR OUTPUT_DIR
233  FuseGMock(sys.argv[1], sys.argv[2])
234  else:
235  print __doc__
236  sys.exit(1)
237 
238 
def FuseGMock(gmock_root, output_dir)
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.

Definition at line 97 of file fuse_gmock_files.py.

References GetGTestRootDir().

Referenced by FuseGMock().

97 def ValidateGMockRootDir(gmock_root):
98  """Makes sure gmock_root points to a valid gmock root directory.
99 
100  The function aborts the program on failure.
101  """
102 
103  gtest.ValidateGTestRootDir(GetGTestRootDir(gmock_root))
104  gtest.VerifyFileExists(gmock_root, GMOCK_H_SEED)
105  gtest.VerifyFileExists(gmock_root, GMOCK_ALL_CC_SEED)
106 
107 
def ValidateGMockRootDir(gmock_root)
def GetGTestRootDir(gmock_root)
def fuse_gmock_files.ValidateOutputDir (   output_dir)
Makes sure output_dir points to a valid output directory.

The function aborts the program on failure.

Definition at line 108 of file fuse_gmock_files.py.

Referenced by FuseGMock().

108 def ValidateOutputDir(output_dir):
109  """Makes sure output_dir points to a valid output directory.
110 
111  The function aborts the program on failure.
112  """
113 
114  gtest.VerifyOutputFile(output_dir, gtest.GTEST_H_OUTPUT)
115  gtest.VerifyOutputFile(output_dir, GMOCK_H_OUTPUT)
116  gtest.VerifyOutputFile(output_dir, GMOCK_GTEST_ALL_CC_OUTPUT)
117 
118 
def ValidateOutputDir(output_dir)

Variable Documentation

string fuse_gmock_files.__author__ = 'wan@google.com (Zhanyong Wan)'
private

Definition at line 62 of file fuse_gmock_files.py.

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

Definition at line 71 of file fuse_gmock_files.py.

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

Definition at line 83 of file fuse_gmock_files.py.

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

Definition at line 88 of file fuse_gmock_files.py.

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

Definition at line 87 of file fuse_gmock_files.py.

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

Definition at line 82 of file fuse_gmock_files.py.

fuse_gmock_files.gtest = fuse_gtest_files

Definition at line 76 of file fuse_gmock_files.py.

Referenced by option(), and set().

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

Definition at line 86 of file fuse_gmock_files.py.

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

Definition at line 79 of file fuse_gmock_files.py.