def LoadProject(filename, toolchains):
    """Generate a Master Makefile that builds all examples.

  Load a project description file, verifying it conforms and checking
  if it matches the set of requested toolchains.  Return None if the
  project is filtered out."""

    Trace('Processing %s...' % filename)
    # Default src directory is the directory the description was found in
    desc = open(filename, 'r').read()
    desc = eval(desc, {}, {})

    # Verify the format of this file
    if not ValidateFormat(desc, DSC_FORMAT):
        ErrorExit('Failed to validate: ' + filename)

    # Check if we are actually interested in this example
    match = False
    for toolchain in toolchains:
        if toolchain in desc['TOOLS']:
            match = True
            break
    if not match:
        return None

    desc['FILENAME'] = filename
    return desc
Exemple #2
0
def FindAndCopyFiles(src_files, root, search_dirs, dst_dir):
  buildbot_common.MakeDir(dst_dir)
  for src_name in src_files:
    src_file = FindFile(src_name, root, search_dirs)
    if not src_file:
      ErrorExit('Failed to find: ' + src_name)
    dst_file = os.path.join(dst_dir, src_name)
    if os.path.exists(dst_file):
      if os.stat(src_file).st_mtime <= os.stat(dst_file).st_mtime:
        print 'Skipping "%s", destination "%s" is newer.' % (src_file, dst_file)
        continue
    buildbot_common.CopyFile(src_file, dst_file)
Exemple #3
0
def AddMakeBat(pepperdir, makepath):
    """Create a simple batch file to execute Make.

  Creates a simple batch file named make.bat for the Windows platform at the
  given path, pointing to the Make executable in the SDK."""

    makepath = os.path.abspath(makepath)
    if not makepath.startswith(pepperdir):
        ErrorExit('Make.bat not relative to Pepper directory: ' + makepath)

    makeexe = os.path.abspath(os.path.join(pepperdir, 'tools'))
    relpath = os.path.relpath(makeexe, makepath)

    fp = open(os.path.join(makepath, 'make.bat'), 'wb')
    outpath = os.path.join(relpath, 'make.exe')

    # Since make.bat is only used by Windows, for Windows path style
    outpath = outpath.replace(os.path.sep, '\\')
    fp.write('@%s %%*\n' % outpath)
    fp.close()
def main(argv):
    usage = "usage: generate_make [options] <dsc_file ..>"
    parser = optparse.OptionParser(usage=usage)
    parser.add_option('--dstroot',
                      help='Set root for destination.',
                      default=os.path.join(OUT_DIR, 'pepper_canary'))
    parser.add_option('--master',
                      help='Create master Makefile.',
                      action='store_true')
    parser.add_option('--newlib',
                      help='Create newlib examples.',
                      action='store_true')
    parser.add_option('--glibc',
                      help='Create glibc examples.',
                      action='store_true')
    parser.add_option('--pnacl',
                      help='Create pnacl examples.',
                      action='store_true')
    parser.add_option('--host',
                      help='Create host examples.',
                      action='store_true')
    parser.add_option('--config',
                      help='Add configuration (debug/release).',
                      action='append')
    parser.add_option('--experimental',
                      help='Create experimental examples.',
                      action='store_true')
    parser.add_option(
        '--first-valid-toolchain',
        help='Only build one toolchain, the first one that is valid.',
        action='store_true')
    parser.add_option('-v',
                      '--verbose',
                      help='Verbose output',
                      action='store_true')

    toolchains = []
    platform = getos.GetPlatform()

    options, args = parser.parse_args(argv)
    if options.verbose:
        Trace.verbose = True
    if options.newlib:
        toolchains.append('newlib')
    if options.glibc:
        toolchains.append('glibc')
    if options.pnacl:
        toolchains.append('pnacl')
    if options.host:
        toolchains.append(platform)

    if not args:
        ErrorExit(
            'Please specify one or more projects to generate Makefiles for.')

    # By default support newlib and glibc
    if not toolchains:
        toolchains = ['newlib', 'glibc', 'pnacl']

    valid_configs = ['Debug', 'Release']
    if options.config:
        configs = []
        for config in options.config:
            if config in valid_configs:
                configs.append(config)
            else:
                ErrorExit('Invalid config: %s' % config)
    else:
        configs = valid_configs

    master_projects = {}

    for i, filename in enumerate(args):
        if i:
            # Print two newlines between each dsc file we process
            Trace('\n')
        desc = LoadProject(filename, toolchains)
        if not desc:
            Trace('Skipping %s, not in [%s].' %
                  (filename, ', '.join(toolchains)))
            continue

        if desc.get('EXPERIMENTAL', False) and not options.experimental:
            Trace('Skipping %s, experimental only.' % (filename, ))
            continue

        srcroot = os.path.dirname(os.path.abspath(filename))
        if not ProcessProject(srcroot, options.dstroot, desc, toolchains,
                              options.first_valid_toolchain):
            ErrorExit('\n*** Failed to process project: %s ***' % filename)

        # if this is an example update it's html file.
        if ShouldProcessHTML(desc):
            ProcessHTML(srcroot, options.dstroot, desc, toolchains, configs,
                        options.first_valid_toolchain)

        # Create a list of projects for each DEST. This will be used to generate a
        # master makefile.
        master_projects.setdefault(desc['DEST'], []).append(desc)

    if master_projects.get('examples'):
        landing_page = LandingPage()
        for desc in master_projects.get('examples'):
            landing_page.AddDesc(desc)

        # Generate the landing page text file.
        index_html = os.path.join(options.dstroot, 'examples', 'index.html')
        example_resources_dir = os.path.join(SDK_EXAMPLE_DIR, 'resources')
        index_template = os.path.join(example_resources_dir,
                                      'index.html.template')
        with open(index_html, 'w') as fh:
            fh.write(landing_page.GeneratePage(index_template))

        # Copy additional files needed for the landing page.
        extra_files = [
            'index.css', 'index.js', 'button_close.png',
            'button_close_hover.png'
        ]
        for filename in extra_files:
            src_file = os.path.join(example_resources_dir, filename)
            dst_file = os.path.join(options.dstroot, 'examples', filename)
            buildbot_common.CopyFile(src_file, dst_file)

    if options.master:
        if use_gyp:
            master_in = os.path.join(SDK_EXAMPLE_DIR, 'Makefile_gyp')
        else:
            master_in = os.path.join(SDK_EXAMPLE_DIR, 'Makefile')
        for dest, projects in master_projects.iteritems():
            master_out = os.path.join(options.dstroot, dest, 'Makefile')
            GenerateMasterMakefile(master_in, master_out, projects)

    return 0
Exemple #5
0
def main(argv):
  usage = "usage: generate_make [options] <dsc_file ..>"
  parser = optparse.OptionParser(usage=usage)
  parser.add_option('--dstroot', help='Set root for destination.',
      default=os.path.join(OUT_DIR, 'pepper_canary'))
  parser.add_option('--master', help='Create master Makefile.',
      action='store_true', default=False)
  parser.add_option('--newlib', help='Create newlib examples.',
      action='store_true', default=False)
  parser.add_option('--glibc', help='Create glibc examples.',
      action='store_true', default=False)
  parser.add_option('--pnacl', help='Create pnacl examples.',
      action='store_true', default=False)
  parser.add_option('--host', help='Create host examples.',
      action='store_true', default=False)
  parser.add_option('--experimental', help='Create experimental examples.',
      action='store_true', default=False)

  toolchains = []
  platform = getos.GetPlatform()

  options, args = parser.parse_args(argv)
  if options.newlib:
    toolchains.append('newlib')
  if options.glibc:
    toolchains.append('glibc')
  if options.pnacl:
    toolchains.append('pnacl')
  if options.host:
    toolchains.append(platform)

  if not args:
    ErrorExit('Please specify one or more projects to generate Makefiles for.')

  # By default support newlib and glibc
  if not toolchains:
    toolchains = ['newlib', 'glibc', 'pnacl']

  master_projects = {}

  landing_page = LandingPage()
  for i, filename in enumerate(args):
    if i:
      # Print two newlines between each dsc file we process
      print '\n'
    desc = LoadProject(filename, toolchains)
    if not desc:
      print 'Skipping %s, not in [%s].' % (filename, ', '.join(toolchains))
      continue

    if desc.get('EXPERIMENTAL', False) and not options.experimental:
      print 'Skipping %s, experimental only.' % (filename,)
      continue

    srcroot = os.path.dirname(os.path.abspath(filename))
    if not ProcessProject(srcroot, options.dstroot, desc, toolchains):
      ErrorExit('\n*** Failed to process project: %s ***' % filename)

    # if this is an example update it's html file.
    if ShouldProcessHTML(desc):
      ProcessHTML(srcroot, options.dstroot, desc, toolchains)

    # if this is an example, update landing page html file.
    if desc['DEST'] == 'examples':
      landing_page.AddDesc(desc)

    # Create a list of projects for each DEST. This will be used to generate a
    # master makefile.
    master_projects.setdefault(desc['DEST'], []).append(desc)

  # Generate the landing page text file.
  index_html = os.path.join(options.dstroot, 'examples', 'index.html')
  with open(index_html, 'w') as fh:
    fh.write(landing_page.GeneratePage())

  if options.master:
    if use_gyp:
      master_in = os.path.join(SDK_EXAMPLE_DIR, 'Makefile_gyp')
    else:
      master_in = os.path.join(SDK_EXAMPLE_DIR, 'Makefile')
    for dest, projects in master_projects.iteritems():
      master_out = os.path.join(options.dstroot, dest, 'Makefile')
      GenerateMasterMakefile(master_in, master_out, projects)

  return 0