Skip to content

Commit 9b94c68

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents b3be331 + abbc2f4 commit 9b94c68

File tree

12 files changed

+282
-76
lines changed

12 files changed

+282
-76
lines changed

.github/workflows/build-binaries.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# -e causes the execution to terminate as soon as any command fails
55
set -x -e
66
DEBUG=$1 # Value is '' or 'debug'
7-
RUNNER_OS=$2 # ${{ runner.os }} is Linux, Windiws, maxOS
7+
RUNNER_OS=$2 # ${{ runner.os }} is Linux, Windows, macOS
88
TAG=$3 # For master it's 24.0.999, while for tag it's the tag itself
99
NO_REBASE=$4 # Specify this to skip the rebase over the edge branch. Used for local debugging.
1010
CROSS=$5 # '' for native, aarch64 for ARM cross

.github/workflows/pack-binaries.sh

Lines changed: 82 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,90 @@ VSCE_TOKEN=$2
55
OVSX_TOKEN=$3
66
TAG=$4 # For master it's 24.0.999, while for tag it's the tag itself
77

8-
function make_change_log()
9-
{
10-
echo "# Release notes"
11-
echo ""
12-
for TAG_ID in `git tag --list --sort=-v:refname '2*'` ; do
13-
DATE=`git show --no-patch --format=Date:%ad --date=short $TAG_ID |\
14-
grep Date: | sed -e s/Date://`
15-
echo "## $TAG_ID ($DATE)"
16-
git show --no-patch --format=%n $TAG_ID | sed -e '1,/Release notes/d'
17-
done
8+
function make_change_log() {
9+
echo "# Release notes"
10+
echo ""
11+
for TAG_ID in $(git tag --list --sort=-v:refname '2*'); do
12+
DATE=$(git show --no-patch --format=Date:%ad --date=short "$TAG_ID" |
13+
grep Date: | sed -e s/Date://)
14+
echo "## $TAG_ID ($DATE)"
15+
git show --no-patch --format=%n "$TAG_ID" | sed -e '1,/Release notes/d'
16+
done
1817
}
1918

20-
chmod -R -v +x als-*-$DEBUG als-{Linux,macOS}-${DEBUG}aarch64
19+
function os_to_node_platform() {
20+
case "$1" in
21+
Linux)
22+
echo -n "linux"
23+
;;
24+
Windows)
25+
echo -n "win32"
26+
;;
27+
macOS)
28+
echo -n "darwin"
29+
;;
30+
esac
31+
}
32+
33+
function cross_to_node_arch() {
34+
case "$1" in
35+
aarch64)
36+
echo -n "arm64"
37+
;;
38+
*)
39+
echo -n "x64"
40+
;;
41+
esac
42+
}
43+
44+
ext_dir=integration/vscode/ada
45+
46+
(
47+
cd "$ext_dir"
48+
49+
# Set package version based on the Git tag
50+
sed -i -e "/version/s/[0-9][0-9.]*/$TAG/" package.json
51+
# Change extension ID and name if we're in debug mode
52+
[ -z "$DEBUG" ] || sed -i -e '/^ "name"/s/ada/ada-debug/' \
53+
-e '/displayName/s/Ada & SPARK/Ada & SPARK (with debug info)/' package.json
54+
55+
# Install NPM deps
56+
npm -v
57+
node -v
58+
which node
59+
npm install
60+
61+
# Create change log
62+
make_change_log >CHANGELOG.md
63+
)
64+
65+
# At the moment we only create VSIX-es for macOS on GitHub. Other platforms are
66+
# provided elsewhere.
67+
# shellcheck disable=SC2043
68+
for OS in macOS Windows Linux; do
69+
for CROSS in "" "aarch64"; do
70+
source=als-"$OS"-"$DEBUG""$CROSS"
71+
if [ -d "$source" ]; then
72+
# Make sure the file are executable
73+
chmod -R -v +x "$source"
74+
# Copy the binary in place
75+
rsync -rva als-$OS-"$DEBUG""$CROSS"/ "$ext_dir"/
76+
# Delete debug info
77+
rm -rf -v "$ext_dir"/{arm,arm64,x64}/{linux,darwin,win32}/*.{debug,dSYM}
78+
79+
(
80+
cd "$ext_dir"
81+
# Create the VSIX
82+
npx vsce package --target "$(os_to_node_platform $OS)-$(cross_to_node_arch $CROSS)"
83+
)
2184

22-
for X in Linux macOS Windows ; do
23-
rsync -rva als-$X-$DEBUG/ integration/vscode/ada/
85+
# Cleanup the binary directory
86+
rm -rf -v "$ext_dir"/{arm,arm64,x64}
87+
fi
88+
done
2489
done
2590

26-
rsync -rva als-{Linux,macOS}-${DEBUG}aarch64/ integration/vscode/ada/
27-
28-
# VS Code is supported on arm, arm64 and x64 so we only consider those
29-
# architectures
30-
rm -rf -v integration/vscode/ada/{arm,arm64,x64}/{linux,darwin,win32}/*.{debug,dSYM}
31-
32-
pushd integration/vscode/ada
33-
sed -i -e "/version/s/[0-9][0-9.]*/$TAG/" package.json
34-
[ -z "$DEBUG" ] || sed -i -e '/^ "name"/s/ada/ada-debug/' \
35-
-e '/displayName/s/Ada/Ada (with debug info)/' package.json
36-
37-
npm -v; node -v; which node
38-
npm install
39-
sudo npm install -g @vscode/vsce --unsafe-perm
40-
sudo npm install -g esbuild --unsafe-perm
41-
make_change_log > CHANGELOG.md
42-
if [[ ${GITHUB_REF##*/} = 2*.[0-9]*.[0-9]* ]] ; then
43-
vsce publish -p "$VSCE_TOKEN" || true
44-
npx ovsx publish -p "$OVSX_TOKEN" || true
45-
fi
46-
vsce package || true
47-
popd
48-
mv -v integration/vscode/ada/*.vsix .
49-
git checkout integration/vscode/ada/package.json
50-
rm -rf integration/vscode/ada/{arm,arm64,x64}/{linux,darwin,win32}
91+
# Move all .vsix packages to the root of the checkout
92+
mv -v "$ext_dir"/*.vsix .
93+
# Discard the package.json and package-lock.json changes
94+
git checkout "$ext_dir"/package*.json

doc/traces.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# ALS Trace File
22

3-
Default trace file name is `$HOME/.als/traces.cfg`. This file gets automatically created
4-
if not present on the disk. The first line of the traces file
5-
defines the traces output stream (a filename in our case) and the other
3+
Default trace file names are:
4+
5+
* `$HOME/.als/ada_ls_traces.cfg` for the language server spawned for Ada projects/files, which produce `ada_ls_log.<timestamp>.log` log files by default.
6+
* `$HOME/.als/gpr_ls_traces.cfg` for the language server spawned for GPR project files, which produce `gpr_ls_log.<timestamp>.log` log files by default.
7+
8+
These files gets automatically created if not present on the disk. The first line of the
9+
traces files defines the traces output stream (a filename in our case) and the other
610
lines are used to enable or disable traces.
711

812
Note that you can provide another traces file via the `--tracefile=<FILE>` command line option.

integration/vscode/ada/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"Extension Packs"
1414
],
1515
"extensionPack": [
16-
"ms-vscode.cpptools"
16+
"ms-vscode.cpptools",
17+
"ms-sarifvscode.sarif-viewer"
1718
],
1819
"activationEvents": [
1920
"workspaceContains:*.gpr",

integration/vscode/ada/src/ExtensionState.ts

Lines changed: 88 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import { logger } from './extension';
77
import { GnatTaskProvider } from './gnatTaskProvider';
88
import { initializeTesting } from './gnattest';
99
import { GprTaskProvider } from './gprTaskProvider';
10-
import { TERMINAL_ENV_SETTING_NAME } from './helpers';
10+
import { getArgValue, TERMINAL_ENV_SETTING_NAME } from './helpers';
1111
import {
12+
SimpleTaskDef,
1213
SimpleTaskProvider,
1314
TASK_TYPE_ADA,
1415
TASK_TYPE_SPARK,
1516
createAdaTaskProvider,
1617
createSparkTaskProvider,
1718
} from './taskProviders';
19+
import { isAbsolute } from 'path';
1820

1921
/**
2022
* This class encapsulates all state that should be maintained throughout the
@@ -36,7 +38,7 @@ export class ExtensionState {
3638
};
3739
public readonly initialDebugConfigProvider: AdaInitialDebugConfigProvider;
3840

39-
private registeredTaskProviders: Disposable[];
41+
private taskDisposables: Disposable[];
4042

4143
public readonly codelensProvider = new AdaCodeLensProvider();
4244
public readonly testController: vscode.TestController;
@@ -78,7 +80,7 @@ export class ExtensionState {
7880
[],
7981
'**/.{adb,ads,adc,ada}'
8082
);
81-
this.registeredTaskProviders = [];
83+
this.taskDisposables = [];
8284
const result = initializeDebugging(this.context);
8385
this.initialDebugConfigProvider = result.providerInitial;
8486
this.dynamicDebugConfigProvider = result.providerDynamic;
@@ -87,36 +89,51 @@ export class ExtensionState {
8789

8890
public start = async () => {
8991
await Promise.all([this.gprClient.start(), this.adaClient.start()]);
90-
this.registerTaskProviders();
92+
this.registerTaskDisposables();
9193
this.context.subscriptions.push(
9294
vscode.languages.registerCodeLensProvider('ada', this.codelensProvider)
9395
);
9496
};
9597

9698
public dispose = () => {
97-
this.unregisterTaskProviders();
99+
this.unregisterTaskDisposables();
98100
};
99101

100-
public registerTaskProviders = (): void => {
102+
/**
103+
* Register all the task disposables needed by the extension (e.g: task providers,
104+
* listeners...).
105+
*/
106+
public registerTaskDisposables = (): void => {
101107
this.adaTaskProvider = createAdaTaskProvider();
102108
this.sparkTaskProvider = createSparkTaskProvider();
103109

104-
this.registeredTaskProviders = [
110+
this.taskDisposables = [
105111
vscode.tasks.registerTaskProvider(GnatTaskProvider.gnatType, new GnatTaskProvider()),
106112
vscode.tasks.registerTaskProvider(
107113
GprTaskProvider.gprTaskType,
108114
new GprTaskProvider(this.adaClient)
109115
),
110116
vscode.tasks.registerTaskProvider(TASK_TYPE_ADA, this.adaTaskProvider),
111117
vscode.tasks.registerTaskProvider(TASK_TYPE_SPARK, this.sparkTaskProvider),
118+
119+
// Add a listener on tasks to open the SARIF Viewer when the
120+
// task that ends outputs a SARIF file.
121+
vscode.tasks.onDidEndTaskProcess(async (e) => {
122+
const task = e.execution.task;
123+
await openSARIFViewerIfNeeded(task);
124+
}),
112125
];
113126
};
114127

115-
public unregisterTaskProviders = (): void => {
116-
for (const item of this.registeredTaskProviders) {
128+
/**
129+
* Unregister all the task disposables needed by the extension (e.g: task providers,
130+
* listeners...).
131+
*/
132+
public unregisterTaskDisposables = (): void => {
133+
for (const item of this.taskDisposables) {
117134
item.dispose();
118135
}
119-
this.registeredTaskProviders = [];
136+
this.taskDisposables = [];
120137
};
121138

122139
/**
@@ -150,8 +167,8 @@ export class ExtensionState {
150167
) {
151168
logger.info('project related settings have changed: clearing caches for tasks');
152169
this.clearALSCache();
153-
this.unregisterTaskProviders();
154-
this.registerTaskProviders();
170+
this.unregisterTaskDisposables();
171+
this.registerTaskDisposables();
155172
}
156173

157174
// React to changes made in the environment variables, showing
@@ -239,3 +256,62 @@ export class ExtensionState {
239256
return this.sparkTaskProvider;
240257
}
241258
}
259+
260+
/**
261+
*
262+
* Open the SARIF Viewer if the given task outputs its results in
263+
* a SARIF file (e.g: GNAT SAS Report task).
264+
*/
265+
async function openSARIFViewerIfNeeded(task: vscode.Task) {
266+
const definition: SimpleTaskDef = task.definition;
267+
268+
if (definition) {
269+
const args = definition.args;
270+
271+
if (args?.some((arg) => getArgValue(arg).includes('sarif'))) {
272+
const execution = task.execution;
273+
let cwd = undefined;
274+
275+
if (execution && execution instanceof vscode.ShellExecution) {
276+
cwd = execution.options?.cwd;
277+
}
278+
279+
if (!cwd && vscode.workspace.workspaceFolders) {
280+
cwd = vscode.workspace.workspaceFolders[0].uri.fsPath;
281+
}
282+
283+
const sarifExt = vscode.extensions.getExtension('ms-sarifvscode.sarif-viewer');
284+
285+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
286+
const sarifExtAPI = sarifExt ? await sarifExt.activate() : undefined;
287+
288+
if (cwd && sarifExtAPI) {
289+
const cwdURI = vscode.Uri.file(cwd);
290+
const outputFilePathArgRaw = args.find((arg) =>
291+
getArgValue(arg).includes('.sarif')
292+
);
293+
294+
if (outputFilePathArgRaw) {
295+
// Convert the raw argument into a string
296+
const outputFilePathArg = getArgValue(outputFilePathArgRaw);
297+
298+
// The SARIF output file can be specified as '--output=path/to/file.sarif':
299+
// split the argument on '=' if that's the case, to retrieve only the file path
300+
const outputFilePath = outputFilePathArg.includes('=')
301+
? outputFilePathArg.split('=').pop()
302+
: outputFilePathArg;
303+
304+
if (outputFilePath) {
305+
const sarifFileURI = isAbsolute(outputFilePath)
306+
? vscode.Uri.file(outputFilePath)
307+
: vscode.Uri.joinPath(cwdURI, outputFilePath);
308+
309+
// eslint-disable-next-line max-len
310+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
311+
await sarifExtAPI.openLogs([sarifFileURI]);
312+
}
313+
}
314+
}
315+
}
316+
}
317+
}

integration/vscode/ada/src/helpers.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ import { LanguageClient } from 'vscode-languageclient/node';
2323
import winston from 'winston';
2424
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2525
import { existsSync } from 'fs';
26-
import { ExtensionState } from './ExtensionState';
2726
import { EXTENSION_NAME, adaExtState, logger, mainOutputChannel } from './extension';
2827

2928
/* Whether we are under Windows */
3029
const isWindows = process.platform === 'win32';
3130

3231
/**
33-
* Substitue any variable reference present in the given string. VS Code
32+
* Substitute any variable reference present in the given string. VS Code
3433
* variable references are listed here:
3534
* https://code.visualstudio.com/docs/editor/variables-reference
3635
* @param str - string to perform substitution on
@@ -164,6 +163,15 @@ export function getEvaluatedTerminalEnv() {
164163
return custom_env;
165164
}
166165

166+
/**
167+
* Get the given argument actual string value, converting it to a string if
168+
* specified as {@link vscode.ShellQuotedString}.
169+
* @returns a string containing the argument's actual value.
170+
*/
171+
export function getArgValue(a: string | vscode.ShellQuotedString): string {
172+
return typeof a == 'string' ? a : a.value;
173+
}
174+
167175
/**
168176
* Read the environment variables specified in the vscode setting
169177
* `terminal.integrated.env.<os>` and set them in the given ProcessEnv object.

0 commit comments

Comments
 (0)