Back to index

enigmail  1.4.3
Public Member Functions | Public Attributes | Private Member Functions
expandlibs_exec.ExpandArgsMore Class Reference
Inheritance diagram for expandlibs_exec.ExpandArgsMore:
Inheritance graph
[legend]
Collaboration diagram for expandlibs_exec.ExpandArgsMore:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __enter__
def __exit__
def extract
def makelist
def orderSymbols

Public Attributes

 tmp

Private Member Functions

def _extract
def _getFoldedSections
def _getOrderedSections

Detailed Description

Meant to be used as 'with ExpandArgsMore(args) as ...: 

Definition at line 78 of file expandlibs_exec.py.


Member Function Documentation

Definition at line 80 of file expandlibs_exec.py.

00080 
00081     def __enter__(self):
00082         self.tmp = []
00083         return self
        
def expandlibs_exec.ExpandArgsMore.__exit__ (   self,
  type,
  value,
  tb 
)
Automatically remove temporary files

Definition at line 84 of file expandlibs_exec.py.

00084 
00085     def __exit__(self, type, value, tb):
00086         '''Automatically remove temporary files'''
00087         for tmp in self.tmp:
00088             if os.path.isdir(tmp):
00089                 shutil.rmtree(tmp, True)
00090             else:
00091                 os.remove(tmp)

def expandlibs_exec.ExpandArgsMore._extract (   self,
  args 
) [private]
When a static library name is found, either extract its contents
in a temporary directory or use the information found in the
corresponding lib descriptor.

Definition at line 95 of file expandlibs_exec.py.

00095 
00096     def _extract(self, args):
00097         '''When a static library name is found, either extract its contents
00098         in a temporary directory or use the information found in the
00099         corresponding lib descriptor.
00100         '''
00101         ar_extract = conf.AR_EXTRACT.split()
00102         newlist = []
00103         for arg in args:
00104             if os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
00105                 if os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
00106                     newlist += self._extract(self._expand_desc(arg))
00107                 elif os.path.exists(arg) and len(ar_extract):
00108                     tmp = tempfile.mkdtemp(dir=os.curdir)
00109                     self.tmp.append(tmp)
00110                     subprocess.call(ar_extract + [os.path.abspath(arg)], cwd=tmp)
00111                     objs = []
00112                     for root, dirs, files in os.walk(tmp):
00113                         objs += [relativize(os.path.join(root, f)) for f in files if isObject(f)]
00114                     newlist += objs
00115                 else:
00116                     newlist += [arg]
00117             else:
00118                 newlist += [arg]
00119         return newlist

Here is the call graph for this function:

Here is the caller graph for this function:

Returns a dict about folded sections.
When section A and B are folded into section C, the dict contains:
{ 'A': 'C',
  'B': 'C',
  'C': ['A', 'B'] }

Definition at line 145 of file expandlibs_exec.py.

00145 
00146     def _getFoldedSections(self):
00147         '''Returns a dict about folded sections.
00148         When section A and B are folded into section C, the dict contains:
00149         { 'A': 'C',
00150           'B': 'C',
00151           'C': ['A', 'B'] }'''
00152         if not conf.LD_PRINT_ICF_SECTIONS:
00153             return {}
00154 
00155         proc = subprocess.Popen(self + [conf.LD_PRINT_ICF_SECTIONS], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
00156         (stdout, stderr) = proc.communicate()
00157         result = {}
00158         # gold's --print-icf-sections output looks like the following:
00159         # ld: ICF folding section '.section' in file 'file.o'into '.section' in file 'file.o'
00160         # In terms of words, chances are this will change in the future,
00161         # especially considering "into" is misplaced. Splitting on quotes
00162         # seems safer.
00163         for l in stderr.split('\n'):
00164             quoted = l.split("'")
00165             if len(quoted) > 5 and quoted[1] != quoted[5]:
00166                 result[quoted[1]] = quoted[5]
00167                 if quoted[5] in result:
00168                     result[quoted[5]].append(quoted[1])
00169                 else:
00170                     result[quoted[5]] = [quoted[1]]
00171         return result

Here is the caller graph for this function:

def expandlibs_exec.ExpandArgsMore._getOrderedSections (   self,
  ordered_symbols 
) [private]
Given an ordered list of symbols, returns the corresponding list
of sections following the order.

Definition at line 172 of file expandlibs_exec.py.

00172 
00173     def _getOrderedSections(self, ordered_symbols):
00174         '''Given an ordered list of symbols, returns the corresponding list
00175         of sections following the order.'''
00176         if not conf.EXPAND_LIBS_ORDER_STYLE in ['linkerscript', 'section-ordering-file']:
00177             raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' % conf.EXPAND_LIBS_ORDER_STYLE)
00178         finder = SectionFinder([arg for arg in self if isObject(arg) or os.path.splitext(arg)[1] == conf.LIB_SUFFIX])
00179         folded = self._getFoldedSections()
00180         sections = set()
00181         ordered_sections = []
00182         for symbol in ordered_symbols:
00183             symbol_sections = finder.getSections(symbol)
00184             all_symbol_sections = []
00185             for section in symbol_sections:
00186                 if section in folded:
00187                     if isinstance(folded[section], str):
00188                         section = folded[section]
00189                     all_symbol_sections.append(section)
00190                     all_symbol_sections.extend(folded[section])
00191                 else:
00192                     all_symbol_sections.append(section)
00193             for section in all_symbol_sections:
00194                 if not section in sections:
00195                     ordered_sections.append(section)
00196                     sections.add(section)
00197         return ordered_sections

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 92 of file expandlibs_exec.py.

00092 
00093     def extract(self):
00094         self[0:] = self._extract(self)

Here is the call graph for this function:

Replaces object file names with a temporary list file, using a
list format depending on the EXPAND_LIBS_LIST_STYLE variable

Definition at line 120 of file expandlibs_exec.py.

00120 
00121     def makelist(self):
00122         '''Replaces object file names with a temporary list file, using a
00123         list format depending on the EXPAND_LIBS_LIST_STYLE variable
00124         '''
00125         objs = [o for o in self if isObject(o)]
00126         if not len(objs): return
00127         fd, tmp = tempfile.mkstemp(suffix=".list",dir=os.curdir)
00128         if conf.EXPAND_LIBS_LIST_STYLE == "linkerscript":
00129             content = ["INPUT(%s)\n" % obj for obj in objs]
00130             ref = tmp
00131         elif conf.EXPAND_LIBS_LIST_STYLE == "list":
00132             content = ["%s\n" % obj for obj in objs]
00133             ref = "@" + tmp
00134         else:
00135             os.close(fd)
00136             os.remove(tmp)
00137             return
00138         self.tmp.append(tmp)
00139         f = os.fdopen(fd, "w")
00140         f.writelines(content)
00141         f.close()
00142         idx = self.index(objs[0])
00143         newlist = self[0:idx] + [ref] + [item for item in self[idx:] if item not in objs]
00144         self[0:] = newlist

Here is the call graph for this function:

def expandlibs_exec.ExpandArgsMore.orderSymbols (   self,
  order 
)
Given a file containing a list of symbols, adds the appropriate
argument to make the linker put the symbols in that order.

Definition at line 198 of file expandlibs_exec.py.

00198 
00199     def orderSymbols(self, order):
00200         '''Given a file containing a list of symbols, adds the appropriate
00201         argument to make the linker put the symbols in that order.'''
00202         with open(order) as file:
00203             sections = self._getOrderedSections([l.strip() for l in file.readlines() if l.strip()])
00204         split_sections = {}
00205         linked_sections = [s[0] for s in SECTION_INSERT_BEFORE]
00206         for s in sections:
00207             for linked_section in linked_sections:
00208                 if s.startswith(linked_section):
00209                     if linked_section in split_sections:
00210                         split_sections[linked_section].append(s)
00211                     else:
00212                         split_sections[linked_section] = [s]
00213                     break
00214         content = []
00215         # Order is important
00216         linked_sections = [s for s in linked_sections if s in split_sections]
00217 
00218         if conf.EXPAND_LIBS_ORDER_STYLE == 'section-ordering-file':
00219             option = '-Wl,--section-ordering-file,%s'
00220             content = sections
00221             for linked_section in linked_sections:
00222                 content.extend(split_sections[linked_section])
00223                 content.append('%s.*' % linked_section)
00224                 content.append(linked_section)
00225 
00226         elif conf.EXPAND_LIBS_ORDER_STYLE == 'linkerscript':
00227             option = '-Wl,-T,%s'
00228             section_insert_before = dict(SECTION_INSERT_BEFORE)
00229             for linked_section in linked_sections:
00230                 content.append('SECTIONS {')
00231                 content.append('  %s : {' % linked_section)
00232                 content.extend('    *(%s)' % s for s in split_sections[linked_section])
00233                 content.append('  }')
00234                 content.append('}')
00235                 content.append('INSERT BEFORE %s' % section_insert_before[linked_section])
00236         else:
00237             raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' % conf.EXPAND_LIBS_ORDER_STYLE)
00238 
00239         fd, tmp = tempfile.mkstemp(dir=os.curdir)
00240         f = os.fdopen(fd, "w")
00241         f.write('\n'.join(content)+'\n')
00242         f.close()
00243         self.tmp.append(tmp)
00244         self.append(option % tmp)

Here is the call graph for this function:


Member Data Documentation

Definition at line 81 of file expandlibs_exec.py.


The documentation for this class was generated from the following file: