Skip to content

Conversation

@matt-livefront
Copy link
Collaborator

@matt-livefront matt-livefront commented Nov 19, 2025

🎟️ Tracking

PM-28540

📔 Objective

When I added Sourcery to BitwardenKit (#2136), I wondered if we could simplify some of the duplication in our project files.

This is an attempt at using Xcodegen's templates to share some common logic between targets.

There's two categories of templates that I've added:

  • "Sources" templates: a template that contains our common regex patterns for the source files used in different types of targets:
    • CommonTarget: this is meant for app or framework targets and mainly includes all files other than tests and test helpers (mocks, fixtures, etc).
    • MocksTarget: a target containing mocks and fixtures.
    • TestTarget: a unit testing target which excludes ViewInspector and snapshot tests.
    • SnapshotTestTarget: a test target for snapshot tests.
    • ViewInspectorTestTarget: a test target for ViewInspector tests.
  • "Build phase" templates:
    • SourceryTarget: a template for a target that needs a Sourcery pre-build script.

The templates are defined in project-common.yml.

Going forward, adding Sourcery to a target is simplified to adding SourceryTarget to the list of a target's templates (and adding the generated file to any test targets):

diff --git a/project-bwk.yml b/project-bwk.yml
--- a/project-bwk.yml
+++ b/project-bwk.yml
@@ -121,4 +121,5 @@
     templates:
       - CommonTarget
+      - SourceryTarget
     templateAttributes:
       sourcesPath: BitwardenKit
Diff of the project files before and after:

The only noticeable change here of the project files is the removal of the gitignore files, which I intentionally excluded. So even though this changes a bunch of stuff, I hope I've minimized any potential issues 🤞.

diff -U0 before/Bitwarden.pbxproj Bitwarden.xcodeproj/project.pbxproj
--- before/Bitwarden.pbxproj	2025-11-18 16:36:29
+++ Bitwarden.xcodeproj/project.pbxproj	2025-11-19 09:25:25
@@ -3158 +3157,0 @@
-		20E4EE0C07D3EE8586C46233 /* .gitignore */ = {isa = PBXFileReference; path = .gitignore; sourceTree = "<group>"; };
@@ -4607 +4605,0 @@
-		A6C964FC3085FA0C093F0C63 /* .gitignore */ = {isa = PBXFileReference; path = .gitignore; sourceTree = "<group>"; };
@@ -7463 +7460,0 @@
-				20E4EE0C07D3EE8586C46233 /* .gitignore */,
@@ -8724 +8720,0 @@
-				A6C964FC3085FA0C093F0C63 /* .gitignore */,

diff -U0 before/Authenticator.pbxproj Authenticator.xcodeproj/project.pbxproj
--- before/Authenticator.pbxproj	2025-11-18 16:36:53
+++ Authenticator.xcodeproj/project.pbxproj	2025-11-19 09:25:25
@@ -980 +979,0 @@
-		3CEC58C44DB13461B95880A5 /* .gitignore */ = {isa = PBXFileReference; path = .gitignore; sourceTree = "<group>"; };
@@ -1008 +1006,0 @@
-		4D0217410E4A8906F80DEDD9 /* .gitignore */ = {isa = PBXFileReference; path = .gitignore; sourceTree = "<group>"; };
@@ -1209 +1206,0 @@
-		C203B0C946484B15F519EFE6 /* .gitignore */ = {isa = PBXFileReference; path = .gitignore; sourceTree = "<group>"; };
@@ -1472 +1468,0 @@
-				3CEC58C44DB13461B95880A5 /* .gitignore */,
@@ -1528 +1523,0 @@
-				C203B0C946484B15F519EFE6 /* .gitignore */,
@@ -2278 +2272,0 @@
-				4D0217410E4A8906F80DEDD9 /* .gitignore */,

diff -U0 before/BitwardenKit.pbxproj BitwardenKit.xcodeproj/project.pbxproj
--- before/BitwardenKit.pbxproj	2025-11-18 16:36:16
+++ BitwardenKit.xcodeproj/project.pbxproj	2025-11-19 09:25:23
@@ -1309 +1308,0 @@
-		DBBC174DA9DFDD9E2F708A65 /* .gitignore */ = {isa = PBXFileReference; path = .gitignore; sourceTree = "<group>"; };
@@ -1669 +1667,0 @@
-				DBBC174DA9DFDD9E2F708A65 /* .gitignore */,

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@github-actions
Copy link
Contributor

github-actions bot commented Nov 19, 2025

Logo
Checkmarx One – Scan Summary & Details93eb6d2b-63d0-459b-ac8b-0ae026a9d4a5

Great job! No new security vulnerabilities introduced in this pull request

@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.18%. Comparing base (fdf8495) to head (d553a80).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2153      +/-   ##
==========================================
- Coverage   85.52%   84.18%   -1.34%     
==========================================
  Files        1738     1984     +246     
  Lines      147216   162582   +15366     
==========================================
+ Hits       125909   136875   +10966     
- Misses      21307    25707    +4400     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@matt-livefront matt-livefront force-pushed the matt/xcodegen-templates branch from 51342b0 to d553a80 Compare December 17, 2025 16:11
@matt-livefront matt-livefront changed the title Simplify project files with Xcodegen templates [PM-28540] Simplify project files with Xcodegen templates Dec 17, 2025
@matt-livefront matt-livefront marked this pull request as ready for review December 17, 2025 16:18
@matt-livefront matt-livefront requested a review from a team as a code owner December 17, 2025 16:18
@claude
Copy link

claude bot commented Dec 17, 2025

Claude finished @matt-livefront's task in 2m 40s —— View job


Code Review Complete

The review agent has completed its analysis. The XcodeGen template refactoring successfully reduces duplication while maintaining correct target configurations.

Overall Assessment: APPROVE

The templates are well-structured and the refactoring is clean. All target configurations have been preserved correctly while significantly reducing configuration file size.

Copy link
Member

@fedemkr fedemkr left a comment

Choose a reason for hiding this comment

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

Amazing work Matt, love it! 🎉 👏
Just have a few questions.

Comment on lines +50 to +55
MocksTarget:
sources:
- path: ${sourcesPath}
includes:
- "**/Fixtures/*"
- "**/Mocks/*"
Copy link
Member

Choose a reason for hiding this comment

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

🤔 Should the auto generated Sourcery optional file be added here as well?

- path: ${sourcesPath}/Sourcery/Generated/AutoMockable.generated.swift
        optional: true

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The only issue with this is that not all targets using the MocksTarget template integrate Sourcery. AuthenticatorBridgeKitMocks doesn't use Sourcery (yet), which causes the build to fail if that file doesn't exist. I guess we could add Sourcery for that target or keep it as-is for now. Do you have a preference?

Copy link
Member

Choose a reason for hiding this comment

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

I would like the bridge to follow the same pattern at some point but currently there are only 2 mocks in there, so applying it now may be a bit overkill.
Maybe we can revisit this if we have more work being done in the bridge. Does that sound good to you?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, I like that.

@matt-livefront matt-livefront merged commit 3559d2f into main Dec 18, 2025
81 checks passed
@matt-livefront matt-livefront deleted the matt/xcodegen-templates branch December 18, 2025 17:20
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.

3 participants