-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[build-script] Presets Module #14422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… understand parser. Moved the swift-sdks migration code to a new migration module and added testing for both the presets and migration modules. Also converted build-script to use the new presets parser.
@swift-ci please test |
On second thought, I can add testing to compare the results of the previous preset-parsing code to the new |
os.path.join( | ||
SWIFT_SOURCE_ROOT, SWIFT_REPO_NAME, "utils", | ||
"build-presets.ini") | ||
] | ||
|
||
user_presets_file = os.path.join(HOME, '.swift-build-presets') | ||
if os.path.isfile(user_presets_file): | ||
args.preset_file_names.append(user_presets_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is technically a behavior change.
If the both files has presets in a same name, ConfigParser
merges those sections. e.g.
# preset1.ini
[section]
opt1 = True
opt2 = foo
# preset2.ini
[section]
opt1 = False
opt3 = bar
parser.read(['preset1.ini', 'preset2.ini'])
will be like:
{
"section": {
"opt1": "False", // NOTE: preset2.ini overwrites this
"opt2": "foo",
"opt3": "bar"
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced this is a behavior change. The old presets parsing code could read in more than one file at a time as well (namely the _load_preset_files_impl
function).
All I've done here is add checking to ensure that the user presets file (~/.swift-build-presets
) exists before trying to parse it and failing. The previous implementation would only fail if all the presets files failed to parse, which ignored the failure for a non-existing user presets file. My implementation is more strict and will throw an exception for any missing files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant the order in the preset_file_names
might affect the result of the parsing.
In your implementation, the order is ['utils/build-presets.ini', '~/.swift-build-presets']
, whereas the current master implementation is ['~/.swift-build-presets', 'utils/build-presets.ini']
.
When ~/.swift-build-presets
declares an option with the same name in the same section name in utils/build-presets.ini
, in the current implementation, it will be ignored because it will be overwritten by the latter file.
To keep the current behavior, the code should insert ~/.swift-build-presets
at the top of the list.
if os.path.isfile(user_presets_file):
args.preset_file_names.insert(0, user_presets_file)
That's said, I think your implementation is OK because user defined (~/.swift-build-presets
) value should be able to override the default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather keep this functionality change (however slight) since you make a good point. User presets should be able to override the built-in ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should enforce that every file should have unique presets. It could save someone from a really bad day, and is there any real win with the use case of overriding presets?
utils/build_swift/presets.py
Outdated
self._presets = {} | ||
|
||
def _parse_raw_preset(self, section): | ||
preset_name = _remove_prefix(section, PresetParser._PRESET_PREFIX) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SwiftBuildSupport.py
used to ignore non-prefixed sections.
Are we going to make preset:
optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the time-being we are going to maintain feature parity with the old implementation. In the future we might consider changing the format some.
utils/build_swift/presets.py
Outdated
for mixin_name in raw_preset.mixins: | ||
mixin = self._get_preset(mixin_name) | ||
|
||
args += mixin.args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[preset: base]
opt1 = 0
opt2 = 0
[preset: derived]
opt1 = 1
mixin-preset = base
opt2 = 1
should emit --opt1=1 --opt1=0 --opt2=0 --opt2=1
so the derived preset can override the options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was an oversight on my part. I didn't realize that it was possible to have mixins expanded in-place. I had only ever seen them declared at the beginning of a preset. I'll modify my parser to preserve this behavior and add some testing for it. Thanks!
…nown feature) and also changed the parser to skip all non-preset sections. Tests are included for these two behaviors.
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test Linux |
@swift-ci Build Toolchain |
@swift-ci please Build Toolchain macOS |
macOS Toolchain Install command |
@swift-ci please test |
@swift-ci please build toolchain |
Build failed |
Build failed |
74909c4
to
e99dc54
Compare
@swift-ci please test |
@swift-ci please build toolchain |
Build failed |
Build failed |
e99dc54
to
95e70c2
Compare
@swift-ci please test |
@swift-ci please build toolchain |
Build failed |
Build failed |
95e70c2
to
6793553
Compare
@swift-ci please test |
@swift-ci please build toolchain |
Build failed |
Build failed |
@swift-ci please build toolchain macOS |
macOS Toolchain Install command |
…formation packed exception classes. Also re-worked the PresetParser to catch duplicate preset declarations and duplicate options in a single preset. There's some special shim-code to handle the disconnect between the Python 2 ConfigParser module and the Python 3 update which adds DuplicateOptionError.
6793553
to
0113466
Compare
@swift-ci please test |
Build failed |
Build failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
os.path.join( | ||
SWIFT_SOURCE_ROOT, SWIFT_REPO_NAME, "utils", | ||
"build-presets.ini") | ||
] | ||
|
||
user_presets_file = os.path.join(HOME, '.swift-build-presets') | ||
if os.path.isfile(user_presets_file): | ||
args.preset_file_names.append(user_presets_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should enforce that every file should have unique presets. It could save someone from a really bad day, and is there any real win with the use case of overriding presets?
@zisko Ultimately I would like to enforce uniqueness, but at the moment I don't want to modify functionality. There's also some technical limitations with the Python 2 |
* Implemented a presets module which includes a more robust and easy to understand parser. Moved the swift-sdks migration code to a new migration module and added testing for both the presets and migration modules. Also converted build-script to use the new presets parser. * Switched the expansion algorithm to resolve mixins in-place (little known feature) and also changed the parser to skip all non-preset sections. Tests are included for these two behaviors. * Re-worked the presets error hierarchy to have more descriptive and information packed exception classes. Also re-worked the PresetParser to catch duplicate preset declarations and duplicate options in a single preset. There's some special shim-code to handle the disconnect between the Python 2 ConfigParser module and the Python 3 update which adds DuplicateOptionError.
* Implemented a presets module which includes a more robust and easy to understand parser. Moved the swift-sdks migration code to a new migration module and added testing for both the presets and migration modules. Also converted build-script to use the new presets parser. * Switched the expansion algorithm to resolve mixins in-place (little known feature) and also changed the parser to skip all non-preset sections. Tests are included for these two behaviors. * Re-worked the presets error hierarchy to have more descriptive and information packed exception classes. Also re-worked the PresetParser to catch duplicate preset declarations and duplicate options in a single preset. There's some special shim-code to handle the disconnect between the Python 2 ConfigParser module and the Python 3 update which adds DuplicateOptionError.
Purpose
This PR implements a new
presets
module with a more robust and easy to understand presets parser compared to theswift_build_support
implementation inSwiftBuildSupport.py
. The--swift-sdks
migration code has also been moved to a newmigration
module that will house functionality for eventually migrating away frombuild-script-impl
.There's testing for all the new functionality, both the
presets
andmigration
modules have associated test suites.This furthers the efforts for completing SR-237
rdar://25281853