Skip to content

Only write the dependency tree output file if it has changed #167

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 2 commits into from
Jun 3, 2025

Conversation

dfed
Copy link
Owner

@dfed dfed commented Jun 3, 2025

@ahmdmhasn had a great idea to not touch the output file if the output file's content hasn't changed. Looks like modern Xcode seems to support having a package plugin that does supports this, so let's do it.

I believe earlier SPM implementations required the output file to be touched as part of the build plugin run, so we needed to write the file. This does not seem to be the case in Xcode 16+.

@dfed dfed requested a review from ahmdmhasn June 3, 2025 22:06
@dfed dfed self-assigned this Jun 3, 2025
Copy link

codecov bot commented Jun 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.92%. Comparing base (ff91f9e) to head (4e3d3cc).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #167   +/-   ##
=======================================
  Coverage   99.92%   99.92%           
=======================================
  Files          32       32           
  Lines        3751     3763   +12     
=======================================
+ Hits         3748     3760   +12     
  Misses          3        3           
Files with missing lines Coverage Δ
Sources/SafeDITool/SafeDITool.swift 99.63% <100.00%> (+0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@ahmdmhasn ahmdmhasn left a comment

Choose a reason for hiding this comment

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

Good job. I hope this makes build time even faster for incremental builds. 🙌🏼

@@ -52,6 +52,13 @@ struct SafeDITool: AsyncParsableCommand, Sendable {
throw ValidationError("Must provide 'swift-sources-file-path', '--include', or '--include-file-path'.")
}

async let existingGeneratedCode: String? = Task.detached {
if let dependencyTreeOutput {
try? String(contentsOf: dependencyTreeOutput.asFileURL, encoding: .utf8)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to log if unable to initialize a string with the content of the tree output? Anyway, it should be nil for initialization errors, or the file doesn't exist initially.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I don't think so – if we can't read it for whatever reason we'll just write a new one.

if let dependencyTreeOutput, let generatedCode = try await generatedCode {
if let dependencyTreeOutput,
let generatedCode = try await generatedCode,
// Only update the file if the file has changed.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice inline comment

Co-authored-by: Ahmed M. Hassan <[email protected]>
@dfed dfed merged commit 5e0dba6 into main Jun 3, 2025
20 checks passed
@dfed dfed deleted the dfed--less-work branch June 3, 2025 22:50
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