| 1 |
import subprocess |
| 2 |
from pathlib import Path |
| 3 |
|
| 4 |
from briefcase.commands import ( |
| 5 |
BuildCommand, |
| 6 |
DevCommand, |
| 7 |
OpenCommand, |
| 8 |
PublishCommand, |
| 9 |
UpdateCommand, |
| 10 |
) |
| 11 |
from briefcase.config import BaseConfig |
| 12 |
from briefcase.exceptions import BriefcaseCommandError |
| 13 |
from briefcase.integrations.visualstudio import VisualStudio |
| 14 |
from briefcase.platforms.windows import ( |
| 15 |
WindowsCreateCommand, |
| 16 |
WindowsMixin, |
| 17 |
WindowsPackageCommand, |
| 18 |
WindowsRunCommand, |
| 19 |
) |
| 20 |
|
| 21 |
|
| 22 |
class WindowsVisualStudioMixin(WindowsMixin): |
| 23 |
output_format = "VisualStudio" |
| 24 |
packaging_root = Path("x64/Release") |
| 25 |
|
| 26 |
def project_path(self, app): |
| 27 |
return self.bundle_path(app) / f"{app.formal_name}.sln" |
| 28 |
|
| 29 |
|
| 30 |
class WindowsVisualStudioCreateCommand(WindowsVisualStudioMixin, WindowsCreateCommand): |
| 31 |
description = "Create and populate a Visual Studio project." |
| 32 |
|
| 33 |
|
| 34 |
class WindowsVisualStudioUpdateCommand(WindowsVisualStudioCreateCommand, UpdateCommand): |
| 35 |
description = "Update an existing Visual Studio project." |
| 36 |
supports_debugger = True |
| 37 |
|
| 38 |
|
| 39 |
class WindowsVisualStudioOpenCommand(WindowsVisualStudioMixin, OpenCommand): |
| 40 |
description = "Open an existing Visual Studio project." |
| 41 |
|
| 42 |
|
| 43 |
class WindowsVisualStudioBuildCommand(WindowsVisualStudioMixin, BuildCommand): |
| 44 |
description = "Build a Visual Studio project." |
| 45 |
supports_debugger = True |
| 46 |
|
| 47 |
def verify_tools(self): |
| 48 |
super().verify_tools() |
| 49 |
VisualStudio.verify(tools=self.tools) |
| 50 |
|
| 51 |
def build_app(self, app: BaseConfig, **kwargs): |
| 52 |
"""Build the Visual Studio project. |
| 53 |
|
| 54 |
:param app: The config object for the app |
| 55 |
""" |
| 56 |
self.console.info("Building VisualStudio project...", prefix=app.app_name) |
| 57 |
|
| 58 |
with self.console.wait_bar("Building solution..."): |
| 59 |
try: |
| 60 |
self.tools.subprocess.run( |
| 61 |
[ |
| 62 |
self.tools.visualstudio.msbuild_path, |
| 63 |
f"{app.formal_name}.sln", |
| 64 |
"-target:restore", |
| 65 |
"-property:RestorePackagesConfig=true", |
| 66 |
f"-target:{app.formal_name}", |
| 67 |
"-property:Configuration=Release", |
| 68 |
( |
| 69 |
"-verbosity:detailed" |
| 70 |
if self.console.is_deep_debug |
| 71 |
else "-verbosity:normal" |
| 72 |
), |
| 73 |
], |
| 74 |
check=True, |
| 75 |
cwd=self.bundle_path(app), |
| 76 |
) |
| 77 |
except subprocess.CalledProcessError as e: |
| 78 |
raise BriefcaseCommandError( |
| 79 |
f"Unable to build solution for {app.app_name}." |
| 80 |
) from e |
| 81 |
|
| 82 |
|
| 83 |
class WindowsVisualStudioRunCommand(WindowsVisualStudioMixin, WindowsRunCommand): |
| 84 |
description = "Run a Visual Studio project." |
| 85 |
|
| 86 |
|
| 87 |
class WindowsVisualStudioDevCommand(WindowsVisualStudioMixin, DevCommand): |
| 88 |
description = "Run a Visual Studio project in development mode." |
| 89 |
|
| 90 |
|
| 91 |
class WindowsVisualStudioPackageCommand( |
| 92 |
WindowsVisualStudioMixin, |
| 93 |
WindowsPackageCommand, |
| 94 |
): |
| 95 |
description = "Package a Visual Studio project." |
| 96 |
|
| 97 |
|
| 98 |
class WindowsVisualStudioPublishCommand(WindowsVisualStudioMixin, PublishCommand): |
| 99 |
description = "Publish a Visual Studio project." |
| 100 |
|
| 101 |
|
| 102 |
# Declare the briefcase command bindings |
| 103 |
create = WindowsVisualStudioCreateCommand |
| 104 |
update = WindowsVisualStudioUpdateCommand |
| 105 |
open = WindowsVisualStudioOpenCommand |
| 106 |
build = WindowsVisualStudioBuildCommand |
| 107 |
run = WindowsVisualStudioRunCommand |
| 108 |
package = WindowsVisualStudioPackageCommand |
| 109 |
publish = WindowsVisualStudioPublishCommand |
| 110 |
dev = WindowsVisualStudioDevCommand |