summaryrefslogtreecommitdiffstats
path: root/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/taskProvider.ts
blob: 9b9b75f9a023eb072bffdd09e75a878bb57f94b5 (plain)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
 * Copyright (C) 2019 Intel Corporation.  All rights reserved.
 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 */

import * as vscode from 'vscode';
import * as os from 'os';
import { TargetConfigPanel } from './view/TargetConfigPanel';

export interface OwnShellOption {
    cmd: string;
    options: vscode.ShellExecutionOptions;
}

export class WasmTaskProvider implements vscode.TaskProvider {
    constructor(
        public _type: Map<string, string>,
        public _script: Map<string, string>,
        public _wamrVersion: string
    ) {}

    buildShellOption: OwnShellOption | undefined;
    runShellOption: OwnShellOption | undefined;
    debugShellOption: OwnShellOption | undefined;
    destroyShellOption: OwnShellOption | undefined;

    private wasmPromise: Thenable<vscode.Task[]> | undefined = undefined;

    public provideTasks(): Thenable<vscode.Task[]> | undefined {
        if (!this.wasmPromise) {
            /* target name is used for generated aot target */
            const targetName =
                TargetConfigPanel.buildArgs.outputFileName.split('.')[0];

            if (
                os.platform() === 'linux' ||
                os.platform() === 'darwin' ||
                os.platform() === 'win32'
            ) {
                /* build */
                this.buildShellOption = {
                    cmd:
                        os.platform() === 'linux' || os.platform() === 'darwin'
                            ? 'bash'
                            : (this._script.get('buildScript') as string),
                    options: {
                        executable: this._script.get('buildScript'),
                        shellArgs: [targetName, this._wamrVersion],
                    },
                };

                /* debug */
                this.debugShellOption = {
                    cmd:
                        os.platform() === 'linux' || os.platform() === 'darwin'
                            ? 'bash'
                            : (this._script.get('debugScript') as string),
                    options: {
                        executable: this._script.get('debugScript'),
                        shellArgs: [targetName, this._wamrVersion],
                    },
                };

                /* run */
                this.runShellOption = {
                    cmd:
                        os.platform() === 'linux' || os.platform() === 'darwin'
                            ? 'bash'
                            : (this._script.get('runScript') as string),
                    options: {
                        executable: this._script.get('runScript'),
                        shellArgs: [targetName, this._wamrVersion],
                    },
                };

                /* destroy */
                /* run */
                this.destroyShellOption = {
                    cmd:
                        os.platform() === 'linux' || os.platform() === 'darwin'
                            ? 'bash'
                            : (this._script.get('destroyScript') as string),
                    options: {
                        executable: this._script.get('destroyScript'),
                        shellArgs: [targetName],
                    },
                };
            } else {
                this.buildShellOption = {
                    cmd: "echo 'os platform is not supported yet'",
                    options: {},
                };

                this.debugShellOption = {
                    cmd: "echo 'os platform is not supported yet'",
                    options: {},
                };

                this.runShellOption = {
                    cmd: "echo 'os platform is not supported yet'",
                    options: {},
                };

                this.destroyShellOption = {
                    cmd: "echo 'os platform is not supported yet'",
                    options: {},
                };
            }

            this.wasmPromise = Promise.resolve([
                new vscode.Task(
                    { type: 'wasm' },
                    vscode.TaskScope.Workspace,
                    'Wasm',
                    this._type.get('Build') as string,
                    new vscode.ShellExecution(
                        this.buildShellOption.cmd,
                        this.buildShellOption.options
                    )
                ),

                new vscode.Task(
                    { type: 'wasm' },
                    vscode.TaskScope.Workspace,
                    'Wasm',
                    this._type.get('Run') as string,
                    new vscode.ShellExecution(
                        this.runShellOption.cmd,
                        this.runShellOption.options
                    )
                ),

                new vscode.Task(
                    { type: 'wasm' },
                    vscode.TaskScope.Workspace,
                    'Wasm',
                    this._type.get('Debug') as string,
                    new vscode.ShellExecution(
                        this.debugShellOption.cmd,
                        this.debugShellOption.options
                    )
                ),

                new vscode.Task(
                    { type: 'wasm' },
                    vscode.TaskScope.Workspace,
                    'Wasm-Container-Before-Build',
                    this._type.get('Destroy') as string,
                    new vscode.ShellExecution(
                        this.destroyShellOption.cmd,
                        this.destroyShellOption.options
                    )
                ),

                new vscode.Task(
                    { type: 'wasm' },
                    vscode.TaskScope.Workspace,
                    'Wasm-Container-Before-Debug',
                    this._type.get('Destroy') as string,
                    new vscode.ShellExecution(
                        this.destroyShellOption.cmd,
                        this.destroyShellOption.options
                    )
                ),

                new vscode.Task(
                    { type: 'wasm' },
                    vscode.TaskScope.Workspace,
                    'Wasm-Container-Before-Run',
                    this._type.get('Destroy') as string,
                    new vscode.ShellExecution(
                        this.destroyShellOption.cmd,
                        this.destroyShellOption.options
                    )
                ),

                new vscode.Task(
                    { type: 'wasm' },
                    vscode.TaskScope.Workspace,
                    'Wasm-Container-After-Build',
                    this._type.get('Destroy') as string,
                    new vscode.ShellExecution(
                        this.destroyShellOption.cmd,
                        this.destroyShellOption.options
                    )
                ),

                new vscode.Task(
                    { type: 'wasm' },
                    vscode.TaskScope.Workspace,
                    'Wasm-Container-After-Debug',
                    this._type.get('Destroy') as string,
                    new vscode.ShellExecution(
                        this.destroyShellOption.cmd,
                        this.destroyShellOption.options
                    )
                ),

                new vscode.Task(
                    { type: 'wasm' },
                    vscode.TaskScope.Workspace,
                    'Wasm-Container-After-Run',
                    this._type.get('Destroy') as string,
                    new vscode.ShellExecution(
                        this.destroyShellOption.cmd,
                        this.destroyShellOption.options
                    )
                ),
            ]);
        }

        return this.wasmPromise;
    }

    /**
     * if the task or task in tasks.json does not set command, `
     * resolveTask` will be invoked,
     * otherwise, `provideTasks` will be invoked
     * @param _task
     * @returns
     */
    public resolveTask(task: vscode.Task): vscode.Task | undefined {
        if (task) {
            return task;
        }
        return undefined;
    }
}