Skip to content

Commit 3b452df

Browse files
committed
Add devcontainer example
Update other examples to avoid deprecated names. (no-issue-check)
1 parent 6356b60 commit 3b452df

File tree

14 files changed

+170
-8
lines changed

14 files changed

+170
-8
lines changed

integration/vscode/Code Samples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Here is some code samples for the Ada Language Server and the VS Code extension.
77
* [Gnatprove](gnatprove/) - SPARK/gnatprove integration example
88
* [Refactoring demos](refactoring_demos/) - sample code to check refactoring capabilities
99
* [Custom worspace-specific environment](custom_env/) - example showing how to set workspace-specific environment variables
10+
* [Devcontainer example](devcontainer/) - example showing how to set a devcontainer up

integration/vscode/Code Samples/custom_env/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ Open VS Code and click on the `File -> Open Workspace From File...` menu
2222
and select the `custom_env.code-workspace` file present in this folder.
2323

2424
You can then build the project by clicking on the `Terminal -> Run Task...` menu,
25-
and by selecting the `gprbuild -> ada: Build current project` task.
25+
and by selecting the `ada` -> `ada: Build current project` task.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
3+
{
4+
"name": "Ubuntu",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"image": "mcr.microsoft.com/devcontainers/base:jammy",
7+
"extensions": ["adacore.ada"],
8+
9+
// Features to add to the dev container. More info: https://containers.dev/features.
10+
// "features": {},
11+
12+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
13+
// "forwardPorts": [],
14+
15+
// Use 'postCreateCommand' to run commands after the container is created.
16+
"postCreateCommand": "sh .devcontainer/install_alr_and_gnat.sh",
17+
18+
// Configure tool-specific properties.
19+
// "customizations": {},
20+
21+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
22+
// "remoteUser": "root"
23+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
set -e -x
4+
5+
curl -L -O https://github.com/alire-project/alire/releases/download/v2.0.1/alr-2.0.1-bin-x86_64-linux.zip
6+
unzip alr-2.0.1-bin-x86_64-linux.zip
7+
rm -f alr-2.0.1-bin-x86_64-linux.zip
8+
echo export PATH=$(realpath bin):'$PATH' >> ~/.profile
9+
export PATH=$(realpath bin):$PATH
10+
alr --non-interactive toolchain --select gnat_native gprbuild
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for more information:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
# https://containers.dev/guide/dependabot
6+
7+
version: 2
8+
updates:
9+
- package-ecosystem: "devcontainers"
10+
directory: "/"
11+
schedule:
12+
interval: weekly
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Workspace-specific environment for devcontainers
2+
3+
This demo presents a workspace-specific environment specification for
4+
devcontainers. This is a modified version of `custom_env` example.
5+
6+
The `.devcontainer` folder contains a `devcontainer.json` file with
7+
instructions on how to build the container, install Alire and
8+
install the Ada toolchain with Alire.
9+
10+
The folder contains a `custom_env.code-workspace` file that setups a custom
11+
environment for this workspace, setting and modifying some environment
12+
variables, including the `PATH` pointing to the Alire installed toolchain.
13+
14+
NOTE! Please check `PATH` variable in the `custom_env.code-workspace` file,
15+
because it will outdate as Alire gets updated versions of the toolchain.
16+
17+
# Run the Code Sample
18+
19+
Open VS Code and click on the `File -> Open Workspace From File...` menu
20+
and select the `custom_env.code-workspace` file present in this folder.
21+
22+
VS Code propose to build the devcontainer and open the folder in it.
23+
As you agree, container will be built and GNAT toolchain will be installed.
24+
After that you should reload the project (with `Ada: repoad project` command
25+
launched from the Command palette `Ctrl+Shift+P`) or reload the window
26+
(with `Developer: Reload Window` command).
27+
28+
Now you have ready to use environment!
29+
30+
You can then build the project by clicking on the `Terminal -> Run Task...` menu,
31+
and by selecting the `ada` then `ada: Build current project` task.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "."
5+
}
6+
],
7+
"settings": {
8+
"ada.projectFile": "default.gpr",
9+
10+
// Set a workspace-specific environment for Linux/OSX platforms
11+
"terminal.integrated.env.linux": {
12+
// Set MAIN_NUMBER scenario variable to MAIN_2 directly from the environment
13+
"MAIN_NUMBER": "MAIN_2",
14+
15+
// Optionally, you can append the Ada toolchain of your choice to the PATH environment variable
16+
// if you want to use a different toolchain.
17+
"PATH": "${env:HOME}/.local/share/alire/toolchains/gnat_native_13.2.2_a27fd794/bin:${env:HOME}/.local/share/alire/toolchains/gprbuild_22.0.1_24dfc1b5/bin:${env:PATH}",
18+
19+
// Append the path to the directory containing print_utils.gpr project file dependency to
20+
// the GPR_PROJECT_PATH environment variable
21+
"GPR_PROJECT_PATH": "./imported:${env:GPR_PROJECT_PATH}:"
22+
},
23+
24+
// Set a workspace-specific environment for Windows
25+
"terminal.integrated.env.windows": {
26+
// Set MAIN_NUMBER scenario variable to MAIN_2 directly from the environment
27+
"MAIN_NUMBER": "MAIN_2",
28+
29+
// Optionally, you can append the Ada toolchain of your choice to the PATH environment variable
30+
// if you want to use a different toolchain.
31+
// "PATH": "<PATH_TO_TOOLCHAIN>;${env:PATH}",
32+
33+
// Append the path to the directory containing print_utils.gpr project file dependency to
34+
// the GPR_PROJECT_PATH environment variable
35+
"GPR_PROJECT_PATH": ".\\imported;${env:GPR_PROJECT_PATH}:"
36+
}
37+
}
38+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
with "print_utils.gpr";
2+
3+
project Default is
4+
5+
for Source_Dirs use ("src");
6+
for Object_Dir use "obj";
7+
type MAIN_NUMBER_Type is
8+
("MAIN_1", "MAIN_2");
9+
MAIN_NUMBER : MAIN_NUMBER_Type := external ("MAIN_NUMBER", "MAIN_1");
10+
11+
case MAIN_NUMBER is
12+
when "MAIN_2" =>
13+
for Main use ("main_2.adb");
14+
15+
when "MAIN_1" =>
16+
for Main use ("main_1.adb");
17+
end case;
18+
19+
-- Use the same executable name for main source files
20+
package Builder is
21+
for Executable ("main_1.adb") use "main";
22+
for Executable ("main_2.adb") use "main";
23+
end Builder;
24+
25+
for Create_Missing_Dirs use "True";
26+
27+
end Default;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
with Ada.Text_IO;
2+
3+
procedure Print (S : String) is
4+
begin
5+
Ada.Text_IO.Put_Line (S);
6+
end Print;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project Print_Utils is
2+
end Print_Utils;

0 commit comments

Comments
 (0)