Skip to content

[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

Merged
merged 3 commits into from
Feb 26, 2018
Merged

Conversation

Rostepher
Copy link
Contributor

Purpose

This PR implements a new presets module with a more robust and easy to understand presets parser compared to the swift_build_support implementation in SwiftBuildSupport.py. The --swift-sdks migration code has also been moved to a new migration module that will house functionality for eventually migrating away from build-script-impl.

There's testing for all the new functionality, both the presets and migration modules have associated test suites.

This furthers the efforts for completing SR-237
rdar://25281853

… 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.
@Rostepher
Copy link
Contributor Author

@swift-ci please test

@Rostepher Rostepher self-assigned this Feb 6, 2018
@Rostepher Rostepher requested review from zisko and rintaro February 6, 2018 04:42
@Rostepher
Copy link
Contributor Author

On second thought, I can add testing to compare the results of the previous preset-parsing code to the new PresetParser if that would give everyone more confidence.

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)
Copy link
Member

@rintaro rintaro Feb 6, 2018

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"
   }
}

Copy link
Contributor Author

@Rostepher Rostepher Feb 6, 2018

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.

Copy link
Member

@rintaro rintaro Feb 6, 2018

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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?

self._presets = {}

def _parse_raw_preset(self, section):
preset_name = _remove_prefix(section, PresetParser._PRESET_PREFIX)
Copy link
Member

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?

Copy link
Contributor Author

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.

for mixin_name in raw_preset.mixins:
mixin = self._get_preset(mixin_name)

args += mixin.args
Copy link
Member

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.

Copy link
Contributor Author

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.
@Rostepher
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Feb 6, 2018

Build failed
Swift Test OS X Platform
Git Sha - 4342207

@swift-ci
Copy link
Contributor

swift-ci commented Feb 6, 2018

Build failed
Swift Test Linux Platform
Git Sha - 4342207

@Rostepher
Copy link
Contributor Author

@swift-ci please test Linux

@shahmishal
Copy link
Member

@swift-ci Build Toolchain

@Rostepher
Copy link
Contributor Author

@swift-ci please Build Toolchain macOS

@swift-ci
Copy link
Contributor

swift-ci commented Feb 7, 2018

macOS Toolchain
Download Toolchain
Git Sha - 009b6aa

Install command
tar -zxf swift-PR-14422-15-osx.tar.gz --directory ~/

@Rostepher
Copy link
Contributor Author

@swift-ci please test

@Rostepher
Copy link
Contributor Author

@swift-ci please build toolchain

@swift-ci
Copy link
Contributor

swift-ci commented Feb 8, 2018

Build failed
Swift Test Linux Platform
Git Sha - 009b6aa

@swift-ci
Copy link
Contributor

swift-ci commented Feb 9, 2018

Build failed
Swift Test OS X Platform
Git Sha - 009b6aa

@Rostepher
Copy link
Contributor Author

@swift-ci please test

@Rostepher
Copy link
Contributor Author

@swift-ci please build toolchain

@swift-ci
Copy link
Contributor

swift-ci commented Feb 9, 2018

Build failed
Swift Test OS X Platform
Git Sha - 74909c4fb1903e281e157b998740570b0f3a3eef

@swift-ci
Copy link
Contributor

swift-ci commented Feb 9, 2018

Build failed
Swift Test Linux Platform
Git Sha - 74909c4fb1903e281e157b998740570b0f3a3eef

@Rostepher
Copy link
Contributor Author

@swift-ci please test

@Rostepher
Copy link
Contributor Author

@swift-ci please build toolchain

@swift-ci
Copy link
Contributor

swift-ci commented Feb 9, 2018

Build failed
Swift Test Linux Platform
Git Sha - e99dc545a9c046df387d50d551bd825c8ae02828

@swift-ci
Copy link
Contributor

swift-ci commented Feb 9, 2018

Build failed
Swift Test OS X Platform
Git Sha - e99dc545a9c046df387d50d551bd825c8ae02828

@Rostepher
Copy link
Contributor Author

@swift-ci please test

@Rostepher
Copy link
Contributor Author

@swift-ci please build toolchain

@swift-ci
Copy link
Contributor

swift-ci commented Feb 9, 2018

Build failed
Swift Test Linux Platform
Git Sha - 95e70c22241d157dc5d8fe897f88467dad15c629

@swift-ci
Copy link
Contributor

swift-ci commented Feb 9, 2018

Build failed
Swift Test OS X Platform
Git Sha - 95e70c22241d157dc5d8fe897f88467dad15c629

@Rostepher
Copy link
Contributor Author

@swift-ci please build toolchain macOS

@swift-ci
Copy link
Contributor

swift-ci commented Feb 9, 2018

macOS Toolchain
Download Toolchain
Git Sha - 6793553acc9570a28a233a1d2e7fc213ef71ef92

Install command
tar -zxf swift-PR-14422-26-osx.tar.gz --directory ~/

…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.
@Rostepher
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 6793553acc9570a28a233a1d2e7fc213ef71ef92

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 6793553acc9570a28a233a1d2e7fc213ef71ef92

Copy link
Contributor

@zisko zisko left a 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)
Copy link
Contributor

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?

@Rostepher
Copy link
Contributor Author

@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 ConfigParser module (which is substantially different from the Python 3 configparser) that will make it more difficult to implement. We'd need to have a separate ConfigParser instance per file read and then validate each preset is not repeated, but in Python 2 it's not possible to validate that sections in the same file (i.e. presets) are unique.

@Rostepher Rostepher merged commit 4edb8d9 into swiftlang:master Feb 26, 2018
Rostepher added a commit to Rostepher/swift that referenced this pull request Feb 26, 2018
* 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.
Rostepher added a commit that referenced this pull request Feb 27, 2018
* 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.
@Rostepher Rostepher deleted the presets-module branch January 19, 2020 20:31
@AnthonyLatsis AnthonyLatsis added build-script Area → utils: The build script improvement and removed enhancement labels Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-script Area → utils: The build script improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants