Skip to content

Conversation

@matt-livefront
Copy link
Collaborator

🎟️ Tracking

📔 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).
    • 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

Note

One issue I ran into is how we handle fixtures differently between targets. In BitwardenKit we include fixtures in BitwardenKitMocks and exclude them from the test targets so that they can be shared. Other targets include the fixtures in the test targets. I ended up not using the templates for the BitwardenKit test targets for this reason (51342b0). We could consider moving these fixtures into a "SharedFixtures" directory which would facilitate adding a MockTarget template though.

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

Logo
Checkmarx One – Scan Summary & Detailsc5118a07-c848-4ad8-a75f-a951eb7ac9f8

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 83.94%. Comparing base (7c901c2) to head (51342b0).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2153      +/-   ##
==========================================
- Coverage   85.38%   83.94%   -1.44%     
==========================================
  Files        1726     1979     +253     
  Lines      145611   160977   +15366     
==========================================
+ Hits       124335   135138   +10803     
- Misses      21276    25839    +4563     

☔ 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.

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