/
CeedlingExec.py
89 lines (73 loc) · 2.82 KB
/
CeedlingExec.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
78
79
80
81
82
83
84
85
86
87
88
89
import sys
import os
import sublime
import sublime_plugin
from .CeedlingSettings import CeedlingProjectSettings
from .CeedlingSettings import CeedlingUserSettings
class CeedlingExecCommand(sublime_plugin.WindowCommand):
def run(self, **kwargs):
# "working_dir" is set by "new project" command.
# project.xml does not exist unit project is created.
if kwargs.get("working_dir") is None:
try:
self.conf = CeedlingProjectSettings(self.window)
except OSError as e:
self.window.status_message("Ceedling: {}".format(e))
return
kwargs["working_dir"] = self.conf.working_dir
if hasattr(self, "conf"):
test_dir = os.path.join(
self.conf.working_dir, self.conf.test[0].rstrip("*")
)
else:
test_dir = ""
variables = self.window.extract_variables()
settings = CeedlingUserSettings()
# Check if the user is attempting to build an unsupported file.
for i in kwargs.get("tasks"):
if i.find("$file") != -1:
if variables.get("file_name") is None or (
variables.get("file_extension")
not in (self.conf.source_ext, self.conf.header_ext)
):
self.window.status_message(
"Ceedling: Cannot test {}".format(
variables.get("file_name", "nothing")
)
)
return
elif i.startswith("release") and not self.conf.release_build:
sublime.error_message(
"Release build is not configured.\nCheck project.yml"
)
return
if settings.logging & (
i.startswith("test") | i.startswith("release")
):
kwargs["prefix"] = kwargs.get("prefix", list()) + ["logging"]
if settings.verbose & (
i.startswith("test") | i.startswith("release")
):
kwargs["prefix"] = kwargs.get("prefix", list()) + [
"verbosity[%d]" % settings.verbose_level
]
task_sub = [
sublime.expand_variables(task, variables)
for task in kwargs.pop("tasks", [])
]
# Build up the command line
if sys.platform == "win32":
cmd = ["ceedling.bat"]
else:
cmd = ["ceedling"]
for i in (
kwargs.pop("prefix", []),
task_sub,
kwargs.pop("options", []),
):
cmd.extend(i)
kwargs["cmd"] = cmd
self.window.run_command("exec", kwargs)
self.window.find_output_panel("exec").settings().set(
"result_base_dir", test_dir
)