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 #2
0
def UpdateProjects(pepperdir,
                   project_tree,
                   toolchains,
                   clobber=False,
                   configs=None,
                   first_toolchain=False):
    if configs is None:
        configs = ['Debug', 'Release']
    if not os.path.exists(os.path.join(pepperdir, 'tools')):
        buildbot_common.ErrorExit('Examples depend on missing tools.')
    if not os.path.exists(os.path.join(pepperdir, 'toolchain')):
        buildbot_common.ErrorExit('Examples depend on missing toolchains.')

    ValidateToolchains(toolchains)

    # Create the library output directories
    libdir = os.path.join(pepperdir, 'lib')
    platform = getos.GetPlatform()
    for config in configs:
        for arch in LIB_DICT[platform]:
            dirpath = os.path.join(libdir, '%s_%s_host' % (platform, arch),
                                   config)
            if clobber:
                buildbot_common.RemoveDir(dirpath)
            buildbot_common.MakeDir(dirpath)

    landing_page = None
    for branch, projects in project_tree.iteritems():
        dirpath = os.path.join(pepperdir, branch)
        if clobber:
            buildbot_common.RemoveDir(dirpath)
        buildbot_common.MakeDir(dirpath)
        targets = [desc['NAME'] for desc in projects]

        # Generate master make for this branch of projects
        generate_make.GenerateMasterMakefile(pepperdir,
                                             os.path.join(pepperdir, branch),
                                             targets)

        if branch.startswith('examples') and not landing_page:
            landing_page = LandingPage()

        # Generate individual projects
        for desc in projects:
            srcroot = os.path.dirname(desc['FILEPATH'])
            generate_make.ProcessProject(pepperdir,
                                         srcroot,
                                         pepperdir,
                                         desc,
                                         toolchains,
                                         configs=configs,
                                         first_toolchain=first_toolchain)

            if branch.startswith('examples'):
                landing_page.AddDesc(desc)

    if landing_page:
        # Generate the landing page text file.
        index_html = os.path.join(pepperdir, 'examples', 'index.html')
        index_template = os.path.join(SDK_RESOURCE_DIR, 'index.html.template')
        with open(index_html, 'w') as fh:
            out = landing_page.GeneratePage(index_template)
            fh.write(out)

    # Generate top Make for examples
    targets = ['api', 'demo', 'getting_started', 'tutorial']
    targets = [x for x in targets if 'examples/' + x in project_tree]
    branch_name = 'examples'
    generate_make.GenerateMasterMakefile(pepperdir,
                                         os.path.join(pepperdir, branch_name),
                                         targets)
Exemple #3
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