tools/clang/scripts/goma_link.py
def analyze_expanded_args(self, args, output, linker, gen_dir, common_dir,
                            use_common_objects):
    """
    Helper function for analyze_args. This is called by analyze_args after
    expanding rsp files and determining which files are bitcode files, and
    produces codegen_params, final_params, and index_params.

    This function interacts with the filesystem through os.path.exists,
    is_bitcode_file, and ensure_file.
    """
    if 'clang' in os.path.basename(linker):
      compiler = linker
    else:
      compiler_dir = os.path.dirname(linker)
      if compiler_dir:
        compiler_dir += '/'
      else:
        compiler_dir = ''
      compiler = compiler_dir + 'clang-cl' + exe_suffix()

    if use_common_objects:
      obj_dir = common_dir
    else:
      obj_dir = gen_dir

    common_index = common_dir + '/empty.thinlto.bc'
    index_inputs = set()
    index_params = []
    codegen = []
    codegen_params = [
        '-Wno-unused-command-line-argument',
        '-Wno-override-module',
    ]
    final_inputs = set()
    final_params = []
    in_mllvm = [False]

    # Defaults that match those for local linking.
    optlevel = [2]
    data_sections = [True]
    function_sections = [True]

    def extract_opt_level(param):
      """
      If param is a parameter that specifies the LTO optimization level,
      returns the level. If not, returns None.
      """
      match = re.match('(?:-Wl,)?--lto-O(.+)', param)
      if match:
        return match.group(1)
      match = re.match('[-/]opt:.*lldlto=([^:]*)', param, re.IGNORECASE)
      if match:
        return match.group(1)
      return None

    def process_param(param):
      """
      Common code for processing a single parameter from the either the
      command line or an rsp file.
      """

      def helper():
        """
        This exists so that we can use return instead of
        nested if statements to use the first matching case.
        """
        # After -mllvm, just pass on the param.
        if in_mllvm[0]:
          if param.startswith('-Wl,'):
            codegen_params.append(param[4:])
          else:
            codegen_params.append(param)
          in_mllvm[0] = False
          return

        # Check for params that specify LTO optimization level.
        o = extract_opt_level(param)
        if o is not None:
          optlevel[0] = o
          return

        # Check for params that affect code generation.
        cg_param = self.transform_codegen_param(param)
        if cg_param:
          codegen_params.extend(cg_param)
          # No return here, we still want to check for -mllvm.

        # Check for -mllvm.
        match = self.MLLVM_RE.match(param)
        if match and not match.group(2):
          # Next parameter will be the thing to pass to LLVM.
          in_mllvm[0] = True

      # Parameters that override defaults disable the defaults; the
      # final value is set by passing through the parameter.
      if self.DATA_SECTIONS_RE.match(param):
        data_sections[0] = False
      if self.FUNCTION_SECTIONS_RE.match(param):
        function_sections[0] = False

      helper()
      if self.GROUP_RE.match(param):
        return
      index_params.append(param)
      if os.path.exists(param):
        index_inputs.add(param)
        match = self.OBJ_RE.match(param)
        if match and is_bitcode_file(param):
          native = obj_dir + '/' + match.group(1) + '.' + match.group(2)
          if use_common_objects:
            index = common_index
          else:
            index = obj_dir + '/' + param + '.thinlto.bc'
            ensure_file(index)
          codegen.append((os.path.normpath(native), param, index))
        else:
          final_inputs.add(param)
          final_params.append(param)
      elif not self.LTO_RE.match(param):
        final_params.append(param)

    index_params.append(self.WL + self.PREFIX_REPLACE + ';' + obj_dir + '/')
    i = 0
    while i < len(args):
      x = args[i]
      if not self.GROUP_RE.match(x):
        outfile, next_i = self.process_output_param(args, i)
        if outfile is not None:
          index_params.extend(args[i:next_i])
          final_params.extend(args[i:next_i])
          i = next_i - 1
        else:
          process_param(x)
      i += 1

    # If we are not doing ThinLTO codegen, just invoke the original command.
    if len(codegen) < 1:
      return None

    codegen_params.append('-O' + str(optlevel[0]))
    if data_sections[0]:
      codegen_params.append(self.DATA_SECTIONS)
    if function_sections[0]:
      codegen_params.append(self.FUNCTION_SECTIONS)

    if use_common_objects:
      splitfile = None
      for tup in codegen:
        final_params.append(tup[0])
      index_inputs = []
    else:
      splitfile = gen_dir + '/' + output + '.split' + self.OBJ_SUFFIX
      final_params.append(splitfile)
      index_params.append(self.WL + self.OBJ_PATH + splitfile)
      used_obj_file = gen_dir + '/' + os.path.basename(output) + '.objs'
      final_params.append('@' + used_obj_file)

    return AnalyzeArgsResult(
        output=output,
        linker=linker,
        compiler=compiler,
        splitfile=splitfile,
        index_inputs=index_inputs,
        index_params=index_params,
        codegen=codegen,
        codegen_params=codegen_params,
        final_inputs=final_inputs,
        final_params=final_params,
    )

    Helper function for analyze_args. This is called by analyze_args after
    expanding rsp files and determining which files are bitcode files, and
    produces codegen_params, final_params, and index_params.

    This function interacts with the filesystem through os.path.exists,
    is_bitcode_file, and ensure_file.
    
Helper function for analyze_args. This is called by analyze_args after
expanding rsp files and determining which files are bitcode files, and
produces codegen_params, final_params, and index_params.

This function interacts with the filesystem through os.path.exists,
is_bitcode_file, and ensure_file.
Helper function for analyze_args . This is called by analyze_args after expanding rsp files and determining which files are bitcode files and produces codegen_params final_params and index_params . This function interacts with the filesystem through os . path . exists is_bitcode_file and ensure_file .
def analyze_expanded_args(self, args, output, linker, gen_dir, common_dir,
                            use_common_objects):
    if 'clang' in os.path.basename(linker):
      compiler = linker
    else:
      compiler_dir = os.path.dirname(linker)
      if compiler_dir:
        compiler_dir += '/'
      else:
        compiler_dir = ''
      compiler = compiler_dir + 'clang-cl' + exe_suffix()
    if use_common_objects:
      obj_dir = common_dir
    else:
      obj_dir = gen_dir
    common_index = common_dir + '/empty.thinlto.bc'
    index_inputs = set()
    index_params = []
    codegen = []
    codegen_params = [
        '-Wno-unused-command-line-argument',
        '-Wno-override-module',
    ]
    final_inputs = set()
    final_params = []
    in_mllvm = [False]
    optlevel = [2]
    data_sections = [True]
    function_sections = [True]
    def extract_opt_level(param):
      match = re.match('(?:-Wl,)?--lto-O(.+)', param)
      if match:
        return match.group(1)
      match = re.match('[-/]opt:.*lldlto=([^:]*)', param, re.IGNORECASE)
      if match:
        return match.group(1)
      return None
    def process_param(param):
      def helper():
        if in_mllvm[0]:
          if param.startswith('-Wl,'):
            codegen_params.append(param[4:])
          else:
            codegen_params.append(param)
          in_mllvm[0] = False
          return
        o = extract_opt_level(param)
        if o is not None:
          optlevel[0] = o
          return
        cg_param = self.transform_codegen_param(param)
        if cg_param:
          codegen_params.extend(cg_param)
        match = self.MLLVM_RE.match(param)
        if match and not match.group(2):
          in_mllvm[0] = True
      if self.DATA_SECTIONS_RE.match(param):
        data_sections[0] = False
      if self.FUNCTION_SECTIONS_RE.match(param):
        function_sections[0] = False
      helper()
      if self.GROUP_RE.match(param):
        return
      index_params.append(param)
      if os.path.exists(param):
        index_inputs.add(param)
        match = self.OBJ_RE.match(param)
        if match and is_bitcode_file(param):
          native = obj_dir + '/' + match.group(1) + '.' + match.group(2)
          if use_common_objects:
            index = common_index
          else:
            index = obj_dir + '/' + param + '.thinlto.bc'
            ensure_file(index)
          codegen.append((os.path.normpath(native), param, index))
        else:
          final_inputs.add(param)
          final_params.append(param)
      elif not self.LTO_RE.match(param):
        final_params.append(param)
    index_params.append(self.WL + self.PREFIX_REPLACE + ';' + obj_dir + '/')
    i = 0
    while i < len(args):
      x = args[i]
      if not self.GROUP_RE.match(x):
        outfile, next_i = self.process_output_param(args, i)
        if outfile is not None:
          index_params.extend(args[i:next_i])
          final_params.extend(args[i:next_i])
          i = next_i - 1
        else:
          process_param(x)
      i += 1
    if len(codegen) < 1:
      return None
    codegen_params.append('-O' + str(optlevel[0]))
    if data_sections[0]:
      codegen_params.append(self.DATA_SECTIONS)
    if function_sections[0]:
      codegen_params.append(self.FUNCTION_SECTIONS)
    if use_common_objects:
      splitfile = None
      for tup in codegen:
        final_params.append(tup[0])
      index_inputs = []
    else:
      splitfile = gen_dir + '/' + output + '.split' + self.OBJ_SUFFIX
      final_params.append(splitfile)
      index_params.append(self.WL + self.OBJ_PATH + splitfile)
      used_obj_file = gen_dir + '/' + os.path.basename(output) + '.objs'
      final_params.append('@' + used_obj_file)
    return AnalyzeArgsResult(
        output=output,
        linker=linker,
        compiler=compiler,
        splitfile=splitfile,
        index_inputs=index_inputs,
        index_params=index_params,
        codegen=codegen,
        codegen_params=codegen_params,
        final_inputs=final_inputs,
        final_params=final_params,
    )
def analyze_expanded_args ( self , args , output , linker , gen_dir , common_dir , use_common_objects ) : if 'clang' in os . path . basename ( linker ) : compiler = linker else : compiler_dir = os . path . dirname ( linker ) if compiler_dir : compiler_dir += '/' else : compiler_dir = '' compiler = compiler_dir + 'clang-cl' + exe_suffix ( ) if use_common_objects : obj_dir = common_dir else : obj_dir = gen_dir common_index = common_dir + '/empty.thinlto.bc' index_inputs = set ( ) index_params = [ ] codegen = [ ] codegen_params = [ '-Wno-unused-command-line-argument' , '-Wno-override-module' , ] final_inputs = set ( ) final_params = [ ] in_mllvm = [ False ] optlevel = [ 2 ] data_sections = [ True ] function_sections = [ True ] def extract_opt_level ( param ) : """
      If param is a parameter that specifies the LTO optimization level,
      returns the level. If not, returns None.
      """ match = re . match ( '(?:-Wl,)?--lto-O(.+)' , param ) if match : return match . group ( 1 ) match = re . match ( '[-/]opt:.*lldlto=([^:]*)' , param , re . IGNORECASE ) if match : return match . group ( 1 ) return None def process_param ( param ) : """
      Common code for processing a single parameter from the either the
      command line or an rsp file.
      """ def helper ( ) : """
        This exists so that we can use return instead of
        nested if statements to use the first matching case.
        """ if in_mllvm [ 0 ] : if param . startswith ( '-Wl,' ) : codegen_params . append ( param [ 4 : ] ) else : codegen_params . append ( param ) in_mllvm [ 0 ] = False return o = extract_opt_level ( param ) if o is not None : optlevel [ 0 ] = o return cg_param = self . transform_codegen_param ( param ) if cg_param : codegen_params . extend ( cg_param ) match = self . MLLVM_RE . match ( param ) if match and not match . group ( 2 ) : in_mllvm [ 0 ] = True if self . DATA_SECTIONS_RE . match ( param ) : data_sections [ 0 ] = False if self . FUNCTION_SECTIONS_RE . match ( param ) : function_sections [ 0 ] = False helper ( ) if self . GROUP_RE . match ( param ) : return index_params . append ( param ) if os . path . exists ( param ) : index_inputs . add ( param ) match = self . OBJ_RE . match ( param ) if match and is_bitcode_file ( param ) : native = obj_dir + '/' + match . group ( 1 ) + '.' + match . group ( 2 ) if use_common_objects : index = common_index else : index = obj_dir + '/' + param + '.thinlto.bc' ensure_file ( index ) codegen . append ( ( os . path . normpath ( native ) , param , index ) ) else : final_inputs . add ( param ) final_params . append ( param ) elif not self . LTO_RE . match ( param ) : final_params . append ( param ) index_params . append ( self . WL + self . PREFIX_REPLACE + ';' + obj_dir + '/' ) i = 0 while i < len ( args ) : x = args [ i ] if not self . GROUP_RE . match ( x ) : outfile , next_i = self . process_output_param ( args , i ) if outfile is not None : index_params . extend ( args [ i : next_i ] ) final_params . extend ( args [ i : next_i ] ) i = next_i - 1 else : process_param ( x ) i += 1 if len ( codegen ) < 1 : return None codegen_params . append ( '-O' + str ( optlevel [ 0 ] ) ) if data_sections [ 0 ] : codegen_params . append ( self . DATA_SECTIONS ) if function_sections [ 0 ] : codegen_params . append ( self . FUNCTION_SECTIONS ) if use_common_objects : splitfile = None for tup in codegen : final_params . append ( tup [ 0 ] ) index_inputs = [ ] else : splitfile = gen_dir + '/' + output + '.split' + self . OBJ_SUFFIX final_params . append ( splitfile ) index_params . append ( self . WL + self . OBJ_PATH + splitfile ) used_obj_file = gen_dir + '/' + os . path . basename ( output ) + '.objs' final_params . append ( '@' + used_obj_file ) return AnalyzeArgsResult ( output = output , linker = linker , compiler = compiler , splitfile = splitfile , index_inputs = index_inputs , index_params = index_params , codegen = codegen , codegen_params = codegen_params , final_inputs = final_inputs , final_params = final_params , )
Helper function for analyze_args.
Helper function for analyze_args .
"""
    Helper function for analyze_args. This is called by analyze_args after
    expanding rsp files and determining which files are bitcode files, and
    produces codegen_params, final_params, and index_params.

    This function interacts with the filesystem through os.path.exists,
    is_bitcode_file, and ensure_file.
    """ # Defaults that match those for local linking. """
      If param is a parameter that specifies the LTO optimization level,
      returns the level. If not, returns None.
      """ """
      Common code for processing a single parameter from the either the
      command line or an rsp file.
      """ """
        This exists so that we can use return instead of
        nested if statements to use the first matching case.
        """ # After -mllvm, just pass on the param. # Check for params that specify LTO optimization level. # Check for params that affect code generation. # No return here, we still want to check for -mllvm. # Check for -mllvm. # Next parameter will be the thing to pass to LLVM. # Parameters that override defaults disable the defaults; the # final value is set by passing through the parameter. # If we are not doing ThinLTO codegen, just invoke the original command.
self
args
output
linker
gen_dir
common_dir
use_common_objects