Пример #1
0
Файл: make.py Проект: kaadam/GYP
def WriteAutoRegenerationRule(params, root_makefile, makefile_name,
                              build_files, Sourceify):
    """Write the target to regenerate the Makefile."""
    options = params['options']
    build_files_args = [
        gyp.common.RelativePath(filename, options.toplevel_dir)
        for filename in params['build_files_arg']
    ]

    gyp_binary = gyp.common.FixIfRelativePath(params['gyp_binary'],
                                              options.toplevel_dir)
    if not gyp_binary.startswith(os.sep):
        gyp_binary = os.path.join('.', gyp_binary)

    root_makefile.write(
        "quiet_cmd_regen_makefile = ACTION Regenerating $@\n"
        "cmd_regen_makefile = cd $(srcdir); %(cmd)s\n"
        "%(makefile_name)s: %(deps)s\n"
        "\t$(call do_cmd,regen_makefile)\n\n" % {
            'makefile_name':
            makefile_name,
            'deps':
            ' '.join(map(Sourceify, build_files)),
            'cmd':
            gyp.common.EncodePOSIXShellList([gyp_binary, '-fmake'] +
                                            gyp.RegenerateFlags(options) +
                                            build_files_args)
        })
Пример #2
0
def WriteAutoRegenerationRule(params, root_makefile, makefile_name,
                              build_files):
    """Write the target to regenerate the Makefile."""
    options = params['options']
    # Sort to avoid non-functional changes to makefile.
    build_files = sorted(
        [os.path.join('$(LOCAL_PATH)', f) for f in build_files])
    build_files_args = [
        gyp.common.RelativePath(filename, options.toplevel_dir)
        for filename in params['build_files_arg']
    ]
    build_files_args = [
        os.path.join('$(PRIVATE_LOCAL_PATH)', f) for f in build_files_args
    ]
    gyp_binary = gyp.common.FixIfRelativePath(params['gyp_binary'],
                                              options.toplevel_dir)
    makefile_path = os.path.join('$(LOCAL_PATH)', makefile_name)
    if not gyp_binary.startswith(os.sep):
        gyp_binary = os.path.join('.', gyp_binary)
    root_makefile.write('GYP_FILES := \\\n  %s\n\n' %
                        '\\\n  '.join(map(Sourceify, build_files)))
    root_makefile.write('%s: PRIVATE_LOCAL_PATH := $(LOCAL_PATH)\n' %
                        makefile_path)
    root_makefile.write('%s: $(GYP_FILES)\n' % makefile_path)
    root_makefile.write(
        '\techo ACTION Regenerating $@\n\t%s\n\n' %
        gyp.common.EncodePOSIXShellList([gyp_binary, '-fandroid'] +
                                        gyp.RegenerateFlags(options) +
                                        build_files_args))
Пример #3
0
def GenerateOutput(target_list, target_dicts, data, params):
  options = params['options']
  generator_flags = params.get('generator_flags', {})
  builddir_name = generator_flags.get('output_dir', 'out')

  # TODO:  search for the first non-'Default' target.  This can go
  # away when we add verification that all targets have the
  # necessary configurations.
  default_configuration = None
  toolsets = set([target_dicts[target]['toolset'] for target in target_list])
  for target in target_list:
    spec = target_dicts[target]
    if spec['default_configuration'] != 'Default':
      default_configuration = spec['default_configuration']
      break
  if not default_configuration:
    default_configuration = 'Default'

  srcdir = '.'
  makefile_name = 'Makefile' + options.suffix
  makefile_path = os.path.join(options.depth, makefile_name)
  if options.generator_output:
    global srcdir_prefix
    makefile_path = os.path.join(options.generator_output, makefile_path)
    srcdir = gyp.common.RelativePath(srcdir, options.generator_output)
    srcdir_prefix = '$(srcdir)/'
  ensure_directory_exists(makefile_path)
  root_makefile = open(makefile_path, 'w')
  root_makefile.write(SHARED_HEADER_SRCDIR % srcdir)
  root_makefile.write(SHARED_HEADER_BUILDDIR_NAME % builddir_name)
  root_makefile.write(SHARED_HEADER.replace('__default_configuration__',
                                            default_configuration))
  for toolset in toolsets:
    root_makefile.write('TOOLSET := %s\n' % toolset)
    root_makefile.write(ROOT_HEADER_SUFFIX_RULES)

  # Find the list of targets that derive from the gyp file(s) being built.
  needed_targets = set()
  for build_file in params['build_files']:
    for target in gyp.common.AllTargets(target_list, target_dicts, build_file):
      needed_targets.add(target)

  build_files = set()
  include_list = []
  for qualified_target in target_list:
    build_file, target, toolset = gyp.common.ParseQualifiedTarget(
        qualified_target)
    build_files.add(gyp.common.RelativePath(build_file, options.depth))
    included_files = data[build_file]['included_files']
    for included_file in included_files:
      # The included_files entries are relative to the dir of the build file
      # that included them, so we have to undo that and then make them relative
      # to the root dir.
      relative_include_file = gyp.common.RelativePath(
          gyp.common.UnrelativePath(included_file, build_file), options.depth)
      abs_include_file = os.path.abspath(relative_include_file)
      # If the include file is from the ~/.gyp dir, we should use absolute path
      # so that relocating the src dir doesn't break the path.
      if (params['home_dot_gyp'] and
          abs_include_file.startswith(params['home_dot_gyp'])):
        build_files.add(abs_include_file)
      else:
        build_files.add(relative_include_file)

    # Paths in gyp files are relative to the .gyp file, but we want
    # paths relative to the source root for the master makefile.  Grab
    # the path of the .gyp file as the base to relativize against.
    # E.g. "foo/bar" when we're constructing targets found "foo/bar/baz.gyp".
    base_path = gyp.common.RelativePath(os.path.dirname(build_file),
                                        options.depth)
    # We write the .mk file in the base_path directory.
    output_file = os.path.join(options.depth,
                               base_path,
                               target + '.' + toolset + options.suffix + '.mk')

    if options.generator_output:
      output_file = os.path.join(options.generator_output, output_file)

    spec = target_dicts[qualified_target]
    configs = spec['configurations']

    writer = MakefileWriter()
    writer.Write(qualified_target, base_path, output_file, spec, configs,
                 part_of_all=qualified_target in needed_targets)

    # Our root_makefile lives at the source root.  Compute the relative path
    # from there to the output_file for including.
    submakefile_path = gyp.common.RelativePath(output_file,
                                               os.path.dirname(makefile_path))
    include_list.append('include ' + submakefile_path + '\n')

  # Write out the sorted list of includes.
  include_list.sort()
  root_makefile.write('\n')
  for include in include_list:
    root_makefile.write(include)
  root_makefile.write('\n')

  # Write the target to regenerate the Makefile.
  if generator_flags.get('auto_regeneration', True):
    build_files_args = [gyp.common.RelativePath(filename, options.depth)
                        for filename in params['build_files_arg']]
    root_makefile.write("%s: %s\n\t%s\n" % (
        makefile_name,
        ' '.join(map(Sourceify, build_files)),
        gyp.common.EncodePOSIXShellList(
            [gyp.common.FixIfRelativePath(params['gyp_binary'], options.depth),
             '-fmake'] +
            gyp.RegenerateFlags(options) +
            build_files_args)))

  root_makefile.write(SHARED_FOOTER)

  root_makefile.close()