Skip to content

Commit

Permalink
Merge remote branch 'origin/master' into edge
Browse files Browse the repository at this point in the history
  • Loading branch information
automatic-merge committed Jul 18, 2024
2 parents b3be331 + abbc2f4 commit 9b94c68
Show file tree
Hide file tree
Showing 12 changed files with 282 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# -e causes the execution to terminate as soon as any command fails
set -x -e
DEBUG=$1 # Value is '' or 'debug'
RUNNER_OS=$2 # ${{ runner.os }} is Linux, Windiws, maxOS
RUNNER_OS=$2 # ${{ runner.os }} is Linux, Windows, macOS
TAG=$3 # For master it's 24.0.999, while for tag it's the tag itself
NO_REBASE=$4 # Specify this to skip the rebase over the edge branch. Used for local debugging.
CROSS=$5 # '' for native, aarch64 for ARM cross
Expand Down
120 changes: 82 additions & 38 deletions .github/workflows/pack-binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,90 @@ VSCE_TOKEN=$2
OVSX_TOKEN=$3
TAG=$4 # For master it's 24.0.999, while for tag it's the tag itself

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

chmod -R -v +x als-*-$DEBUG als-{Linux,macOS}-${DEBUG}aarch64
function os_to_node_platform() {
case "$1" in
Linux)
echo -n "linux"
;;
Windows)
echo -n "win32"
;;
macOS)
echo -n "darwin"
;;
esac
}

function cross_to_node_arch() {
case "$1" in
aarch64)
echo -n "arm64"
;;
*)
echo -n "x64"
;;
esac
}

ext_dir=integration/vscode/ada

(
cd "$ext_dir"

# Set package version based on the Git tag
sed -i -e "/version/s/[0-9][0-9.]*/$TAG/" package.json
# Change extension ID and name if we're in debug mode
[ -z "$DEBUG" ] || sed -i -e '/^ "name"/s/ada/ada-debug/' \
-e '/displayName/s/Ada & SPARK/Ada & SPARK (with debug info)/' package.json

# Install NPM deps
npm -v
node -v
which node
npm install

# Create change log
make_change_log >CHANGELOG.md
)

# At the moment we only create VSIX-es for macOS on GitHub. Other platforms are
# provided elsewhere.
# shellcheck disable=SC2043
for OS in macOS Windows Linux; do
for CROSS in "" "aarch64"; do
source=als-"$OS"-"$DEBUG""$CROSS"
if [ -d "$source" ]; then
# Make sure the file are executable
chmod -R -v +x "$source"
# Copy the binary in place
rsync -rva als-$OS-"$DEBUG""$CROSS"/ "$ext_dir"/
# Delete debug info
rm -rf -v "$ext_dir"/{arm,arm64,x64}/{linux,darwin,win32}/*.{debug,dSYM}

(
cd "$ext_dir"
# Create the VSIX
npx vsce package --target "$(os_to_node_platform $OS)-$(cross_to_node_arch $CROSS)"
)

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

rsync -rva als-{Linux,macOS}-${DEBUG}aarch64/ integration/vscode/ada/

# VS Code is supported on arm, arm64 and x64 so we only consider those
# architectures
rm -rf -v integration/vscode/ada/{arm,arm64,x64}/{linux,darwin,win32}/*.{debug,dSYM}

pushd integration/vscode/ada
sed -i -e "/version/s/[0-9][0-9.]*/$TAG/" package.json
[ -z "$DEBUG" ] || sed -i -e '/^ "name"/s/ada/ada-debug/' \
-e '/displayName/s/Ada/Ada (with debug info)/' package.json

npm -v; node -v; which node
npm install
sudo npm install -g @vscode/vsce --unsafe-perm
sudo npm install -g esbuild --unsafe-perm
make_change_log > CHANGELOG.md
if [[ ${GITHUB_REF##*/} = 2*.[0-9]*.[0-9]* ]] ; then
vsce publish -p "$VSCE_TOKEN" || true
npx ovsx publish -p "$OVSX_TOKEN" || true
fi
vsce package || true
popd
mv -v integration/vscode/ada/*.vsix .
git checkout integration/vscode/ada/package.json
rm -rf integration/vscode/ada/{arm,arm64,x64}/{linux,darwin,win32}
# Move all .vsix packages to the root of the checkout
mv -v "$ext_dir"/*.vsix .
# Discard the package.json and package-lock.json changes
git checkout "$ext_dir"/package*.json
10 changes: 7 additions & 3 deletions doc/traces.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# ALS Trace File

Default trace file name is `$HOME/.als/traces.cfg`. This file gets automatically created
if not present on the disk. The first line of the traces file
defines the traces output stream (a filename in our case) and the other
Default trace file names are:

* `$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.
* `$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.

These files gets automatically created if not present on the disk. The first line of the
traces files defines the traces output stream (a filename in our case) and the other
lines are used to enable or disable traces.

Note that you can provide another traces file via the `--tracefile=<FILE>` command line option.
Expand Down
3 changes: 2 additions & 1 deletion integration/vscode/ada/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"Extension Packs"
],
"extensionPack": [
"ms-vscode.cpptools"
"ms-vscode.cpptools",
"ms-sarifvscode.sarif-viewer"
],
"activationEvents": [
"workspaceContains:*.gpr",
Expand Down
100 changes: 88 additions & 12 deletions integration/vscode/ada/src/ExtensionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import { logger } from './extension';
import { GnatTaskProvider } from './gnatTaskProvider';
import { initializeTesting } from './gnattest';
import { GprTaskProvider } from './gprTaskProvider';
import { TERMINAL_ENV_SETTING_NAME } from './helpers';
import { getArgValue, TERMINAL_ENV_SETTING_NAME } from './helpers';
import {
SimpleTaskDef,
SimpleTaskProvider,
TASK_TYPE_ADA,
TASK_TYPE_SPARK,
createAdaTaskProvider,
createSparkTaskProvider,
} from './taskProviders';
import { isAbsolute } from 'path';

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

private registeredTaskProviders: Disposable[];
private taskDisposables: Disposable[];

public readonly codelensProvider = new AdaCodeLensProvider();
public readonly testController: vscode.TestController;
Expand Down Expand Up @@ -78,7 +80,7 @@ export class ExtensionState {
[],
'**/.{adb,ads,adc,ada}'
);
this.registeredTaskProviders = [];
this.taskDisposables = [];
const result = initializeDebugging(this.context);
this.initialDebugConfigProvider = result.providerInitial;
this.dynamicDebugConfigProvider = result.providerDynamic;
Expand All @@ -87,36 +89,51 @@ export class ExtensionState {

public start = async () => {
await Promise.all([this.gprClient.start(), this.adaClient.start()]);
this.registerTaskProviders();
this.registerTaskDisposables();
this.context.subscriptions.push(
vscode.languages.registerCodeLensProvider('ada', this.codelensProvider)
);
};

public dispose = () => {
this.unregisterTaskProviders();
this.unregisterTaskDisposables();
};

public registerTaskProviders = (): void => {
/**
* Register all the task disposables needed by the extension (e.g: task providers,
* listeners...).
*/
public registerTaskDisposables = (): void => {
this.adaTaskProvider = createAdaTaskProvider();
this.sparkTaskProvider = createSparkTaskProvider();

this.registeredTaskProviders = [
this.taskDisposables = [
vscode.tasks.registerTaskProvider(GnatTaskProvider.gnatType, new GnatTaskProvider()),
vscode.tasks.registerTaskProvider(
GprTaskProvider.gprTaskType,
new GprTaskProvider(this.adaClient)
),
vscode.tasks.registerTaskProvider(TASK_TYPE_ADA, this.adaTaskProvider),
vscode.tasks.registerTaskProvider(TASK_TYPE_SPARK, this.sparkTaskProvider),

// Add a listener on tasks to open the SARIF Viewer when the
// task that ends outputs a SARIF file.
vscode.tasks.onDidEndTaskProcess(async (e) => {
const task = e.execution.task;
await openSARIFViewerIfNeeded(task);
}),
];
};

public unregisterTaskProviders = (): void => {
for (const item of this.registeredTaskProviders) {
/**
* Unregister all the task disposables needed by the extension (e.g: task providers,
* listeners...).
*/
public unregisterTaskDisposables = (): void => {
for (const item of this.taskDisposables) {
item.dispose();
}
this.registeredTaskProviders = [];
this.taskDisposables = [];
};

/**
Expand Down Expand Up @@ -150,8 +167,8 @@ export class ExtensionState {
) {
logger.info('project related settings have changed: clearing caches for tasks');
this.clearALSCache();
this.unregisterTaskProviders();
this.registerTaskProviders();
this.unregisterTaskDisposables();
this.registerTaskDisposables();
}

// React to changes made in the environment variables, showing
Expand Down Expand Up @@ -239,3 +256,62 @@ export class ExtensionState {
return this.sparkTaskProvider;
}
}

/**
*
* Open the SARIF Viewer if the given task outputs its results in
* a SARIF file (e.g: GNAT SAS Report task).
*/
async function openSARIFViewerIfNeeded(task: vscode.Task) {
const definition: SimpleTaskDef = task.definition;

if (definition) {
const args = definition.args;

if (args?.some((arg) => getArgValue(arg).includes('sarif'))) {
const execution = task.execution;
let cwd = undefined;

if (execution && execution instanceof vscode.ShellExecution) {
cwd = execution.options?.cwd;
}

if (!cwd && vscode.workspace.workspaceFolders) {
cwd = vscode.workspace.workspaceFolders[0].uri.fsPath;
}

const sarifExt = vscode.extensions.getExtension('ms-sarifvscode.sarif-viewer');

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const sarifExtAPI = sarifExt ? await sarifExt.activate() : undefined;

if (cwd && sarifExtAPI) {
const cwdURI = vscode.Uri.file(cwd);
const outputFilePathArgRaw = args.find((arg) =>
getArgValue(arg).includes('.sarif')
);

if (outputFilePathArgRaw) {
// Convert the raw argument into a string
const outputFilePathArg = getArgValue(outputFilePathArgRaw);

// The SARIF output file can be specified as '--output=path/to/file.sarif':
// split the argument on '=' if that's the case, to retrieve only the file path
const outputFilePath = outputFilePathArg.includes('=')
? outputFilePathArg.split('=').pop()
: outputFilePathArg;

if (outputFilePath) {
const sarifFileURI = isAbsolute(outputFilePath)
? vscode.Uri.file(outputFilePath)
: vscode.Uri.joinPath(cwdURI, outputFilePath);

// eslint-disable-next-line max-len
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
await sarifExtAPI.openLogs([sarifFileURI]);
}
}
}
}
}
}
12 changes: 10 additions & 2 deletions integration/vscode/ada/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ import { LanguageClient } from 'vscode-languageclient/node';
import winston from 'winston';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { existsSync } from 'fs';
import { ExtensionState } from './ExtensionState';
import { EXTENSION_NAME, adaExtState, logger, mainOutputChannel } from './extension';

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

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

/**
* Get the given argument actual string value, converting it to a string if
* specified as {@link vscode.ShellQuotedString}.
* @returns a string containing the argument's actual value.
*/
export function getArgValue(a: string | vscode.ShellQuotedString): string {
return typeof a == 'string' ? a : a.value;
}

/**
* Read the environment variables specified in the vscode setting
* `terminal.integrated.env.<os>` and set them in the given ProcessEnv object.
Expand Down
Loading

0 comments on commit 9b94c68

Please sign in to comment.