tools/generate_stubs/generate_stubs.py
def CreatePosixStubsForSigFiles(sig_files, stub_name, out_dir, intermediate_dir,
                                path_from_source, extra_stub_header,
                                export_macro, logging_function,
                                logging_include):
  """Create a POSIX stub library with a module for each signature file.

  Args:
    sig_files: Array of strings with the paths to each signature file.
    stub_name: String with the basename of the generated stub file.
    out_dir: String holding path to directory for the .h files.
    intermediate_dir: String holding path to directory for the .cc files.
    path_from_source: String with relative path of generated files from the
                      project root.
    extra_stub_header: String with path to file of extra lines to insert
                       into the generated header for the stub library.
    export_macro: A preprocessor macro used to annotate stub symbols with
                  an EXPORT marking, to control visibility.
    logging_function: Function call that will be used for error logging.
    logging_include: Header file where the logging function is defined.
  """
  header_base_name = stub_name + '.h'
  header_path = os.path.join(out_dir, header_base_name)
  impl_path = os.path.join(intermediate_dir, stub_name + '.cc')

  module_names = [ExtractModuleName(path) for path in sig_files]
  namespace = path_from_source.replace('/', '_').lower()
  header_guard = 'GEN_%s_%s_H_' % (namespace.upper(), stub_name.upper())
  header_include_path = os.path.join(path_from_source, header_base_name)

  # First create the implementation file.
  impl_file = open(impl_path, 'w')
  try:
    # Open the file, and create the preamble which consists of a file
    # header plus any necessary includes.
    PosixStubWriter.WriteImplementationPreamble(header_include_path, impl_file,
                                                logging_include)
    if extra_stub_header is not None:
      extra_header_file = open(extra_stub_header, 'r')
      try:
        impl_file.write('\n')
        for line in extra_header_file:
          impl_file.write(line)
        impl_file.write('\n')
      finally:
        extra_header_file.close()

    impl_file.write(NAMESPACE_START % '')
    impl_file.write(LOG_DLERROR % logging_function)
    impl_file.write(NAMESPACE_END % '')

    # For each signature file, generate the stub population functions
    # for that file.  Each file represents one module.
    for input_path in sig_files:
      name = ExtractModuleName(input_path)
      infile = open(input_path, 'r')
      try:
        signatures = ParseSignatures(infile)
      finally:
        infile.close()
      writer = PosixStubWriter(name, export_macro, signatures, logging_function,
                               logging_include)
      writer.WriteImplementationContents(namespace, impl_file)

    # Lastly, output the umbrella function for the file.
    PosixStubWriter.WriteUmbrellaInitializer(module_names, namespace, impl_file,
                                             logging_function)
  finally:
    impl_file.close()

  # Then create the associated header file.
  header_file = open(header_path, 'w')
  try:
    PosixStubWriter.WriteHeaderContents(module_names, namespace, header_guard,
                                        header_file)
  finally:
    header_file.close()
Create a POSIX stub library with a module for each signature file.

  Args:
    sig_files: Array of strings with the paths to each signature file.
    stub_name: String with the basename of the generated stub file.
    out_dir: String holding path to directory for the .h files.
    intermediate_dir: String holding path to directory for the .cc files.
    path_from_source: String with relative path of generated files from the
                      project root.
    extra_stub_header: String with path to file of extra lines to insert
                       into the generated header for the stub library.
    export_macro: A preprocessor macro used to annotate stub symbols with
                  an EXPORT marking, to control visibility.
    logging_function: Function call that will be used for error logging.
    logging_include: Header file where the logging function is defined.
  
Create a POSIX stub library with a module for each signature file.
Create a POSIX stub library with a module for each signature file .
def CreatePosixStubsForSigFiles(sig_files, stub_name, out_dir, intermediate_dir,
                                path_from_source, extra_stub_header,
                                export_macro, logging_function,
                                logging_include):
  header_base_name = stub_name + '.h'
  header_path = os.path.join(out_dir, header_base_name)
  impl_path = os.path.join(intermediate_dir, stub_name + '.cc')
  module_names = [ExtractModuleName(path) for path in sig_files]
  namespace = path_from_source.replace('/', '_').lower()
  header_guard = 'GEN_%s_%s_H_' % (namespace.upper(), stub_name.upper())
  header_include_path = os.path.join(path_from_source, header_base_name)
  impl_file = open(impl_path, 'w')
  try:
    PosixStubWriter.WriteImplementationPreamble(header_include_path, impl_file,
                                                logging_include)
    if extra_stub_header is not None:
      extra_header_file = open(extra_stub_header, 'r')
      try:
        impl_file.write('\n')
        for line in extra_header_file:
          impl_file.write(line)
        impl_file.write('\n')
      finally:
        extra_header_file.close()
    impl_file.write(NAMESPACE_START % '')
    impl_file.write(LOG_DLERROR % logging_function)
    impl_file.write(NAMESPACE_END % '')
    for input_path in sig_files:
      name = ExtractModuleName(input_path)
      infile = open(input_path, 'r')
      try:
        signatures = ParseSignatures(infile)
      finally:
        infile.close()
      writer = PosixStubWriter(name, export_macro, signatures, logging_function,
                               logging_include)
      writer.WriteImplementationContents(namespace, impl_file)
    PosixStubWriter.WriteUmbrellaInitializer(module_names, namespace, impl_file,
                                             logging_function)
  finally:
    impl_file.close()
  header_file = open(header_path, 'w')
  try:
    PosixStubWriter.WriteHeaderContents(module_names, namespace, header_guard,
                                        header_file)
  finally:
    header_file.close()
def CreatePosixStubsForSigFiles ( sig_files , stub_name , out_dir , intermediate_dir , path_from_source , extra_stub_header , export_macro , logging_function , logging_include ) : header_base_name = stub_name + '.h' header_path = os . path . join ( out_dir , header_base_name ) impl_path = os . path . join ( intermediate_dir , stub_name + '.cc' ) module_names = [ ExtractModuleName ( path ) for path in sig_files ] namespace = path_from_source . replace ( '/' , '_' ) . lower ( ) header_guard = 'GEN_%s_%s_H_' % ( namespace . upper ( ) , stub_name . upper ( ) ) header_include_path = os . path . join ( path_from_source , header_base_name ) impl_file = open ( impl_path , 'w' ) try : PosixStubWriter . WriteImplementationPreamble ( header_include_path , impl_file , logging_include ) if extra_stub_header is not None : extra_header_file = open ( extra_stub_header , 'r' ) try : impl_file . write ( '\n' ) for line in extra_header_file : impl_file . write ( line ) impl_file . write ( '\n' ) finally : extra_header_file . close ( ) impl_file . write ( NAMESPACE_START % '' ) impl_file . write ( LOG_DLERROR % logging_function ) impl_file . write ( NAMESPACE_END % '' ) for input_path in sig_files : name = ExtractModuleName ( input_path ) infile = open ( input_path , 'r' ) try : signatures = ParseSignatures ( infile ) finally : infile . close ( ) writer = PosixStubWriter ( name , export_macro , signatures , logging_function , logging_include ) writer . WriteImplementationContents ( namespace , impl_file ) PosixStubWriter . WriteUmbrellaInitializer ( module_names , namespace , impl_file , logging_function ) finally : impl_file . close ( ) header_file = open ( header_path , 'w' ) try : PosixStubWriter . WriteHeaderContents ( module_names , namespace , header_guard , header_file ) finally : header_file . close ( )
Create a POSIX stub library with a module for each signature file.
Create a POSIX stub library with a module for each signature file .
"""Create a POSIX stub library with a module for each signature file.

  Args:
    sig_files: Array of strings with the paths to each signature file.
    stub_name: String with the basename of the generated stub file.
    out_dir: String holding path to directory for the .h files.
    intermediate_dir: String holding path to directory for the .cc files.
    path_from_source: String with relative path of generated files from the
                      project root.
    extra_stub_header: String with path to file of extra lines to insert
                       into the generated header for the stub library.
    export_macro: A preprocessor macro used to annotate stub symbols with
                  an EXPORT marking, to control visibility.
    logging_function: Function call that will be used for error logging.
    logging_include: Header file where the logging function is defined.
  """ # First create the implementation file. # Open the file, and create the preamble which consists of a file # header plus any necessary includes. # For each signature file, generate the stub population functions # for that file.  Each file represents one module. # Lastly, output the umbrella function for the file. # Then create the associated header file.
sig_files
Array of strings with the paths to each signature file.
Array of strings with the paths to each signature file .
stub_name
String with the basename of the generated stub file.
String with the basename of the generated stub file .
out_dir
String holding path to directory for the .h files.
String holding path to directory for the . h files .
intermediate_dir
String holding path to directory for the .cc files.
String holding path to directory for the . cc files .
path_from_source
String with relative path of generated files from the
project root.
String with relative path of generated files from the project root .
extra_stub_header
String with path to file of extra lines to insert
into the generated header for the stub library.
String with path to file of extra lines to insert into the generated header for the stub library .
export_macro
A preprocessor macro used to annotate stub symbols with
an EXPORT marking, to control visibility.
A preprocessor macro used to annotate stub symbols with an EXPORT marking to control visibility .
logging_function
Function call that will be used for error logging.
Function call that will be used for error logging .
logging_include
Header file where the logging function is defined.
Header file where the logging function is defined .