Debian Codegraph @

src/briefcase/platforms/macOS/xcode.py

raw
1 from __future__ import annotations
2
3 import subprocess
4
5 from briefcase.commands import (
6 BuildCommand,
7 CreateCommand,
8 DevCommand,
9 OpenCommand,
10 PackageCommand,
11 PublishCommand,
12 RunCommand,
13 UpdateCommand,
14 )
15 from briefcase.config import BaseConfig
16 from briefcase.exceptions import BriefcaseCommandError
17 from briefcase.integrations.xcode import Xcode
18 from briefcase.platforms.macOS import (
19 macOSCreateMixin,
20 macOSMixin,
21 macOSPackageMixin,
22 macOSRunMixin,
23 )
24 from briefcase.platforms.macOS.filters import XcodeBuildFilter
25
26
27 class macOSXcodeMixin(macOSMixin):
28 output_format = "Xcode"
29 supported_host_os_reason = (
30 "macOS applications require the Xcode command line "
31 "tools, which are only available on macOS."
32 )
33
34 def verify_tools(self):
35 Xcode.verify(self.tools, min_version=(13, 0, 0))
36
37 # Verify superclass tools *after* xcode. This ensures we get the
38 # git check *after* the xcode check.
39 super().verify_tools()
40
41 def project_path(self, app):
42 return self.bundle_path(app) / f"{app.formal_name}.xcodeproj"
43
44 def binary_path(self, app):
45 return self.bundle_path(app) / "build/Release" / f"{app.formal_name}.app"
46
47
48 class macOSXcodeCreateCommand(macOSXcodeMixin, macOSCreateMixin, CreateCommand):
49 description = "Create and populate a macOS Xcode project."
50
51
52 class macOSXcodeOpenCommand(macOSXcodeMixin, OpenCommand):
53 description = "Open an existing macOS Xcode project."
54
55
56 class macOSXcodeUpdateCommand(macOSXcodeCreateCommand, UpdateCommand):
57 description = "Update an existing macOS Xcode project."
58 supports_debugger = True
59
60
61 class macOSXcodeBuildCommand(macOSXcodeMixin, BuildCommand):
62 description = "Build a macOS Xcode project."
63 supports_debugger = True
64
65 def build_app(self, app: BaseConfig, **kwargs):
66 """Build the Xcode project for the application.
67
68 :param app: The application to build
69 """
70 # Confirm the project isn't currently on an iCloud synced drive.
71 self.verify_not_on_icloud(app)
72
73 self.console.info("Building Xcode project...", prefix=app.app_name)
74 with self.console.wait_bar("Building..."):
75 try:
76 self.tools.subprocess.run(
77 [
78 "xcodebuild",
79 "-project",
80 self.project_path(app),
81 "-verbose" if self.tools.console.is_deep_debug else "-quiet",
82 "-configuration",
83 "Release",
84 "build",
85 ],
86 check=True,
87 filter_func=(
88 None if self.tools.console.is_deep_debug else XcodeBuildFilter()
89 ),
90 )
91 self.console.info("Build succeeded.")
92 except subprocess.CalledProcessError as e:
93 raise BriefcaseCommandError(
94 f"Unable to build app {app.app_name}."
95 ) from e
96
97
98 class macOSXcodeRunCommand(macOSRunMixin, macOSXcodeMixin, RunCommand):
99 description = "Run a macOS app."
100 supports_debugger = True
101
102
103 class macOSXcodeDevCommand(macOSXcodeMixin, DevCommand):
104 description = "Run a macOS app in development mode."
105
106
107 class macOSXcodePackageCommand(macOSPackageMixin, macOSXcodeMixin, PackageCommand):
108 description = "Package a macOS app for distribution."
109
110
111 class macOSXcodePublishCommand(macOSXcodeMixin, PublishCommand):
112 description = "Publish a macOS app."
113
114
115 # Declare the briefcase command bindings
116 create = macOSXcodeCreateCommand
117 update = macOSXcodeUpdateCommand
118 open = macOSXcodeOpenCommand
119 build = macOSXcodeBuildCommand
120 run = macOSXcodeRunCommand
121 package = macOSXcodePackageCommand
122 publish = macOSXcodePublishCommand
123 dev = macOSXcodeDevCommand