Skip to content
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

Replace SwiftPM with Swift Argument Parser #245

Merged
merged 17 commits into from
Jan 6, 2022

Conversation

andrewchang-bird
Copy link
Contributor

@andrewchang-bird andrewchang-bird commented Dec 24, 2021

Motivation

The CLI currently uses the old SwiftPM utils to parse command line arguments, which is no longer source-compatible with the Xcode 13 toolchain / Swift 5.5. Migrating to Swift Argument Parser has been on our backlog for a while and it makes sense to switch now. In addition to offering a more future-proof solution, Swift Argument Parser has a robust feature set that enables us to implement more expressive CLI options.

Considerations

Backwards Compatibility

Backwards compatibility is always important to minimize developer thrash when upgrading. The generate and version commands are used in the critical path for mock generation and can’t be modified much, while the install, download, and testbed commands are only used infrequently such as when setting up new projects.

Duplicate Options

Currently the install command is a rough superset of the generate command as it needs to use those options and flags when configuring the build phase. Although it’s possible to share the parsing and validation logic between the two commands, some of the options are contextual and don’t mix well. For example, it’s reasonable to assume that passing --verbose when configuring a test target will print debug info during the process, but unclear whether it should also carry over to the installed build phase and cause the generator to log verbosely. De-duping options works, but bloats the CLI and makes the options used to configure the generator less predictable.

Setup Process

To simplify setup, adding supporting source files were made an optional step in the guide and default thunk pruning set to omit. Not providing supporting source files for common system frameworks can introduce subtle bugs in generated mocks which are difficult for developers to debug. Ideally, integrating supporting source files into the project should be part of the configuration process.

Implementation

The CLI is almost fully backwards compatible for the generate command but completely replaces install and download with a shiny new configure command. The configure command uses the standard bash double dash (--) to handle parsing and validation of generator options separately. Configuring a test target to generate mocks for a source module in another project is now supported in addition to providing helpful output to streamline the first-time developer experience.

$ mockingbird configure MockingbirdTests -- --targets MockingbirdTestsHost
🛠 Project: ~/mockingbird/Mockingbird.xcodeproj
🎯 Test Target: MockingbirdTests
🧰 Supporting sources: ~/mockingbird/MockingbirdSupport
✅ Downloaded supporting source files
✅ Added build phase 'Generate Mockingbird Mocks'
🎉 Successfully configured MockingbirdTests in 1s
🚀 Usage:
   1. Initialize a mock in your test with `mock(SomeType.self)`
   2. Build 'MockingbirdTests' (⇧⌘U) to generate mocks
   3. Write some Swifty tests!

Major Changes

  • Replaced install with configure
  • Removed uninstall
    • Unused and developers should rely on source control instead
  • Removed download
    • Unified with configure
  • Removed testbed
    • Unused legacy command for profiling the generator

Minor Changes

  • Added --version as a global flag
  • Added --srcproject to configure
    • Allows specifying the project containing the source modules if it differs from the test target project
  • Removed --disable-module-import from generate
    • Only used for the legacy setup method of generating mocks from source targets
  • Removed --asynchronous from install
    • Only used for the legacy setup method of generating mocks from source targets

Incidental Changes

  • XcodeProj 8.0.0 → 8.7.1
  • SwiftSyntax 0.50400.0 → 0.50500.0

Fixes #242
Closes https://github.com/birdrides/mockingbird/projects/2#card-66279076

The CLI was previously split out from the framework package definitions
to fix SwiftUI issues. This merges the packages under a conditional
build flag, similar to the official SwiftPM package manifest:

https://github.com/apple/swift-package-manager/blob/main/Package.swift
Hermetic / non-portable builds are the default going forward given the
the launcher included in 0.17. Installable artifacts will be released
with the `-installable` suffix and the less intuitive `-cisafe` will be
dropped for hermetic builds.
- XcodeProj 8.0.0 -> 8.7.1
- SwiftSyntax 0.50400.0 -> 0.50500.0
Fixes the linker warning that lib_InternalSwiftSyntaxParser.dylib was
built for newer macOS version (10.14.6) than being linked (10.13).
- Removed Xcode 12 workflow as SwiftSyntax 0.50500.0 is not source
  compatible with Xcode 13.
- Migrated from `install` to `configure` command.
@andrewchang-bird andrewchang-bird merged commit c1f61ce into master Jan 6, 2022
@andrewchang-bird andrewchang-bird deleted the dev/andrewchang-bird/swift-argument-parser branch January 6, 2022 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Library evolution support is broken Mocking a protocol I another project
2 participants