output_commands.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #
  2. # Copyright 2021 Espressif Systems (Shanghai) CO LTD
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from entity import Entity
  17. class InputSectionDesc():
  18. def __init__(self, entity, sections, exclusions=None):
  19. assert(entity.specificity != Entity.Specificity.SYMBOL)
  20. self.entity = entity
  21. self.sections = set(sections)
  22. self.exclusions = set()
  23. if exclusions:
  24. assert(not [e for e in exclusions if e.specificity == Entity.Specificity.SYMBOL or
  25. e.specificity == Entity.Specificity.NONE])
  26. self.exclusions = set(exclusions)
  27. else:
  28. self.exclusions = set()
  29. def __str__(self):
  30. if self.sections:
  31. exclusion_strings = []
  32. for exc in sorted(self.exclusions):
  33. if exc.specificity == Entity.Specificity.ARCHIVE:
  34. exc_string = '*%s' % (exc.archive)
  35. else:
  36. exc_string = '*%s:%s.*' % (exc.archive, exc.obj)
  37. exclusion_strings.append(exc_string)
  38. section_strings = []
  39. if exclusion_strings:
  40. exclusion_string = 'EXCLUDE_FILE(%s)' % ' '.join(exclusion_strings)
  41. for section in sorted(self.sections):
  42. section_strings.append('%s %s' % (exclusion_string, section))
  43. else:
  44. for section in sorted(self.sections):
  45. section_strings.append(section)
  46. sections_string = '(%s)' % ' '.join(section_strings)
  47. else:
  48. sections_string = '( )'
  49. command = None
  50. if self.entity.specificity == Entity.Specificity.NONE:
  51. command = '*%s' % (sections_string)
  52. elif self.entity.specificity == Entity.Specificity.ARCHIVE:
  53. command = '*%s:%s' % (self.entity.archive, sections_string)
  54. else:
  55. command = '*%s:%s.*%s' % (self.entity.archive, self.entity.obj, sections_string)
  56. return command
  57. def __eq__(self, other):
  58. return (self.entity == other.entity and
  59. self.sections == other.sections and
  60. self.exclusions == other.exclusions)