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

Enable customization of arguments in Xcode package plugin #149

Merged
merged 12 commits into from
Jan 17, 2025

Conversation

dfed
Copy link
Owner

@dfed dfed commented Jan 16, 2025

Also enable the Xcode package plugin to run a Release binary.

Addresses #147

Also enable the Xcode package plugin to run a Release binary.

WIP. Still needs documentation.
@dfed dfed self-assigned this Jan 16, 2025
Plugins/Shared.swift Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.91%. Comparing base (9f91eb3) to head (192a418).
Report is 5 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #149   +/-   ##
=======================================
  Coverage   99.91%   99.91%           
=======================================
  Files          32       32           
  Lines        3467     3485   +18     
=======================================
+ Hits         3464     3482   +18     
  Misses          3        3           
Files with missing lines Coverage Δ
Sources/SafeDITool/SafeDITool.swift 99.61% <100.00%> (+0.02%) ⬆️

Comment on lines +170 to +171
// Force the command to wait until the async work is done.
dispatchGroup.wait()
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is nuts, but since the method is not async (unlike the plugin for Package.swift files), we have to pull this trick to ensure that the main method here only exits after all our work is done.

Comment on lines +111 to +114
func performCommand(
context: XcodeProjectPlugin.XcodePluginContext,
arguments _: [String]
) throws {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is quite similar to the above func performCommand(context: PackagePlugin.PluginContext, arguments _: [String]) async throws, except our context is different and we aren't async.

@@ -0,0 +1 @@
../Shared.swift
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is how I'm sharing code between Plugins, which can't have shared dependencies.

Comment on lines -64 to -73
if context.hasSafeDIFolder, let safeDIVersion, downloadedToolLocation == nil {
Diagnostics.error("""
\(context.safediFolder.path()) exists, but contains no SafeDITool binary for version \(safeDIVersion).

To install the release SafeDITool binary for version \(safeDIVersion), run:
\tswift package --package-path \(context.package.directoryURL.path()) --allow-network-connections all --allow-writing-to-package-directory safedi-release-install

To use a debug SafeDITool binary instead, remove previous installs by running:
\trm -rf \(context.safediFolder.path())
""")
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we used to error if you previously installed the release version and then changed versions. I'm deleting that code path because:

  1. I'm not convinced it's super helpful. We still have the warnings
  2. It's harder (not impossible) to tell whether the folder exists because we've downloaded a release binary in the past now that we're reusing this folder for configuration setting

@@ -0,0 +1 @@
Subproject
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Examples/ExampleMultiProjectIntegration/ExampleMultiProjectIntegration is already scanned because it's the root module. We just need to list the paths to the other module(s) in this file.

Comment on lines -1 to -3
// This file was generated by the SafeDIGenerateDependencyTree build tool plugin.
// Any modifications made to this file will be overwritten on subsequent builds.
// Please refrain from editing this file directly.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file is now in derived data! much nicer

@@ -321,6 +294,10 @@
target = 3289B4002BF955710053F2E4 /* Subproject */;
targetProxy = 3289B4052BF955720053F2E4 /* PBXContainerItemProxy */;
};
32B72E1D2D39765B00F5EB6F /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
productRef = 32B72E1C2D39765B00F5EB6F /* SafeDIGenerator */;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're now using the plugin instead of a build script phase

Comment on lines -39 to -54
// As of Xcode 16.0 Beta 6, the display version is of the form "Optional(version)".
// This regular expression is duplicated by SafeDIGenerateDependencyTree since plugins can not share code.
guard let versionMatch = try /Optional\((.*?)\)|^(.*?)$/.firstMatch(in: displayVersion),
let versionSubstring = versionMatch.output.1 ?? versionMatch.output.2
else {
Diagnostics.error("Could not extract version for SafeDI")
exit(1)
}
let version = String(versionSubstring)
let safediFolder = context.package.directoryURL.appending(
component: ".safedi"
)
let expectedToolFolder = safediFolder.appending(
component: version
)
let expectedToolLocation = expectedToolFolder.appending(component: "safeditool")
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is mostly in Shared.swift now

Comment on lines -181 to -190
fileprivate func write(toPath filePath: String) throws {
#if os(Linux)
try write(to: URL(fileURLWithPath: filePath))
#else
guard #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) else {
try write(to: URL(fileURLWithPath: filePath))
}
try write(to: URL(filePath: filePath))
#endif
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer used

}
}

extension PackagePlugin.PluginContext {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the below was moved to Shared.swift

@Option(help: "The desired output location of a file a SafeDI representation of this module. Only include this option when running on a project‘s non-root module. Must have a `.safedi` suffix") var moduleInfoOutput: String?
@Option(help: "A path to a CSV file comprising the names of modules to import in the generated dependency tree. This list is in addition to the import statements found in files that declare @Instantiable types.") var additionalImportedModulesFilePath: String?

@Option(help: "The desired output location of a file a SafeDI representation of this module. Only include this option when running on a project‘s non-root module. Must have a `.safedi` suffix.") var moduleInfoOutput: String?
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just added a trailing . to the comment here

@dfed dfed marked this pull request as ready for review January 16, 2025 21:57
@dfed
Copy link
Owner Author

dfed commented Jan 17, 2025

Going to merge this and release a 1.1.0-beta-1 release so it can be tested. @pouyayarandi can you adopt and lmk if it works well for you before I release the version to all?

@dfed dfed force-pushed the dfed--xcode-plugin-configuration branch from 1f882cd to 192a418 Compare January 17, 2025 01:12
@dfed dfed merged commit d78a03d into main Jan 17, 2025
18 checks passed
@dfed dfed deleted the dfed--xcode-plugin-configuration branch January 17, 2025 01:15
@dfed dfed restored the dfed--xcode-plugin-configuration branch January 17, 2025 01:15
@dfed dfed deleted the dfed--xcode-plugin-configuration branch January 17, 2025 03:04
@pouyayarandi
Copy link

I just tested both include.csv and additionalImportedModules.csv, everything's work smoothly 🔥

@dfed
Copy link
Owner Author

dfed commented Jan 17, 2025

Incredible! Will release the 1.1.0 within a few days then. Thank you for the feedback that led to this improvement, and for testing SafeDI 😄

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.

2 participants