This repository has been archived by the owner on Sep 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhls_stack.py
145 lines (113 loc) · 4.37 KB
/
hls_stack.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python3
#
# hls_stack.py
# Copyright 2022 JCWasmx86 <[email protected]>
#
# Based on: Stack_plugin.py
# Copyright 2018 Alberto Fanjul <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import threading
import os
from gi.repository import Gio
from gi.repository import GLib
from gi.repository import GObject
from gi.repository import Ide
_ = Ide.gettext
_ATTRIBUTES = ",".join([
Gio.FILE_ATTRIBUTE_STANDARD_NAME,
Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
Gio.FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON,
])
class StackBuildSystemDiscovery(Ide.SimpleBuildSystemDiscovery):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.props.glob = "stack.yaml"
self.props.hint = "hls_stack"
self.props.priority = 2000
class StackBuildSystem(Ide.Object, Ide.BuildSystem):
project_file = GObject.Property(type=Gio.File)
def do_get_id(self):
return "stack"
def do_get_display_name(self):
return "Stack"
def do_get_priority(self):
return 2000
class StackPipelineAddin(Ide.Object, Ide.PipelineAddin):
"""
The StackPipelineAddin is responsible for creating the necessary build
stages and attaching them to phases of the build pipeline.
"""
def do_load(self, pipeline):
context = self.get_context()
build_system = Ide.BuildSystem.from_context(context)
if type(build_system) != StackBuildSystem:
return
project_file = build_system.props.project_file
project_dir = os.path.dirname(project_file.get_path())
config = pipeline.get_config()
build_dir = pipeline.get_builddir()
runtime = config.get_runtime()
src_dir = pipeline.get_srcdir()
build_launcher = pipeline.create_launcher()
build_launcher.set_cwd(src_dir)
new_path = os.path.expanduser("~/.ghcup/bin") + ":/app/bin/:/usr/bin/:" + os.getenv("PATH")
build_launcher.setenv("PATH", new_path, True)
build_launcher.push_argv(os.path.expanduser("~/.ghcup/bin/stack"))
build_launcher.push_argv("build")
clean_launcher = pipeline.create_launcher()
clean_launcher.setenv("PATH", new_path, True)
clean_launcher.set_cwd(src_dir)
clean_launcher.push_argv(os.path.expanduser("~/.ghcup/bin/stack"))
clean_launcher.push_argv("clean")
build_stage = Ide.PipelineStageLauncher.new(context, build_launcher)
build_stage.set_name(_("Building project"))
build_stage.set_clean_launcher(clean_launcher)
build_stage.connect("query", self._query)
self.track(pipeline.attach(Ide.PipelinePhase.BUILD, 0, build_stage))
def _query(self, stage, pipeline, targets, cancellable):
stage.set_completed(False)
class StackBuildTarget(Ide.Object, Ide.BuildTarget):
def do_get_install_directory(self):
return None
def do_get_name(self):
return "stack-run"
def do_get_language(self):
return "haskell"
def do_get_cwd(self):
context = self.get_context()
project_file = Ide.BuildSystem.from_context(context).project_file
if project_file.query_file_type(0, None) == Gio.FileType.DIRECTORY:
return project_file.get_path()
else:
return project_file.get_parent().get_path()
def do_get_argv(self):
return [os.path.expanduser("~/.ghcup/bin/stack"), "run"]
def do_get_priority(self):
return 0
class StackBuildTargetProvider(Ide.Object, Ide.BuildTargetProvider):
def do_get_targets_async(self, cancellable, callback, data):
task = Ide.Task.new(self, cancellable, callback)
task.set_priority(GLib.PRIORITY_LOW)
context = self.get_context()
build_system = Ide.BuildSystem.from_context(context)
if type(build_system) != StackBuildSystem:
task.return_error(GLib.Error("Not stack build system", domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.NOT_SUPPORTED))
return
task.targets = [build_system.ensure_child_typed(StackBuildTarget)]
task.return_boolean(True)
def do_get_targets_finish(self, result):
if result.propagate_boolean():
return result.targets