-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathuninstallcmd.py
77 lines (61 loc) · 2.39 KB
/
uninstallcmd.py
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
"""
customaction namespaced tasks
"""
import os
import shutil
import sys
from invoke import task
from invoke.exceptions import Exit
from .utils import get_version_numeric_only
# constants
BIN_PATH = os.path.join(".", "bin", "agent")
AGENT_TAG = "datadog/agent:master"
CUSTOM_ACTION_ROOT_DIR = "tools\\windows\\install-help"
@task
def build(ctx, major_version='7', vstudio_root=None, arch="x64", debug=False):
"""
Build the custom action library for the agent
"""
if sys.platform != 'win32':
print("Custom action library is only for Win32")
raise Exit(code=1)
ver = get_version_numeric_only(ctx, major_version=major_version)
build_maj, build_min, build_patch = ver.split(".")
verprops = f" /p:MAJ_VER={build_maj} /p:MIN_VER={build_min} /p:PATCH_VER={build_patch} "
print(f"arch is {arch}")
cmd = ""
configuration = "Release"
if debug:
configuration = "Debug"
if not os.getenv("VCINSTALLDIR"):
print("VC Not installed in environment; checking other locations")
vsroot = vstudio_root or os.getenv('VSTUDIO_ROOT')
if not vsroot:
print("Must have visual studio installed")
raise Exit(code=2)
batchfile = "vcvars64.bat"
if arch == "x86":
batchfile = "vcvars32.bat"
vs_env_bat = f'{vsroot}\\VC\\Auxiliary\\Build\\{batchfile}'
cmd = f'call "{vs_env_bat}" && msbuild {CUSTOM_ACTION_ROOT_DIR}\\uninstall-cmd\\uninstall-cmd.vcxproj /p:Configuration={configuration} /p:Platform={arch}'
else:
cmd = f'msbuild {CUSTOM_ACTION_ROOT_DIR}\\uninstall-cmd\\uninstall-cmd.vcxproj /p:Configuration={configuration} /p:Platform={arch}'
cmd += verprops
print(f"Build Command: {cmd}")
ctx.run(cmd)
srcdll = None
if arch is not None and arch == "x86":
srcdll = f"{CUSTOM_ACTION_ROOT_DIR}\\uninstall-cmd\\{configuration}\\uninstall-cmd.exe"
else:
srcdll = f"{CUSTOM_ACTION_ROOT_DIR}\\uninstall-cmd\\x64\\{configuration}\\uninstall-cmd.exe"
shutil.copy2(srcdll, BIN_PATH)
@task
def clean(_, arch="x64", debug=False):
configuration = "Release"
if debug:
configuration = "Debug"
if arch is not None and arch == "x86":
srcdll = f"{CUSTOM_ACTION_ROOT_DIR}\\uninstall-cmd\\{configuration}"
else:
srcdll = f"{CUSTOM_ACTION_ROOT_DIR}\\uninstall-cmd\\x64\\{configuration}"
shutil.rmtree(srcdll, BIN_PATH)