proxygen
fuse_gtest_files Namespace Reference

Functions

def VerifyFileExists (directory, relative_path)
 
def ValidateGTestRootDir (gtest_root)
 
def VerifyOutputFile (output_dir, relative_path)
 
def ValidateOutputDir (output_dir)
 
def FuseGTestH (gtest_root, output_dir)
 
def FuseGTestAllCcToFile (gtest_root, output_file)
 
def FuseGTestAllCc (gtest_root, output_dir)
 
def FuseGTest (gtest_root, output_dir)
 
def main ()
 

Variables

string __author__ = 'wan@google.com (Zhanyong Wan)'
 
 DEFAULT_GTEST_ROOT_DIR = os.path.join(os.path.dirname(__file__), '..')
 
 INCLUDE_GTEST_FILE_REGEX = re.compile(r'^\s*#\s*include\s*"(gtest/.+)"')
 
 INCLUDE_SRC_FILE_REGEX = re.compile(r'^\s*#\s*include\s*"(src/.+)"')
 
string GTEST_H_SEED = 'include/gtest/gtest.h'
 
string GTEST_SPI_H_SEED = 'include/gtest/gtest-spi.h'
 
string GTEST_ALL_CC_SEED = 'src/gtest-all.cc'
 
string GTEST_H_OUTPUT = 'gtest/gtest.h'
 
string GTEST_ALL_CC_OUTPUT = 'gtest/gtest-all.cc'
 

Function Documentation

def fuse_gtest_files.FuseGTest (   gtest_root,
  output_dir 
)
Fuses gtest.h and gtest-all.cc.

Definition at line 229 of file fuse_gtest_files.py.

References FuseGTestAllCc(), FuseGTestH(), ValidateGTestRootDir(), and ValidateOutputDir().

Referenced by main().

229 def FuseGTest(gtest_root, output_dir):
230  """Fuses gtest.h and gtest-all.cc."""
231 
232  ValidateGTestRootDir(gtest_root)
233  ValidateOutputDir(output_dir)
234 
235  FuseGTestH(gtest_root, output_dir)
236  FuseGTestAllCc(gtest_root, output_dir)
237 
238 
def FuseGTestH(gtest_root, output_dir)
def FuseGTestAllCc(gtest_root, output_dir)
def FuseGTest(gtest_root, output_dir)
def ValidateOutputDir(output_dir)
def ValidateGTestRootDir(gtest_root)
def fuse_gtest_files.FuseGTestAllCc (   gtest_root,
  output_dir 
)
Scans folder gtest_root to generate gtest/gtest-all.cc in output_dir.

Definition at line 221 of file fuse_gtest_files.py.

References FuseGTestAllCcToFile().

Referenced by FuseGTest().

221 def FuseGTestAllCc(gtest_root, output_dir):
222  """Scans folder gtest_root to generate gtest/gtest-all.cc in output_dir."""
223 
224  output_file = open(os.path.join(output_dir, GTEST_ALL_CC_OUTPUT), 'w')
225  FuseGTestAllCcToFile(gtest_root, output_file)
226  output_file.close()
227 
228 
def FuseGTestAllCc(gtest_root, output_dir)
def FuseGTestAllCcToFile(gtest_root, output_file)
def fuse_gtest_files.FuseGTestAllCcToFile (   gtest_root,
  output_file 
)
Scans folder gtest_root to generate gtest/gtest-all.cc in output_file.

Definition at line 178 of file fuse_gtest_files.py.

Referenced by FuseGTestAllCc().

178 def FuseGTestAllCcToFile(gtest_root, output_file):
179  """Scans folder gtest_root to generate gtest/gtest-all.cc in output_file."""
180 
181  processed_files = set()
182 
183  def ProcessFile(gtest_source_file):
184  """Processes the given gtest source file."""
185 
186  # We don't process the same #included file twice.
187  if gtest_source_file in processed_files:
188  return
189 
190  processed_files.add(gtest_source_file)
191 
192  # Reads each line in the given gtest source file.
193  for line in open(os.path.join(gtest_root, gtest_source_file), 'r'):
194  m = INCLUDE_GTEST_FILE_REGEX.match(line)
195  if m:
196  if 'include/' + m.group(1) == GTEST_SPI_H_SEED:
197  # It's '#include "gtest/gtest-spi.h"'. This file is not
198  # #included by "gtest/gtest.h", so we need to process it.
199  ProcessFile(GTEST_SPI_H_SEED)
200  else:
201  # It's '#include "gtest/foo.h"' where foo is not gtest-spi.
202  # We treat it as '#include "gtest/gtest.h"', as all other
203  # gtest headers are being fused into gtest.h and cannot be
204  # #included directly.
205 
206  # There is no need to #include "gtest/gtest.h" more than once.
207  if not GTEST_H_SEED in processed_files:
208  processed_files.add(GTEST_H_SEED)
209  output_file.write('#include "%s"\n' % (GTEST_H_OUTPUT,))
210  else:
211  m = INCLUDE_SRC_FILE_REGEX.match(line)
212  if m:
213  # It's '#include "src/foo"' - let's process it recursively.
214  ProcessFile(m.group(1))
215  else:
216  output_file.write(line)
217 
218  ProcessFile(GTEST_ALL_CC_SEED)
219 
220 
def FuseGTestAllCcToFile(gtest_root, output_file)
Definition: Traits.h:592
def fuse_gtest_files.FuseGTestH (   gtest_root,
  output_dir 
)
Scans folder gtest_root to generate gtest/gtest.h in output_dir.

Definition at line 149 of file fuse_gtest_files.py.

Referenced by FuseGTest().

149 def FuseGTestH(gtest_root, output_dir):
150  """Scans folder gtest_root to generate gtest/gtest.h in output_dir."""
151 
152  output_file = open(os.path.join(output_dir, GTEST_H_OUTPUT), 'w')
153  processed_files = set() # Holds all gtest headers we've processed.
154 
155  def ProcessFile(gtest_header_path):
156  """Processes the given gtest header file."""
157 
158  # We don't process the same header twice.
159  if gtest_header_path in processed_files:
160  return
161 
162  processed_files.add(gtest_header_path)
163 
164  # Reads each line in the given gtest header.
165  for line in open(os.path.join(gtest_root, gtest_header_path), 'r'):
166  m = INCLUDE_GTEST_FILE_REGEX.match(line)
167  if m:
168  # It's '#include "gtest/..."' - let's process it recursively.
169  ProcessFile('include/' + m.group(1))
170  else:
171  # Otherwise we copy the line unchanged to the output file.
172  output_file.write(line)
173 
174  ProcessFile(GTEST_H_SEED)
175  output_file.close()
176 
177 
def FuseGTestH(gtest_root, output_dir)
Definition: Traits.h:592
def fuse_gtest_files.main ( void  )

Definition at line 239 of file fuse_gtest_files.py.

References FuseGTest().

239 def main():
240  argc = len(sys.argv)
241  if argc == 2:
242  # fuse_gtest_files.py OUTPUT_DIR
243  FuseGTest(DEFAULT_GTEST_ROOT_DIR, sys.argv[1])
244  elif argc == 3:
245  # fuse_gtest_files.py GTEST_ROOT_DIR OUTPUT_DIR
246  FuseGTest(sys.argv[1], sys.argv[2])
247  else:
248  print(__doc__)
249  sys.exit(1)
250 
251 
def FuseGTest(gtest_root, output_dir)
def fuse_gtest_files.ValidateGTestRootDir (   gtest_root)
Makes sure gtest_root points to a valid gtest root directory.

The function aborts the program on failure.

Definition at line 103 of file fuse_gtest_files.py.

References VerifyFileExists().

Referenced by FuseGTest().

103 def ValidateGTestRootDir(gtest_root):
104  """Makes sure gtest_root points to a valid gtest root directory.
105 
106  The function aborts the program on failure.
107  """
108 
109  VerifyFileExists(gtest_root, GTEST_H_SEED)
110  VerifyFileExists(gtest_root, GTEST_ALL_CC_SEED)
111 
112 
def VerifyFileExists(directory, relative_path)
def ValidateGTestRootDir(gtest_root)
def fuse_gtest_files.ValidateOutputDir (   output_dir)
Makes sure output_dir points to a valid output directory.

The function aborts the program on failure.

Definition at line 139 of file fuse_gtest_files.py.

References VerifyOutputFile().

Referenced by FuseGTest().

139 def ValidateOutputDir(output_dir):
140  """Makes sure output_dir points to a valid output directory.
141 
142  The function aborts the program on failure.
143  """
144 
145  VerifyOutputFile(output_dir, GTEST_H_OUTPUT)
146  VerifyOutputFile(output_dir, GTEST_ALL_CC_OUTPUT)
147 
148 
def VerifyOutputFile(output_dir, relative_path)
def ValidateOutputDir(output_dir)
def fuse_gtest_files.VerifyFileExists (   directory,
  relative_path 
)
Verifies that the given file exists; aborts on failure.

relative_path is the file path relative to the given directory.

Definition at line 89 of file fuse_gtest_files.py.

Referenced by ValidateGTestRootDir().

89 def VerifyFileExists(directory, relative_path):
90  """Verifies that the given file exists; aborts on failure.
91 
92  relative_path is the file path relative to the given directory.
93  """
94 
95  if not os.path.isfile(os.path.join(directory, relative_path)):
96  print('ERROR: Cannot find %s in directory %s.' % (relative_path,
97  directory))
98  print('Please either specify a valid project root directory '
99  'or omit it on the command line.')
100  sys.exit(1)
101 
102 
def VerifyFileExists(directory, relative_path)
def fuse_gtest_files.VerifyOutputFile (   output_dir,
  relative_path 
)
Verifies that the given output file path is valid.

relative_path is relative to the output_dir directory.

Definition at line 113 of file fuse_gtest_files.py.

References folly::detail::distributed_mutex.strip().

Referenced by ValidateOutputDir().

113 def VerifyOutputFile(output_dir, relative_path):
114  """Verifies that the given output file path is valid.
115 
116  relative_path is relative to the output_dir directory.
117  """
118 
119  # Makes sure the output file either doesn't exist or can be overwritten.
120  output_file = os.path.join(output_dir, relative_path)
121  if os.path.exists(output_file):
122  # TODO(wan@google.com): The following user-interaction doesn't
123  # work with automated processes. We should provide a way for the
124  # Makefile to force overwriting the files.
125  print('%s already exists in directory %s - overwrite it? (y/N) ' %
126  (relative_path, output_dir))
127  answer = sys.stdin.readline().strip()
128  if answer not in ['y', 'Y']:
129  print('ABORTED.')
130  sys.exit(1)
131 
132  # Makes sure the directory holding the output file exists; creates
133  # it and all its ancestors if necessary.
134  parent_directory = os.path.dirname(output_file)
135  if not os.path.isdir(parent_directory):
136  os.makedirs(parent_directory)
137 
138 
def VerifyOutputFile(output_dir, relative_path)
std::uint64_t strip(std::chrono::nanoseconds t)

Variable Documentation

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

Definition at line 59 of file fuse_gtest_files.py.

fuse_gtest_files.DEFAULT_GTEST_ROOT_DIR = os.path.join(os.path.dirname(__file__), '..')

Definition at line 71 of file fuse_gtest_files.py.

string fuse_gtest_files.GTEST_ALL_CC_OUTPUT = 'gtest/gtest-all.cc'

Definition at line 86 of file fuse_gtest_files.py.

string fuse_gtest_files.GTEST_ALL_CC_SEED = 'src/gtest-all.cc'

Definition at line 82 of file fuse_gtest_files.py.

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

Definition at line 85 of file fuse_gtest_files.py.

string fuse_gtest_files.GTEST_H_SEED = 'include/gtest/gtest.h'

Definition at line 80 of file fuse_gtest_files.py.

string fuse_gtest_files.GTEST_SPI_H_SEED = 'include/gtest/gtest-spi.h'

Definition at line 81 of file fuse_gtest_files.py.

fuse_gtest_files.INCLUDE_GTEST_FILE_REGEX = re.compile(r'^\s*#\s*include\s*"(gtest/.+)"')

Definition at line 74 of file fuse_gtest_files.py.

fuse_gtest_files.INCLUDE_SRC_FILE_REGEX = re.compile(r'^\s*#\s*include\s*"(src/.+)"')

Definition at line 77 of file fuse_gtest_files.py.