Making AUnit available to gprbuild

tldr; I have installed AUnit per the docs, but I cannot make GPRBuild “see it”

I like doing “test-driven learning” when learning a new language, and so I thought I would figure out how to write the most basic setup for code covered by unit tests.

I followed the AUnit Cookbook on installation, which basically said to run make install, which would install aunit where gprbuild was installed (unless overridden). This seems to have worked fine:

❯ make --trace install
Makefile:61: update target 'install-clean' due to: install-clean-legacy
gprinstall   -XAUNIT_BUILD_MODE=Install -XAUNIT_RUNTIME=full -XAUNIT_PLATFORM=native --uninstall --prefix=/opt/gprbuild-x86_64-linux-24.0.0-2 aunit
Uninstall project aunit
Makefile:65: update target 'install' due to: install-clean
gprinstall   -XAUNIT_BUILD_MODE=Install -XAUNIT_RUNTIME=full -XAUNIT_PLATFORM=native -p -f --prefix=/opt/gprbuild-x86_64-linux-24.0.0-2 \
        --no-build-var lib/gnat/aunit.gpr
Install project AUnit

❯ v /opt/gprbuild-x86_64-linux-24.0.0-2/lib/
total 4
drwxr-xr-x 2 oscko oscko 4096 mars  11 09:51 aunit

❯ which gprbuild
/opt/gprbuild-x86_64-linux-24.0.0-2/bin/gprbuild

All good so far. If I now build examples/simple_test in the aunit repository, I get an error about it not finding aunit:

❯ gprbuild -P harness.gpr
harness.gpr:1:06: imported project file "aunit" not found
gprbuild: "harness.gpr" processing failed

I thought that it would now find it by virtue of being in /opt/gprbuild-x86_64-linux-24.0.0-2/lib/? CoPilot also suggested adding the library to the path of GPR_PROJECT_PATH, but that had no effect:

export GPR_PROJECT_PATH=/opt/gprbuild-x86_64-linux-24.0.0-2/lib/aunit:$GPR_PROJECT_PATH

I tried reading a bit up on how shared libraries work, but that seemed to imply that the project file of whatever library that was to be shared should include “library project”, and grepping the aunit repo for that string showed 0 results, so I am not even sure if this is a shared library or not …

The only way I managed to compile the example was directly referencing the project file from the place it was included:

aunit/examples/simple_test on  master [!?]
✦ ❯ git diff
diff --git a/examples/simple_test/harness.gpr b/examples/simple_test/harness.gpr
index f445b8d..f0347bf 100644
--- a/examples/simple_test/harness.gpr
+++ b/examples/simple_test/harness.gpr
@@ -1,4 +1,10 @@
-with "aunit";
+-- DOES NOT WORK
+-- with "aunit";
+
+-- WORKS:
+--with "../../lib/gnat/aunit.gpr";
+with "/opt/gprbuild-x86_64-linux-24.0.0-2/share/gpr/aunit.gpr";

Hardcoding those paths is not a very scalable approach :slight_smile:

What am I supposed to do here to get GPRBuild to see aunit?

Gprbuild wants AUnit’s GPR file (aunit.gpr) which I’d expect to see in /opt/gprbuild-x86_64-linux-24.0.0-2/share/gpr/ (up one from the directory gprbuild is in, then down to share/gpr).

But then, outside Alire I like to build gcc & gprbuild together; could aunit.gpr have been installed with the compiler rather than with gprbuild?

If you run gprbuild with -vh or -vm (high or medium verbosity) it should tell you its gpr search path:

Checking configuration /private/var/folders/_q/fvnxz46903z9hjh38fz0lyhm0000gs/T/GPR.35059/GNAT-TEMP-000001.TMP
Setting the default project search directories
   Adding directory "/opt/gcc-15.0.1-2-aarch64/aarch64-darwin/share/gpr"
   Adding directory "/opt/gcc-15.0.1-2-aarch64/aarch64-darwin/lib/gnat"
   Adding directory "/opt/gcc-15.0.1-2-aarch64/share/gpr"
   Adding directory "/opt/gcc-15.0.1-2-aarch64/lib/gnat"
   Adding directory "/usr/aarch64-darwin/share/gpr"
   Adding directory "/usr/aarch64-darwin/lib/gnat"
   Adding directory "/usr/share/gpr"
   Adding directory "/usr/lib/gnat"

(only one of those actually exists!)

1 Like

That was it! Adjusting the install path for aunit when installing made it available.

Related question
Is it it possible to adjust the globally searched paths using some environment variable or some setting that GPRBuild will use? The suggested GPR_PROJECT_PATH did not seem to take effect, or it was perhaps used incorrectly.

Thanks!

Details

Showing the default project search directories

aunit/examples/simple_test on  master [!?]
✦ ❯ gprbuild -vm
GPRBUILD 24.0.0 (2024-08-01) (x86_64-pc-linux-gnu)
Copyright (C) 2004-2024, AdaCore
using project file harness.gpr
 33 lines: No errors
TMPDIR = "/tmp/GPR.49115"
gprconfig --batch -o /tmp/GPR.49115/GNAT-TEMP-000001.TMP --target=x86_64-linux --fallback-targets --config=ada,,,,
Checking configuration /tmp/GPR.49115/GNAT-TEMP-000001.TMP
Setting the default project search directories
   Adding directory "/opt/gnat-x86_64-linux-14.2.0-1/x86_64-linux/share/gpr"
   Adding directory "/opt/gnat-x86_64-linux-14.2.0-1/x86_64-linux/lib/gnat"
   Adding directory "/opt/gnat-x86_64-linux-14.2.0-1/share/gpr"
   Adding directory "/opt/gnat-x86_64-linux-14.2.0-1/lib/gnat"

This shows that the sub directories of the gprbuild install was not being searched.

Adjusting the install path for AUnit

 make install INSTALL=/opt/gnat-x86_64-linux-14.2.0-1

Now I could revert the change from using absolute directory paths to using global shared libraries, such as with "aunit";

✦ ❯ git diff
diff --git a/examples/simple_test/harness.gpr b/examples/simple_test/harness.gpr
index f445b8d..a12f6fd 100644
--- a/examples/simple_test/harness.gpr
+++ b/examples/simple_test/harness.gpr
@@ -1,4 +1,10 @@
-with "aunit";
+-- Requires Aunit to be globally available
+-- See https://forum.ada-lang.io/t/making-aunit-available-to-gprbuild/1879/2
+ with "aunit";
+-- If AUnit has not been made available, it will need to be included by path
+--with "../../lib/gnat/aunit.gpr";
+--with "/opt/gprbuild-x86_64-linux-24.0.0-2/share/gpr/aunit.gpr";
+
 with "tested_lib/testlib";

 project Harness is