-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
793 lines (692 loc) · 27.4 KB
/
Makefile
File metadata and controls
793 lines (692 loc) · 27.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
# ModularHomeInventory - World-Class Build System
# A comprehensive, industry-standard Makefile for iOS development
# Configuration
PROJECT_NAME = HomeInventoryModular
SCHEME = HomeInventoryModular
TEST_SCHEME = $(PROJECT_NAME)Tests
WORKSPACE = $(PROJECT_NAME).xcworkspace
PROJECT = $(PROJECT_NAME).xcodeproj
BUNDLE_ID = com.homeinventory.app
# Build Configuration
CONFIGURATION ?= Debug
SDK ?= iphoneos
DESTINATION ?= platform=iOS Simulator,name=iPhone 16 Pro,OS=latest
DERIVED_DATA = .build/DerivedData
BUILD_DIR = .build
COVERAGE_DIR = .build/coverage
# Tools
XCODEBUILD = xcodebuild
XCODEGEN = xcodegen
SWIFTLINT = swiftlint
SWIFTFORMAT = swiftformat
XCPRETTY = xcpretty
TUIST = tuist
FASTLANE = bundle exec fastlane
DANGER = bundle exec danger
BUILD_MONITOR = ./scripts/claude_build_wrapper.sh
# Swift Compiler Flags
# SWIFT_FLAGS = OTHER_SWIFT_FLAGS="-warnings-as-errors" # Temporarily disabled due to conflict
SWIFT_FLAGS = OTHER_SWIFT_FLAGS="-Xfrontend -warn-long-function-bodies=100 -Xfrontend -warn-long-expression-type-checking=100"
RELEASE_FLAGS = COMPILER_INDEX_STORE_ENABLE=NO SWIFT_COMPILATION_MODE=wholemodule
DEBUG_FLAGS = OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-function-bodies -Xfrontend -debug-time-expression-type-checking"
# Parallel build settings
PARALLEL_WORKERS = $(shell sysctl -n hw.ncpu)
BUILD_FLAGS = -parallelizeTargets -jobs $(PARALLEL_WORKERS)
# Colors for output
RED = \033[0;31m
GREEN = \033[0;32m
YELLOW = \033[0;33m
BLUE = \033[0;34m
NC = \033[0m # No Color
# Default target
.DEFAULT_GOAL := help
# MARK: - Core Targets
.PHONY: all
all: clean generate lint build test ## Run complete build pipeline
.PHONY: help
help: ## Show this help message
@echo "$(BLUE)ModularHomeInventory Build System$(NC)"
@echo "$(YELLOW)Usage:$(NC) make [target]"
@echo ""
@echo "$(GREEN)Available targets:$(NC)"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(BLUE)%-20s$(NC) %s\n", $$1, $$2}'
# MARK: - Project Generation
.PHONY: generate
generate: ## Generate Xcode project from project.yml
@echo "$(BLUE)Generating Xcode project...$(NC)"
@$(XCODEGEN) generate
@echo "$(GREEN)✓ Project generated successfully$(NC)"
.PHONY: regenerate
regenerate: clean-project generate ## Clean and regenerate project
# MARK: - Building
.PHONY: build
build: generate ## Build the project with enhanced diagnostics
@echo "$(BLUE)Building $(PROJECT_NAME) ($(CONFIGURATION))...$(NC)"
@$(XCODEBUILD) build \
-project $(PROJECT) \
-scheme $(SCHEME) \
-configuration $(CONFIGURATION) \
-derivedDataPath $(DERIVED_DATA) \
$(BUILD_FLAGS) \
$(SWIFT_FLAGS) \
$(if $(filter Debug,$(CONFIGURATION)),$(DEBUG_FLAGS),) \
CODE_SIGNING_ALLOWED=NO \
2>&1 | ./scripts/build-error-diagnostics.sh filter | $(XCPRETTY)
@echo "$(GREEN)✓ Build succeeded$(NC)"
.PHONY: build-modular
build-modular: build-spm generate build ## Build SPM modules first, then the main project
@echo "$(GREEN)✓ Modular build complete$(NC)"
.PHONY: run
run: ## Build and run on iOS Simulator
@echo "$(BLUE)Building and running on iOS Simulator...$(NC)"
@$(XCODEBUILD) build-for-testing \
-project $(PROJECT) \
-scheme $(SCHEME) \
-destination "$(DESTINATION)" \
-derivedDataPath $(DERIVED_DATA) \
$(BUILD_FLAGS) \
CODE_SIGNING_ALLOWED=NO \
| $(XCPRETTY)
@echo "$(BLUE)Launching app...$(NC)"
@xcrun simctl boot "iPhone 16 Pro" 2>/dev/null || true
@open -a Simulator --args -CurrentDeviceUDID $$(xcrun simctl list devices | grep "iPhone 16 Pro" | grep -E -o '[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}' | head -1)
@sleep 2
@xcrun simctl install booted $(DERIVED_DATA)/Build/Products/Debug-iphonesimulator/$(PROJECT_NAME).app
@xcrun simctl launch booted $(BUNDLE_ID)
@echo "$(GREEN)✓ App launched$(NC)"
.PHONY: run-modular
run-modular: build-modular run ## Build SPM modules first, then run
@echo "$(GREEN)✓ Modular run complete$(NC)"
.PHONY: build-release
build-release: ## Build for release
@$(MAKE) build CONFIGURATION=Release SWIFT_FLAGS="$(SWIFT_FLAGS) $(RELEASE_FLAGS)"
.PHONY: archive
archive: generate ## Create release archive
@echo "$(BLUE)Archiving $(PROJECT_NAME)...$(NC)"
@$(XCODEBUILD) archive \
-project $(PROJECT) \
-scheme $(SCHEME) \
-configuration Release \
-archivePath $(BUILD_DIR)/$(PROJECT_NAME).xcarchive \
$(BUILD_FLAGS) \
| $(XCPRETTY)
@echo "$(GREEN)✓ Archive created$(NC)"
# MARK: - Monitored Builds (For Claude CLI)
.PHONY: build-monitored
build-monitored: generate ## Build with error monitoring for dashboard
@echo "$(BLUE)Building with dashboard monitoring...$(NC)"
@$(BUILD_MONITOR) "$(XCODEBUILD) build \
-project $(PROJECT) \
-scheme $(SCHEME) \
-destination '$(DESTINATION)' \
-derivedDataPath $(DERIVED_DATA) \
$(BUILD_FLAGS) \
$(SWIFT_FLAGS)"
.PHONY: build-fast-monitored
build-fast-monitored: ## Fast build with monitoring (no prebuild)
@echo "$(BLUE)Fast building with monitoring...$(NC)"
@$(BUILD_MONITOR) "./scripts/build-parallel.sh"
.PHONY: build-dashboard
build-dashboard: build-monitored ## Build and open dashboard
@echo "$(GREEN)✓ Build complete - dashboard updated$(NC)"
# MARK: - Dashboard Deployment
.PHONY: deploy-dashboard
deploy-dashboard: ## Deploy dashboard to Vercel (automated)
@echo "$(BLUE)Deploying dashboard to Vercel...$(NC)"
@./scripts/deploy.sh
@echo "$(GREEN)✓ Dashboard deployed$(NC)"
.PHONY: setup-deployment
setup-deployment: ## Setup GitHub secrets for automated deployment
@echo "$(BLUE)Setting up GitHub secrets...$(NC)"
@./scripts/setup-github-secrets.sh
@echo "$(GREEN)✓ GitHub secrets configured$(NC)"
.PHONY: deploy-status
deploy-status: ## Check deployment status and URLs
@echo "$(BLUE)Checking deployment status...$(NC)"
@if [ -f .vercel_url ]; then \
VERCEL_URL=$$(cat .vercel_url); \
echo "$(GREEN)Dashboard URL: $$VERCEL_URL$(NC)"; \
echo "$(GREEN)API Status: $$VERCEL_URL/api/build-status$(NC)"; \
echo "Testing connection..."; \
curl -s -o /dev/null -w "Status: %{http_code}\n" "$$VERCEL_URL/api/build-status" || echo "$(RED)Connection failed$(NC)"; \
else \
echo "$(YELLOW)No deployment found. Run 'make deploy-dashboard' first$(NC)"; \
fi
# MARK: - Testing
.PHONY: test
test: generate ## Run unit tests
@echo "$(BLUE)Running tests...$(NC)"
@$(XCODEBUILD) test \
-project $(PROJECT) \
-scheme $(SCHEME) \
-destination "$(DESTINATION)" \
-derivedDataPath $(DERIVED_DATA) \
-resultBundlePath $(BUILD_DIR)/TestResults.xcresult \
-enableCodeCoverage YES \
$(BUILD_FLAGS) \
| $(XCPRETTY)
@echo "$(GREEN)✓ Tests passed$(NC)"
.PHONY: test-coverage
test-coverage:
@echo "⚠️ Test coverage generation temporarily disabled"
@echo " Tests cannot compile due to dependency issues"
@echo " See TODO-SPECIAL.md for details"
@echo ""
@echo "To build the app without tests:"
@echo " make build"
@echo ""
@echo "To run the app:"
@echo " make run"
.PHONY: test-parallel
test-parallel: ## Run tests in parallel
@echo "$(BLUE)Running tests in parallel...$(NC)"
@$(XCODEBUILD) test \
-project $(PROJECT) \
-scheme $(SCHEME) \
-destination "$(DESTINATION)" \
-parallel-testing-enabled YES \
-parallel-testing-worker-count $(PARALLEL_WORKERS) \
| $(XCPRETTY)
# MARK: - Code Quality
.PHONY: lint
lint: ## Run SwiftLint
@echo "$(BLUE)Running SwiftLint...$(NC)"
@$(SWIFTLINT) lint --strict
@echo "$(GREEN)✓ Linting passed$(NC)"
.PHONY: lint-fix
lint-fix: ## Auto-fix SwiftLint violations
@echo "$(BLUE)Auto-fixing SwiftLint violations...$(NC)"
@$(SWIFTLINT) lint --fix
@echo "$(GREEN)✓ Auto-fix complete$(NC)"
.PHONY: format
format: ## Format code with SwiftFormat
@echo "$(BLUE)Formatting code...$(NC)"
@$(SWIFTFORMAT) . --swiftversion 5.9
@echo "$(GREEN)✓ Formatting complete$(NC)"
.PHONY: analyze
analyze: ## Run static analysis
@echo "$(BLUE)Running static analysis...$(NC)"
@$(XCODEBUILD) analyze \
-project $(PROJECT) \
-scheme $(SCHEME) \
-configuration $(CONFIGURATION) \
$(BUILD_FLAGS) \
| $(XCPRETTY)
@echo "$(GREEN)✓ Analysis complete$(NC)"
# MARK: - Dependencies
.PHONY: deps
deps: ## Install dependencies
@echo "$(BLUE)Installing dependencies...$(NC)"
@bundle install
@$(XCODEGEN) generate
@echo "$(GREEN)✓ Dependencies installed$(NC)"
.PHONY: update-deps
update-deps: ## Update dependencies
@echo "$(BLUE)Updating dependencies...$(NC)"
@bundle update
@$(XCODEBUILD) -resolvePackageDependencies
@echo "$(GREEN)✓ Dependencies updated$(NC)"
# MARK: - Module Management
.PHONY: prebuild-modules
prebuild-modules: ## Pre-build all modules (alias for build-spm)
@echo "$(BLUE)Pre-building modules...$(NC)"
@./Scripts/build-parallel.sh --release
@echo "$(GREEN)✓ Modules pre-built$(NC)"
.PHONY: smart-build
smart-build: ## Intelligent build with module dependencies
@./Scripts/build-parallel.sh --release
.PHONY: build-spm
build-spm: ## Build all SPM modules in parallel
@echo "$(BLUE)Building all SPM modules in parallel...$(NC)"
@timeout 60s ./Scripts/build-parallel.sh --release || (echo "$(RED)Build timed out after 60 seconds$(NC)" && exit 1)
@echo "$(GREEN)✓ SPM modules built$(NC)"
.PHONY: build-spm-debug
build-spm-debug: ## Build all SPM modules in debug mode
@echo "$(BLUE)Building all SPM modules in debug...$(NC)"
@./Scripts/build-parallel.sh --debug
@echo "$(GREEN)✓ SPM modules built (debug)$(NC)"
.PHONY: validate-spm
validate-spm: ## Validate SPM module structure
@echo "$(BLUE)Validating SPM module structure...$(NC)"
@./Scripts/validate-build.sh
@echo "$(GREEN)✓ SPM validation complete$(NC)"
.PHONY: build-fast
build-fast: build-spm ## Alias for build-spm (fast parallel build)
.PHONY: build-module
build-module: ## Build a specific SPM module (usage: make build-module MODULE=Foundation-Core)
@if [ -z "$(MODULE)" ]; then \
echo "$(RED)Error: MODULE parameter required$(NC)"; \
echo "Usage: make build-module MODULE=Foundation-Core"; \
exit 1; \
fi
@if [ ! -d "$(MODULE)" ]; then \
echo "$(RED)Error: Module '$(MODULE)' not found$(NC)"; \
exit 1; \
fi
@echo "$(BLUE)Building module: $(MODULE)...$(NC)"
@cd $(MODULE) && swift build -c release
@echo "$(GREEN)✓ Module $(MODULE) built successfully$(NC)"
.PHONY: test-module
test-module: ## Test a specific SPM module (usage: make test-module MODULE=Foundation-Core)
@if [ -z "$(MODULE)" ]; then \
echo "$(RED)Error: MODULE parameter required$(NC)"; \
echo "Usage: make test-module MODULE=Foundation-Core"; \
exit 1; \
fi
@if [ ! -d "$(MODULE)" ]; then \
echo "$(RED)Error: Module '$(MODULE)' not found$(NC)"; \
exit 1; \
fi
@echo "$(BLUE)Testing module: $(MODULE)...$(NC)"
@cd $(MODULE) && swift test
@echo "$(GREEN)✓ Module $(MODULE) tests passed$(NC)"
.PHONY: list-modules
list-modules: ## List all SPM modules
@echo "$(BLUE)SPM Modules:$(NC)"
@echo "$(YELLOW)Foundation Layer:$(NC)"
@for module in Foundation-*; do \
if [ -d "$$module" ] && [ -f "$$module/Package.swift" ]; then \
echo " • $$module"; \
fi; \
done
@echo "$(YELLOW)Infrastructure Layer:$(NC)"
@for module in Infrastructure-*; do \
if [ -d "$$module" ] && [ -f "$$module/Package.swift" ]; then \
echo " • $$module"; \
fi; \
done
@echo "$(YELLOW)Services Layer:$(NC)"
@for module in Services-*; do \
if [ -d "$$module" ] && [ -f "$$module/Package.swift" ]; then \
echo " • $$module"; \
fi; \
done
@echo "$(YELLOW)UI Layer:$(NC)"
@for module in UI-*; do \
if [ -d "$$module" ] && [ -f "$$module/Package.swift" ]; then \
echo " • $$module"; \
fi; \
done
@echo "$(YELLOW)Features Layer:$(NC)"
@for module in Features-*; do \
if [ -d "$$module" ] && [ -f "$$module/Package.swift" ]; then \
echo " • $$module"; \
fi; \
done
@echo "$(YELLOW)App Layer:$(NC)"
@if [ -d "Source" ] && [ -f "Source/Package.swift" ]; then \
echo " • Source"; \
fi
.PHONY: clean-spm
clean-spm: ## Clean all SPM module build artifacts
@echo "$(BLUE)Cleaning all SPM modules...$(NC)"
@for module in Foundation-* Infrastructure-* Services-* UI-* Features-* Source; do \
if [ -d "$$module" ] && [ -f "$$module/Package.swift" ]; then \
echo "Cleaning $$module..."; \
cd "$$module" && swift package clean && cd ..; \
fi; \
done
@echo "$(GREEN)✓ All SPM modules cleaned$(NC)"
@./Scripts/fix-build-issues.sh --clean-only 2>/dev/null || echo "$(YELLOW)Using comprehensive clean...$(NC)"
@find . -name ".build" -type d -exec rm -rf {} + 2>/dev/null || true
@find . -name "Package.resolved" -type f -delete 2>/dev/null || true
@echo "$(GREEN)✓ SPM modules cleaned$(NC)"
.PHONY: fix-build
fix-build: ## Fix common SPM build issues (multiple producers, etc.)
@echo "$(BLUE)Fixing SPM build issues...$(NC)"
@./Scripts/fix-build-issues.sh
@echo "$(GREEN)✓ Build issues fixed$(NC)"
.PHONY: build-metrics
build-metrics: ## Analyze build performance
@echo "$(BLUE)Collecting build metrics...$(NC)"
@$(XCODEBUILD) build \
-project $(PROJECT) \
-scheme $(SCHEME) \
-destination "$(DESTINATION)" \
-showBuildTimingSummary \
-resultBundlePath $(BUILD_DIR)/Metrics.xcresult \
OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-compilation" \
| tee $(BUILD_DIR)/build-metrics.log
@if [ -f ./Scripts/analyze-build-metrics.sh ]; then \
./Scripts/analyze-build-metrics.sh $(BUILD_DIR)/Metrics.xcresult; \
else \
echo "$(YELLOW)⚠️ Build metrics analyzer not found$(NC)"; \
fi
.PHONY: module-graph
module-graph: ## Generate module dependency graph
@echo "$(BLUE)Generating module dependency graph...$(NC)"
@if [ -f ./Scripts/generate-module-graph.sh ]; then \
./Scripts/generate-module-graph.sh; \
echo "$(GREEN)✓ Graph generated at docs/module-graph.png$(NC)"; \
else \
echo "$(YELLOW)⚠️ Module graph generator not found$(NC)"; \
mkdir -p docs; \
echo "ModularHomeInventory Module Dependency Graph" > docs/module-graph.txt; \
echo "===========================================" >> docs/module-graph.txt; \
echo "" >> docs/module-graph.txt; \
echo "Foundation-Core, Foundation-Models, Foundation-Resources" >> docs/module-graph.txt; \
echo " ↓" >> docs/module-graph.txt; \
echo "Infrastructure-Network, Infrastructure-Storage, Infrastructure-Security, Infrastructure-Monitoring" >> docs/module-graph.txt; \
echo " ↓" >> docs/module-graph.txt; \
echo "Services-Authentication, Services-Sync, Services-Search, Services-Export" >> docs/module-graph.txt; \
echo " ↓" >> docs/module-graph.txt; \
echo "UI-Styles → UI-Components → UI-Navigation" >> docs/module-graph.txt; \
echo " ↓" >> docs/module-graph.txt; \
echo "Features-Inventory, Features-Locations, Features-Analytics, Features-Settings" >> docs/module-graph.txt; \
echo " ↓" >> docs/module-graph.txt; \
echo "Source (App Layer)" >> docs/module-graph.txt; \
echo "$(GREEN)✓ Basic graph generated at docs/module-graph.txt$(NC)"; \
fi
.PHONY: module-status
module-status: ## Check build status of all SPM modules
@echo "$(BLUE)Checking module build status...$(NC)"
@echo ""
@for layer in "Foundation" "Infrastructure" "Services" "UI" "Features"; do \
echo "$(YELLOW)$$layer Layer:$(NC)"; \
for module in $$layer-*; do \
if [ -d "$$module" ] && [ -f "$$module/Package.swift" ]; then \
if [ -d "$$module/.build" ]; then \
echo " $(GREEN)✓ $$module (built)$(NC)"; \
else \
echo " $(RED)✗ $$module (not built)$(NC)"; \
fi; \
fi; \
done; \
echo ""; \
done
@if [ -d "Source" ] && [ -f "Source/Package.swift" ]; then \
echo "$(YELLOW)App Layer:$(NC)"; \
if [ -d "Source/.build" ]; then \
echo " $(GREEN)✓ Source (built)$(NC)"; \
else \
echo " $(RED)✗ Source (not built)$(NC)"; \
fi; \
fi
.PHONY: module-deps
module-deps: ## Show dependencies for a specific module (usage: make module-deps MODULE=Foundation-Core)
@if [ -z "$(MODULE)" ]; then \
echo "$(RED)Error: MODULE parameter required$(NC)"; \
echo "Usage: make module-deps MODULE=Foundation-Core"; \
exit 1; \
fi
@if [ ! -d "$(MODULE)" ]; then \
echo "$(RED)Error: Module '$(MODULE)' not found$(NC)"; \
exit 1; \
fi
@echo "$(BLUE)Dependencies for $(MODULE):$(NC)"
@cd $(MODULE) && swift package show-dependencies
.PHONY: validate-env
validate-env: ## Validate build environment
@echo "$(BLUE)Validating build environment...$(NC)"
@echo "✓ Xcode: $$(xcodebuild -version | head -1)"
@echo "✓ Swift: $$(swift --version | head -1)"
@echo "✓ XcodeGen: $$(xcodegen --version)"
@echo "$(GREEN)✓ Environment validation complete$(NC)"
# MARK: - CI/CD
.PHONY: ci
ci: deps lint build test ## Run CI pipeline
.PHONY: cd-testflight
cd-testflight: ## Deploy to TestFlight
@echo "$(BLUE)Deploying to TestFlight...$(NC)"
@$(FASTLANE) beta
@echo "$(GREEN)✓ Deployed to TestFlight$(NC)"
.PHONY: cd-appstore
cd-appstore: ## Deploy to App Store
@echo "$(BLUE)Deploying to App Store...$(NC)"
@$(FASTLANE) release
@echo "$(GREEN)✓ Deployed to App Store$(NC)"
# MARK: - Development Tools
.PHONY: dev-setup
dev-setup: ## Setup development environment
@echo "$(BLUE)Setting up development environment...$(NC)"
@if [ -f ./Scripts/setup-dev-environment.sh ]; then \
./Scripts/setup-dev-environment.sh; \
else \
echo "$(YELLOW)⚠️ Development setup script not found$(NC)"; \
fi
@echo "$(GREEN)✓ Development environment ready$(NC)"
.PHONY: simulator
simulator: ## Open iOS Simulator
@open -a Simulator
.PHONY: clean-simulator
clean-simulator: ## Clean simulator data
@echo "$(BLUE)Cleaning simulator...$(NC)"
@xcrun simctl shutdown all
@xcrun simctl erase all
@echo "$(GREEN)✓ Simulator cleaned$(NC)"
# MARK: - Cleaning
.PHONY: clean
clean: ## Clean build artifacts and caches
@echo "$(BLUE)Cleaning build artifacts...$(NC)"
@rm -rf $(BUILD_DIR)
@rm -rf $(DERIVED_DATA)
@rm -rf ~/Library/Developer/Xcode/DerivedData/$(PROJECT_NAME)-*
@rm -rf DerivedData
@find . -name ".DS_Store" -type f -delete 2>/dev/null || true
@find . -name "*.xcactivitylog" -type f -delete 2>/dev/null || true
@find . -name "*.profraw" -type f -delete 2>/dev/null || true
@find . -name "*.profdata" -type f -delete 2>/dev/null || true
@find . -name "xcuserdata" -type d -exec rm -rf {} + 2>/dev/null || true
@find . -type d -name "*.xcodeproj/xcshareddata/swiftpm" -exec rm -rf {} + 2>/dev/null || true
@find . -name ".swiftpm" -type d -exec rm -rf {} + 2>/dev/null || true
@find . -name "*.xcresult" -type d -exec rm -rf {} + 2>/dev/null || true
@find . -name "*.xcactivitylog" -type f -delete 2>/dev/null || true
@find . -name "*.orig" -type f -delete 2>/dev/null || true
@rm -rf trash 2>/dev/null || true
@$(XCODEBUILD) clean -project $(PROJECT) -scheme $(SCHEME) | $(XCPRETTY) || true
@echo "$(GREEN)✓ Clean complete$(NC)"
.PHONY: clean-modules
clean-modules: clean-spm ## Alias for clean-spm
.PHONY: clean-all
clean-all: clean clean-project clean-spm ## Deep clean including project files and SPM modules
@echo "$(BLUE)Deep cleaning...$(NC)"
@rm -rf ~/Library/Developer/Xcode/DerivedData/$(PROJECT_NAME)-*
@rm -rf ~/Library/Caches/com.apple.dt.Xcode
@rm -rf ~/Library/Developer/Xcode/DerivedData
@rm -rf ~/Library/Developer/CoreSimulator/Caches
@rm -rf xcode-build-errors-analysis.xml 2>/dev/null || true
@rm -rf *.xcresult 2>/dev/null || true
@rm -rf Build 2>/dev/null || true
@echo "$(GREEN)✓ Deep clean complete$(NC)"
.PHONY: clean-project
clean-project: ## Remove generated project files
@echo "$(BLUE)Removing generated project files...$(NC)"
@rm -rf $(PROJECT)
@rm -rf $(WORKSPACE)
@echo "$(GREEN)✓ Project files removed$(NC)"
.PHONY: clean-temp
clean-temp: ## Remove temporary files and build artifacts
@echo "$(BLUE)Cleaning temporary files...$(NC)"
@rm -rf trash 2>/dev/null || true
@rm -rf xcode-build-errors-analysis.xml 2>/dev/null || true
@find . -name "*.orig" -type f -delete 2>/dev/null || true
@find . -name "*.log" -type f -delete 2>/dev/null || true
@find . -name "*.tmp" -type f -delete 2>/dev/null || true
@echo "$(GREEN)✓ Temporary files cleaned$(NC)"
# MARK: - Profiling & Performance
.PHONY: profile-build
profile-build: ## Profile build times
@echo "$(BLUE)Profiling build times...$(NC)"
@$(XCODEBUILD) build \
-project $(PROJECT) \
-scheme $(SCHEME) \
-showBuildTimingSummary \
| tee $(BUILD_DIR)/build-timing.log
@echo "$(GREEN)✓ Build timing saved to $(BUILD_DIR)/build-timing.log$(NC)"
.PHONY: size-report
size-report: build-release ## Generate app size report
@echo "$(BLUE)Generating size report...$(NC)"
@if [ -f ./Scripts/generate-size-report.sh ]; then \
./Scripts/generate-size-report.sh; \
else \
echo "$(YELLOW)⚠️ Size report generator not found$(NC)"; \
fi
@echo "$(GREEN)✓ Size report generated$(NC)"
# MARK: - Documentation
.PHONY: docs
docs: ## Generate documentation
@echo "$(BLUE)Generating documentation...$(NC)"
@jazzy \
--module $(PROJECT_NAME) \
--swift-version 5.9 \
--output docs/api
@echo "$(GREEN)✓ Documentation generated at docs/api$(NC)"
# MARK: - Utilities
.PHONY: open
open: ## Open project in Xcode
@open $(PROJECT)
.PHONY: reset
reset: clean-all deps generate ## Reset project to clean state
.PHONY: check-tools
check-tools: ## Check required tools
@echo "$(BLUE)Checking required tools...$(NC)"
@if [ -f ./Scripts/check-tools.sh ]; then \
./Scripts/check-tools.sh; \
else \
echo "$(YELLOW)⚠️ Tool checker not found - checking manually...$(NC)"; \
command -v xcodebuild >/dev/null && echo "✓ xcodebuild" || echo "✗ xcodebuild"; \
command -v swift >/dev/null && echo "✓ swift" || echo "✗ swift"; \
command -v xcodegen >/dev/null && echo "✓ xcodegen" || echo "✗ xcodegen"; \
fi
@echo "$(GREEN)✓ All tools available$(NC)"
.PHONY: integration-check
integration-check: ## Check Swift file integration status
@echo "$(BLUE)Checking Swift file integration status...$(NC)"
@if [ -f ./Scripts/check-swift-integration.py ]; then \
python3 ./Scripts/check-swift-integration.py --markdown reports/swift-integration-report.md --json reports/swift-integration.json; \
else \
echo "$(YELLOW)⚠️ Integration checker not found$(NC)"; \
fi
@echo "$(GREEN)✓ Integration report generated$(NC)"
.PHONY: integration-report
integration-report: ## Generate and display Swift integration report
@echo "$(BLUE)Generating Swift integration report...$(NC)"
@mkdir -p reports
@if [ -f ./Scripts/check-swift-integration.py ]; then \
python3 ./Scripts/check-swift-integration.py --markdown reports/swift-integration-report.md --no-fail --quiet; \
echo ""; \
echo "$(YELLOW)Report saved to: reports/swift-integration-report.md$(NC)"; \
echo "$(YELLOW)View with: open reports/swift-integration-report.md$(NC)"; \
else \
echo "$(YELLOW)⚠️ Integration checker not found$(NC)"; \
fi
# MARK: - Git Hooks
.PHONY: install-hooks
install-hooks: ## Install git hooks
@echo "$(BLUE)Installing git hooks...$(NC)"
@if [ -f ./Scripts/install-git-hooks.sh ]; then \
./Scripts/install-git-hooks.sh; \
else \
echo "$(YELLOW)⚠️ Git hooks installer not found$(NC)"; \
fi
@echo "$(GREEN)✓ Git hooks installed$(NC)"
# MARK: - Dependency Management
.PHONY: dependency-check
dependency-check: ## Run dependency health check
@echo "$(BLUE)Running dependency health check...$(NC)"
@if [ -f ./Scripts/check-dependency-health.sh ]; then \
./Scripts/check-dependency-health.sh; \
else \
echo "$(YELLOW)⚠️ Dependency health checker not found$(NC)"; \
fi
@echo "$(GREEN)✓ Dependency check complete$(NC)"
.PHONY: security-scan
security-scan: ## Run security audit on dependencies
@echo "$(BLUE)Running security audit...$(NC)"
@if [ -f Gemfile.lock ]; then \
bundle exec bundle-audit check --update; \
fi
@swift package audit 2>/dev/null || echo "$(YELLOW)Swift package audit not available$(NC)"
@echo "$(GREEN)✓ Security scan complete$(NC)"
.PHONY: update-dependencies
update-dependencies: ## Update all dependencies
@echo "$(BLUE)Updating dependencies...$(NC)"
@echo "$(YELLOW)Updating Swift packages...$(NC)"
@swift package update
@echo "$(YELLOW)Updating Ruby gems...$(NC)"
@bundle update
@echo "$(GREEN)✓ Dependencies updated$(NC)"
.PHONY: dependency-report
dependency-report: ## Generate comprehensive dependency report
@echo "$(BLUE)Generating dependency report...$(NC)"
@if [ -f ./Scripts/check-dependency-health.sh ]; then \
./Scripts/check-dependency-health.sh; \
echo "$(GREEN)✓ Report generated: dependency-health-report.md$(NC)"; \
else \
echo "$(YELLOW)⚠️ Dependency health checker not found$(NC)"; \
fi
.PHONY: setup-dependency-automation
setup-dependency-automation: ## Setup automated dependency management
@echo "$(BLUE)Setting up dependency automation...$(NC)"
@if [ -f ./Scripts/setup-dependency-automation.sh ]; then \
./Scripts/setup-dependency-automation.sh; \
else \
echo "$(YELLOW)⚠️ Dependency automation setup not found$(NC)"; \
fi
@echo "$(GREEN)✓ Dependency automation configured$(NC)"
# MARK: - PR Management
.PHONY: pr-cleanup
pr-cleanup: ## Clean up stale and bot PRs (dry run)
@echo "$(BLUE)Running PR cleanup (dry run)...$(NC)"
@if [ -f ./Scripts/cleanup-stale-prs.sh ]; then \
./Scripts/cleanup-stale-prs.sh --days 7; \
else \
echo "$(YELLOW)⚠️ PR cleanup script not found$(NC)"; \
fi
@echo "$(GREEN)✓ PR cleanup complete (dry run)$(NC)"
.PHONY: pr-cleanup-execute
pr-cleanup-execute: ## Clean up stale and bot PRs (execute)
@echo "$(RED)Running PR cleanup (EXECUTE MODE)...$(NC)"
@if [ -f ./Scripts/cleanup-stale-prs.sh ]; then \
./Scripts/cleanup-stale-prs.sh --execute --days 7; \
else \
echo "$(YELLOW)⚠️ PR cleanup script not found$(NC)"; \
fi
@echo "$(GREEN)✓ PR cleanup complete$(NC)"
.PHONY: pr-status
pr-status: ## Show PR status summary
@echo "$(BLUE)PR Status Summary$(NC)"
@echo "================="
@echo "Open PRs: $$(gh pr list --state open --json number | jq '. | length')"
@echo "Draft PRs: $$(gh pr list --state open --draft --json number | jq '. | length')"
@echo "Bot PRs: $$(gh pr list --state open --json author --jq '.[] | select(.author.type == "Bot")' | wc -l)"
@echo ""
@gh pr list --state open --limit 10
# MARK: - Branch Protection
.PHONY: setup-branch-protection
setup-branch-protection: ## Apply branch protection rules (dry run)
@echo "$(BLUE)Setting up branch protection rules...$(NC)"
@if [ -f ./Scripts/setup-branch-protection.sh ]; then \
./Scripts/setup-branch-protection.sh; \
else \
echo "$(YELLOW)⚠️ Branch protection script not found$(NC)"; \
fi
@echo "$(GREEN)✓ Branch protection setup complete (dry run)$(NC)"
.PHONY: setup-branch-protection-execute
setup-branch-protection-execute: ## Apply branch protection rules (execute)
@echo "$(RED)Applying branch protection rules (EXECUTE MODE)...$(NC)"
@if [ -f ./Scripts/setup-branch-protection.sh ]; then \
./Scripts/setup-branch-protection.sh --execute; \
else \
echo "$(YELLOW)⚠️ Branch protection script not found$(NC)"; \
fi
@echo "$(GREEN)✓ Branch protection rules applied$(NC)"
.PHONY: check-branch-protection
check-branch-protection: ## Validate branch protection status
@echo "$(BLUE)Checking branch protection status...$(NC)"
@gh workflow run branch-protection-monitor.yml
@echo "$(GREEN)✓ Protection check initiated$(NC)"
.PHONY: branch-protection-report
branch-protection-report: ## Generate branch protection report
@echo "$(BLUE)Generating branch protection report...$(NC)"
@gh api /repos/$$(gh repo view --json owner -q .owner.login)/$$(gh repo view --json name -q .name)/branches/main/protection > branch-protection-current.json
@echo "$(GREEN)✓ Report saved to branch-protection-current.json$(NC)"
@echo ""
@echo "Main branch protection status:"
@cat branch-protection-current.json | jq -r '.required_status_checks.contexts[]' 2>/dev/null || echo "Not configured"
# Performance optimization: Use build caching
export CCACHE_DIR = $(BUILD_DIR)/ccache
export CCACHE_MAXSIZE = 10G
# Ensure build directory exists
$(BUILD_DIR):
@mkdir -p $(BUILD_DIR)