chrome/test/chromedriver/cpp_source.py
def WriteSource(base_name,
                dir_from_src,
                output_dir,
                global_string_map):
  """Writes C++ header/cc source files for the given map of string variables.

  Args:
      base_name: The basename of the file, without the extension.
      dir_from_src: Path from src to the directory that will contain the file,
          using forward slashes.
      output_dir: Directory to output the sources to.
      global_string_map: Map of variable names to their string values. These
          variables will be available as globals.
  """
  copyright_header_template = (
      '// Copyright 2018 The Chromium Authors. All rights reserved.\n'
      '// Use of this source code is governed by a BSD-style license '
      'that can be\n'
      '// found in the LICENSE file.\n\n'
      '// This file was generated by running:\n'
      '//     %s')
  copyright_header = copyright_header_template % (' '.join(sys.argv))

  # Write header file.
  externs = []
  for name in global_string_map.keys():
    externs += ['extern const char %s[];' % name]

  temp = '_'.join(dir_from_src.split('/') + [base_name])
  define = temp.upper() + '_H_'
  header = '\n'.join([
      copyright_header,
      '',
      '#ifndef ' + define,
      '#define ' + define,
      '',
      '\n'.join(externs),
      '',
      '#endif  // ' + define])
  header += '\n'

  with open(os.path.join(output_dir, base_name + '.h'), 'w') as f:
    f.write(header)

  # Write cc file.
  def EscapeLine(line):
    return line.replace('\\', '\\\\').replace('"', '\\"')

  definitions = []
  for name, contents in global_string_map.items():
    lines = []
    if '\n' not in contents:
      lines = ['    "%s"' % EscapeLine(contents)]
    else:
      for line in contents.split('\n'):
        lines += ['    "%s\\n"' % EscapeLine(line)]
    definitions += ['const char %s[] =\n%s;' % (name, '\n'.join(lines))]

  cc = '\n'.join([
      copyright_header,
      '',
      '#include "%s"' % (dir_from_src + '/' + base_name + '.h'),
      '',
      '\n'.join(definitions)])
  cc += '\n'

  with open(os.path.join(output_dir, base_name + '.cc'), 'w') as f:
    f.write(cc)
Writes C++ header/cc source files for the given map of string variables.

  Args:
      base_name: The basename of the file, without the extension.
      dir_from_src: Path from src to the directory that will contain the file,
          using forward slashes.
      output_dir: Directory to output the sources to.
      global_string_map: Map of variable names to their string values. These
          variables will be available as globals.
  
Writes C++ header/cc source files for the given map of string variables.
Writes C ++ header / cc source files for the given map of string variables .
def WriteSource(base_name,
                dir_from_src,
                output_dir,
                global_string_map):
  copyright_header_template = (
      '// Copyright 2018 The Chromium Authors. All rights reserved.\n'
      '// Use of this source code is governed by a BSD-style license '
      'that can be\n'
      '// found in the LICENSE file.\n\n'
      '// This file was generated by running:\n'
      '//     %s')
  copyright_header = copyright_header_template % (' '.join(sys.argv))
  externs = []
  for name in global_string_map.keys():
    externs += ['extern const char %s[];' % name]
  temp = '_'.join(dir_from_src.split('/') + [base_name])
  define = temp.upper() + '_H_'
  header = '\n'.join([
      copyright_header,
      '',
      '#ifndef ' + define,
      '#define ' + define,
      '',
      '\n'.join(externs),
      '',
      '#endif  // ' + define])
  header += '\n'
  with open(os.path.join(output_dir, base_name + '.h'), 'w') as f:
    f.write(header)
  def EscapeLine(line):
    return line.replace('\\', '\\\\').replace('"', '\\"')
  definitions = []
  for name, contents in global_string_map.items():
    lines = []
    if '\n' not in contents:
      lines = ['    "%s"' % EscapeLine(contents)]
    else:
      for line in contents.split('\n'):
        lines += ['    "%s\\n"' % EscapeLine(line)]
    definitions += ['const char %s[] =\n%s;' % (name, '\n'.join(lines))]
  cc = '\n'.join([
      copyright_header,
      '',
      '#include "%s"' % (dir_from_src + '/' + base_name + '.h'),
      '',
      '\n'.join(definitions)])
  cc += '\n'
  with open(os.path.join(output_dir, base_name + '.cc'), 'w') as f:
    f.write(cc)
def WriteSource ( base_name , dir_from_src , output_dir , global_string_map ) : copyright_header_template = ( '// Copyright 2018 The Chromium Authors. All rights reserved.\n' '// Use of this source code is governed by a BSD-style license ' 'that can be\n' '// found in the LICENSE file.\n\n' '// This file was generated by running:\n' '//     %s' ) copyright_header = copyright_header_template % ( ' ' . join ( sys . argv ) ) externs = [ ] for name in global_string_map . keys ( ) : externs += [ 'extern const char %s[];' % name ] temp = '_' . join ( dir_from_src . split ( '/' ) + [ base_name ] ) define = temp . upper ( ) + '_H_' header = '\n' . join ( [ copyright_header , '' , '#ifndef ' + define , '#define ' + define , '' , '\n' . join ( externs ) , '' , '#endif  // ' + define ] ) header += '\n' with open ( os . path . join ( output_dir , base_name + '.h' ) , 'w' ) as f : f . write ( header ) def EscapeLine ( line ) : return line . replace ( '\\' , '\\\\' ) . replace ( '"' , '\\"' ) definitions = [ ] for name , contents in global_string_map . items ( ) : lines = [ ] if '\n' not in contents : lines = [ '    "%s"' % EscapeLine ( contents ) ] else : for line in contents . split ( '\n' ) : lines += [ '    "%s\\n"' % EscapeLine ( line ) ] definitions += [ 'const char %s[] =\n%s;' % ( name , '\n' . join ( lines ) ) ] cc = '\n' . join ( [ copyright_header , '' , '#include "%s"' % ( dir_from_src + '/' + base_name + '.h' ) , '' , '\n' . join ( definitions ) ] ) cc += '\n' with open ( os . path . join ( output_dir , base_name + '.cc' ) , 'w' ) as f : f . write ( cc )
Writes C++ header/cc source files for the given map of string variables.
Writes C ++ header / cc source files for the given map of string variables .
"""Writes C++ header/cc source files for the given map of string variables.

  Args:
      base_name: The basename of the file, without the extension.
      dir_from_src: Path from src to the directory that will contain the file,
          using forward slashes.
      output_dir: Directory to output the sources to.
      global_string_map: Map of variable names to their string values. These
          variables will be available as globals.
  """ # Write header file. # Write cc file.
base_name
The basename of the file, without the extension.
The basename of the file without the extension .
dir_from_src
Path from src to the directory that will contain the file,
using forward slashes.
Path from src to the directory that will contain the file using forward slashes .
output_dir
Directory to output the sources to.
Directory to output the sources to .
global_string_map
Map of variable names to their string values. These
variables will be available as globals.
Map of variable names to their string values . These variables will be available as globals .