(lines, build_dir)
return flags_by_output
Turn a list of command lines into a semi-structured dict.
Turn a list of command lines into a semi-structured dict.
Turn a list of command lines into a semi - structured dict .
def GetFlags(lines, build_dir):
  """Turn a list of command lines into a semi-structured dict."""
  is_win = sys.platform == 'win32'
  flags_by_output = {}
  for line in lines:
    command_line = shlex.split(line.strip(), posix=not is_win)[1:]

    output_name = FindAndRemoveArgWithValue(command_line, '-o')
    dep_name = FindAndRemoveArgWithValue(command_line, '-MF')

    NormalizeSymbolArguments(command_line)

    command_line = MergeSpacedArgs(command_line, '-Xclang')

    cc_file = [x for x in command_line if x.endswith('.cc') or
                                          x.endswith('.c') or
                                          x.endswith('.cpp')]
    if len(cc_file) != 1:
      print 'Skipping %s' % command_line
      continue
    assert len(cc_file) == 1

    if is_win:
      rsp_file = [x for x in command_line if x.endswith('.rsp')]
      assert len(rsp_file) <= 1
      if rsp_file:
        rsp_file = os.path.join(build_dir, rsp_file[0][1:])
        with open(rsp_file, "r") as open_rsp_file:
          command_line = shlex.split(open_rsp_file, posix=False)

    defines = [x for x in command_line if x.startswith('-D')]
    include_dirs = [x for x in command_line if x.startswith('-I')]
    dash_f = [x for x in command_line if x.startswith('-f')]
    warnings = \
        [x for x in command_line if x.startswith('/wd' if is_win else '-W')]
    others = [x for x in command_line if x not in defines and \
                                         x not in include_dirs and \
                                         x not in dash_f and \
                                         x not in warnings and \
                                         x not in cc_file]

    for index, value in enumerate(include_dirs):
      if value == '-Igen':
        continue
      path = value[2:]
      if not os.path.isabs(path):
        path = os.path.join(build_dir, path)
      include_dirs[index] = '-I' + os.path.normpath(path)

    # GYP supports paths above the source root like <(DEPTH)/../foo while such
    # paths are unsupported by gn. But gn allows to use system-absolute paths
    # instead (paths that start with single '/'). Normalize all paths.
    cc_file = [os.path.normpath(os.path.join(build_dir, cc_file[0]))]

    # Filter for libFindBadConstructs.so having a relative path in one and
    # absolute path in the other.
    others_filtered = []
    for x in others:
      if x.startswith('-Xclang ') and x.endswith('libFindBadConstructs.so'):
        others_filtered.append(
            '-Xclang ' +
            os.path.join(os.getcwd(),
                         os.path.normpath(
                             os.path.join('out/gn_flags', x.split(' ', 1)[1]))))
      elif x.startswith('-B'):
        others_filtered.append(
            '-B' +
            os.path.join(os.getcwd(),
                         os.path.normpath(os.path.join('out/gn_flags', x[2:]))))
      else:
        others_filtered.append(x)
    others = others_filtered

    flags_by_output[cc_file[0]] = {
      'output': output_name,
      'depname': dep_name,
      'defines': sorted(defines),
      'include_dirs': sorted(include_dirs),  # TODO(scottmg): This is wrong.
      'dash_f': sorted(dash_f),
      'warnings': sorted(warnings),
      'other': sorted(others),
    }
  return flags_by_output
def GetFlags ( lines , build_dir ) : is_win = sys . platform == 'win32' flags_by_output = { } for line in lines : command_line = shlex . split ( line . strip ( ) , posix = not is_win ) [ 1 : ] output_name = FindAndRemoveArgWithValue ( command_line , '-o' ) dep_name = FindAndRemoveArgWithValue ( command_line , '-MF' ) NormalizeSymbolArguments ( command_line ) command_line = MergeSpacedArgs ( command_line , '-Xclang' ) cc_file = [ x for x in command_line if x . endswith ( '.cc' ) or x . endswith ( '.c' ) or x . endswith ( '.cpp' ) ] if len ( cc_file ) != 1 : print 'Skipping %s' % command_line continue assert len ( cc_file ) == 1 if is_win : rsp_file = [ x for x in command_line if x . endswith ( '.rsp' ) ] assert len ( rsp_file ) <= 1 if rsp_file : rsp_file = os . path . join ( build_dir , rsp_file [ 0 ] [ 1 : ] ) with open ( rsp_file , "r" ) as open_rsp_file : command_line = shlex . split ( open_rsp_file , posix = False ) defines = [ x for x in command_line if x . startswith ( '-D' ) ] include_dirs = [ x for x in command_line if x . startswith ( '-I' ) ] dash_f = [ x for x in command_line if x . startswith ( '-f' ) ] warnings = [ x for x in command_line if x . startswith ( '/wd' if is_win else '-W' ) ] others = [ x for x in command_line if x not in defines and x not in include_dirs and x not in dash_f and x not in warnings and x not in cc_file ] for index , value in enumerate ( include_dirs ) : if value == '-Igen' : continue path = value [ 2 : ] if not os . path . isabs ( path ) : path = os . path . join ( build_dir , path ) include_dirs [ index ] = '-I' + os . path . normpath ( path ) # GYP supports paths above the source root like <(DEPTH)/../foo while such # paths are unsupported by gn. But gn allows to use system-absolute paths # instead (paths that start with single '/'). Normalize all paths. cc_file = [ os . path . normpath ( os . path . join ( build_dir , cc_file [ 0 ] ) ) ] # Filter for libFindBadConstructs.so having a relative path in one and # absolute path in the other. others_filtered = [ ] for x in others : if x . startswith ( '-Xclang ' ) and x . endswith ( 'libFindBadConstructs.so' ) : others_filtered . append ( '-Xclang ' + os . path . join ( os . getcwd ( ) , os . path . normpath ( os . path . join ( 'out/gn_flags' , x . split ( ' ' , 1 ) [ 1 ] ) ) ) ) elif x . startswith ( '-B' ) : others_filtered . append ( '-B' + os . path . join ( os . getcwd ( ) , os . path . normpath ( os . path . join ( 'out/gn_flags' , x [ 2 : ] ) ) ) ) else : others_filtered . append ( x ) others = others_filtered flags_by_output [ cc_file [ 0 ] ] = { 'output' : output_name , 'depname' : dep_name , 'defines' : sorted ( defines ) , 'include_dirs' : sorted ( include_dirs ) , # TODO(scottmg): This is wrong. 'dash_f' : sorted ( dash_f ) , 'warnings' : sorted ( warnings ) , 'other' : sorted ( others ) , } return flags_by_output