1+ #!/usr/bin/env python3
2+ """
3+ Build-Project.command: Generate OCLP-R.app and OCLP-R.pkg
4+ """
5+
6+ import os
7+ import sys
8+ import time
9+ import argparse
10+
11+ from pathlib import Path
12+
13+ from ci_tooling .build_modules import (
14+ application ,
15+ disk_images ,
16+ package ,
17+ sign_notarize
18+ )
19+
20+
21+ def main () -> None :
22+ """
23+ Parse Command Line Arguments
24+ """
25+
26+ parser = argparse .ArgumentParser (description = "Build OCLP-R Suite" , add_help = False )
27+
28+ # Signing Parameters
29+ parser .add_argument ("--application-signing-identity" , type = str , help = "Application Signing Identity" )
30+ parser .add_argument ("--installer-signing-identity" , type = str , help = "Installer Signing Identity" )
31+
32+
33+ # Notarization Parameters
34+ parser .add_argument ("--notarization-apple-id" , type = str , help = "Notarization Apple ID" , default = None )
35+ parser .add_argument ("--notarization-password" , type = str , help = "Notarization Password" , default = None )
36+ parser .add_argument ("--notarization-team-id" , type = str , help = "Notarization Team ID" , default = None )
37+
38+ # GitHub Actions CI/CD Parameters
39+ parser .add_argument ("--git-branch" , type = str , help = "Git Branch" , default = None )
40+ parser .add_argument ("--git-commit-url" , type = str , help = "Git Commit URL" , default = None )
41+ parser .add_argument ("--git-commit-date" , type = str , help = "Git Commit Date" , default = None )
42+
43+ # Local Build Parameters
44+ parser .add_argument ("--reset-dmg-cache" , action = "store_true" , help = "Redownload PatcherSupportPkg.dmg and regenerate payloads.dmg" , default = False )
45+ parser .add_argument ("--reset-pyinstaller-cache" , action = "store_true" , help = "Clean PyInstaller Cache" , default = False )
46+
47+ # CI/CD Parameters for individual steps
48+ # If not specified, will run all steps
49+ parser .add_argument ("--run-as-individual-steps" , action = "store_true" , help = "CI: Run as individual steps" , default = False )
50+ parser .add_argument ("--prepare-application" , action = "store_true" , help = "CI: Prepare Application" , default = False )
51+ parser .add_argument ("--prepare-package" , action = "store_true" , help = "CI: Prepare Package" , default = False )
52+ parser .add_argument ("--prepare-assets" , action = "store_true" , help = "CI: Prepare Assets" , default = False )
53+
54+ # Analytics Parameters
55+ parser .add_argument ("--analytics-key" , type = str , help = "Analytics Key" , default = None )
56+ parser .add_argument ("--analytics-endpoint" , type = str , help = "Analytics Endpoint" , default = None )
57+
58+ # Help
59+ parser .add_argument ("--help" , action = "store_true" , help = "Show this help message and exit" , default = False )
60+
61+ # Parse Arguments
62+ args = parser .parse_args ()
63+
64+ if args .help :
65+ parser .print_help ()
66+ print ("\n \n If running outside of CI/CD, simply run the following command:" )
67+ print ("$ python3 Build-Project.command" )
68+ sys .exit (0 )
69+
70+ # Set 'Current Working Directory' to script directory
71+ os .chdir (Path (__file__ ).resolve ().parent )
72+
73+
74+ if (args .run_as_individual_steps is False ) or (args .run_as_individual_steps and args .prepare_assets ):
75+ # Prepare workspace
76+ disk_images .GenerateDiskImages (args .reset_dmg_cache ).generate ()
77+
78+ if (args .run_as_individual_steps is False ) or (args .run_as_individual_steps and args .prepare_application ):
79+ # Prepare Privileged Helper Tool
80+ sign_notarize .SignAndNotarize (
81+ path = Path ("./ci_tooling/privileged_helper_tool/com.pyquick.oclp-r.privileged-helper" ),
82+ signing_identity = args .application_signing_identity ,
83+ notarization_apple_id = args .notarization_apple_id ,
84+ notarization_password = args .notarization_password ,
85+ notarization_team_id = args .notarization_team_id ,
86+ ).sign_and_notarize ()
87+
88+ # Build OCLP-R.app
89+ application .GenerateApplication (
90+ reset_pyinstaller_cache = args .reset_pyinstaller_cache ,
91+ git_branch = args .git_branch ,
92+ git_commit_url = args .git_commit_url ,
93+ git_commit_date = args .git_commit_date ,
94+ analytics_key = args .analytics_key ,
95+ analytics_endpoint = args .analytics_endpoint ,
96+ ).generate ()
97+
98+ # Sign OCLP-R.app
99+ sign_notarize .SignAndNotarize (
100+ path = Path ("dist/OCLP-R.app" ),
101+ signing_identity = args .application_signing_identity ,
102+ notarization_apple_id = args .notarization_apple_id ,
103+ notarization_password = args .notarization_password ,
104+ notarization_team_id = args .notarization_team_id ,
105+ entitlements = Path ("./ci_tooling/entitlements/entitlements.plist" ),
106+ ).sign_and_notarize ()
107+
108+
109+ if (args .run_as_individual_steps is False ) or (args .run_as_individual_steps and args .prepare_package ):
110+ # Build OCLP-R.pkg and OCLP-R-Uninstaller.pkg
111+ package .GeneratePackage ().generate ()
112+
113+ # Sign OCLP-R.pkg
114+ sign_notarize .SignAndNotarize (
115+ path = Path ("dist/OCLP-R.pkg" ),
116+ signing_identity = args .installer_signing_identity ,
117+ notarization_apple_id = args .notarization_apple_id ,
118+ notarization_password = args .notarization_password ,
119+ notarization_team_id = args .notarization_team_id ,
120+ ).sign_and_notarize ()
121+
122+ # Sign OCLP-R-Uninstaller.pkg
123+ sign_notarize .SignAndNotarize (
124+ path = Path ("dist/OCLP-R-Uninstaller.pkg" ),
125+ signing_identity = args .installer_signing_identity ,
126+ notarization_apple_id = args .notarization_apple_id ,
127+ notarization_password = args .notarization_password ,
128+ notarization_team_id = args .notarization_team_id ,
129+ ).sign_and_notarize ()
130+
131+
132+ if __name__ == '__main__' :
133+ _start = time .time ()
134+ main ()
135+ print (f"Build script completed in { str (round (time .time () - _start , 2 ))} seconds" )
0 commit comments