Skip to content

Commit 5852aea

Browse files
author
Ross Bayer
committed
[Build System: build-script] Updated the presets module to simplify the API and improve testability.
1 parent 0405cb5 commit 5852aea

File tree

6 files changed

+260
-150
lines changed

6 files changed

+260
-150
lines changed

utils/build-script

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -968,8 +968,8 @@ def main_preset():
968968
preset_parser = presets.PresetParser()
969969

970970
try:
971-
preset_parser.read(args.preset_file_names)
972-
except presets.Error as e:
971+
preset_parser.read_files(args.preset_file_names)
972+
except presets.PresetError as e:
973973
diagnostics.fatal(e.message)
974974

975975
if args.show_presets:
@@ -987,12 +987,13 @@ def main_preset():
987987
args.preset_substitutions[name] = value
988988

989989
try:
990-
preset = preset_parser.get_preset(args.preset,
991-
vars=args.preset_substitutions)
992-
except presets.Error as e:
990+
preset = preset_parser.get_preset(
991+
args.preset,
992+
vars=args.preset_substitutions)
993+
except presets.PresetError as e:
993994
diagnostics.fatal(e.message)
994995

995-
preset_args = migration.migrate_swift_sdks(preset.format_args())
996+
preset_args = migration.migrate_swift_sdks(preset.args)
996997

997998
if args.distcc and (args.cmake_c_launcher or args.cmake_cxx_launcher):
998999
diagnostics.fatal(
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8+
9+
10+
"""
11+
Class utility functions and decorators.
12+
"""
13+
14+
15+
from __future__ import absolute_import, unicode_literals
16+
17+
18+
__all__ = [
19+
'generate_repr',
20+
]
21+
22+
23+
def generate_repr(*attrs):
24+
"""Generates a standardized __repr__ implementation for the decorated class
25+
using the provided attributes and the class name.
26+
"""
27+
28+
def _repr(self):
29+
args = []
30+
for attr in attrs:
31+
value = getattr(self, attr)
32+
args.append('{}={}'.format(attr, repr(value)))
33+
34+
return '{}({})'.format(type(self).__name__, ', '.join(args))
35+
36+
def decorator(cls):
37+
setattr(cls, '__repr__', _repr)
38+
return cls
39+
40+
return decorator

0 commit comments

Comments
 (0)