Skip to content

Commit

Permalink
Merge branch 'master' into feat/improve-uri-recognition
Browse files Browse the repository at this point in the history
  • Loading branch information
Seb-MCaw authored Oct 8, 2024
2 parents 50a30e1 + adae95b commit 14567e5
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 17 deletions.
24 changes: 10 additions & 14 deletions doc/toolchains.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

Toolchains are comprised by a GNAT compiler and a `gprbuild` project file
processor. Alire strives to simplify the availability of GNAT releases, which
are packaged to be retrieved and used with ease.
are packaged to be retrieved and used with ease.

The user can now select a preferred compiler via `alr toolchain --select`.
Releases may still override this selection (for example to use a
cross-compiler).
cross-compiler). Several compilers can be installed simultaneously, but only
the last one `--select`ed will be used by default. The rest will be used in
preference to uninstalled compilers, if the default one does not match some
crate's dependencies.

There are two kinds of dependencies on GNAT compilers: generic dependencies on
the `gnat` crate, which apply to every compiler, and dependencies on a precise
Expand All @@ -27,35 +30,28 @@ They will also be shown by the selection assistant,
Running `alr toolchain` without arguments will show the installed compilers and
the preferred compiler, if any.

## Manual compiler installation

Besides selecting a default compiler with `alr toolchain --select`, the user
may install other compilers via `alr toolchain --install`. Installed but
unselected compilers will not be used, though, unless a crate explicitly
requests them via dependencies.

Compilers can be removed with `alr toolchain --uninstall`.

## Automatic compiler installation

If a crate requires a target-specific compiler via its dependencies, `alr` will
attempt to use first a matching installed compiler. Otherwise, a matching
compiler will be automatically downloaded.

Generic dependencies on `gnat` will never cause a compiler download.

## Automatic compiler selection by Alire

When a build is launched, or `alr printenv` is run to obtain a build environment,
`alr` will use the available compilers as follows:

1. Any target-specific compiler needed due to dependencies will be
1. A target-specific compiler needed due to dependencies will be
selected.
1. Otherwise, if the user has defined a preferred compiler, it will be
selected.
1. If no preferred compiler has been defined, Alire will rely on the existing
user environment.

Within these conditions, a compiler already downloaded will be preferred.
Downloading a new compiler will be attempted only if no matching compiler is
already available.

## Specifying dependencies on GNAT compilers for crate publishing

From the point of view of a user preparing a release for publication, these
Expand Down
6 changes: 4 additions & 2 deletions src/alire/alire-roots.adb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ package body Alire.Roots is
-- Will regenerate on demand only those changed. For shared
-- dependencies, will also generate any missing configs not generated
-- during sync, such as for linked releases and the root release.

-- Set the environment to be used during build

This.Export_Build_Environment;
end Build_Prepare;

-----------
Expand Down Expand Up @@ -279,8 +283,6 @@ package body Alire.Roots is
return True;
end if;

This.Export_Build_Environment;

This.Traverse (Build_Single_Release'Access);

return True;
Expand Down
7 changes: 6 additions & 1 deletion testsuite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ You also must have [GNAT](https://www.gnu.org/software/gnat) and
[GPRBuild](https://github.com/AdaCore/gprbuild) in your `PATH`. You can install
these with, for example:
```sh
alr toolchain --install --install-dir=<dir> gnat_native=<version_x> gprbuild=<version_y>
alr install gnat_native=<version_x> gprbuild=<version_y> --prefix=<dir>
```
and add `<dir>/bin` to your `PATH`, or
```sh
cd <dir>
alr get gnat_native=<version_x> gprbuild=<version_y>
```
and add `<dir>/gnat_native_<version_x>_(...)/bin` and
`<dir>/gprbuild_<version_y>_(...)/bin` to your `PATH`.
Expand Down
51 changes: 51 additions & 0 deletions testsuite/tests/action/environment/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
Verify the proper environment is set up for the action. We create an executable
within a crate that will be run during pre-build. For it to be found, the
proper path must be set in the crate environment. This should work for a
regular build (as it did before) and for a manually triggered action (the bug
being fixed).
"""

import os
from shutil import which
from drivers.alr import run_alr, init_local_crate, add_action, alr_manifest
from drivers.asserts import assert_eq
from drivers.helpers import content_of, on_windows

tool_name = "myalrtestingtool"

# Tool crate to be used during build
init_local_crate(tool_name, enter=False)

# Ensure the tool is not found in path by pure chance!
assert not which(tool_name)

# Build the tool
run_alr("-C", tool_name, "build")

# Create the new crate that uses this tool during pre-build step
init_local_crate()

# Edit its manifest to require it during pre-build
add_action("pre-build", [tool_name + (".exe" if on_windows() else "")])

# Build should fail because the tool is not found in the path
run_alr("build", complain_on_error=False)

# Likewise, stand-alone running of the action should fail
run_alr("action", "pre-build", complain_on_error=False)

# Add the tool location to the crate environment
with open(alr_manifest(), "at") as f:
f.write(f"""
[environment]
PATH.prepend = "../{tool_name}/bin"
""")

# assert_eq(content_of(alr_manifest()), "XXX")

# Now both build and action should succeed
run_alr("build")
run_alr("action", "pre-build")

print("SUCCESS")
4 changes: 4 additions & 0 deletions testsuite/tests/action/environment/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: python-script
build_mode: both
indexes:
compiler_only_index: {}

0 comments on commit 14567e5

Please sign in to comment.