name = "libadalang2xml"
description = "Generates XML for Ada source, using libadalang."
long-description = """
Libadalang2XML is a tool to extract syntatic aspects of Ada source code into XML.

The Ada source is initially read using [Libadalang](https://github.com/AdaCore/libadalang). The resulting tree is then traversed, and its structure output in an XML form.

The [document type definition](https://en.wikipedia.org/wiki/Document_type_definition) isn't explicit; it's simply derived from the tree elements created by Libadalang. Note that Libadalang includes much more semantic information than the surface structure generated by this tool, but nevertheless there's enough there to --- for example --- create a scriptable body for a package spec.

## macOS ##

For reasons explained [here](https://forward-in-code.blogspot.com/2023/03/libadalang-alire-and-macos.html), the tool can't be built on macOS using Alire's `gnat_native` compiler; you need to have a full compiler suite on your `PATH`, like that obtainable for [GCC 12.2.0 (x86 64)](https://github.com/simonjwright/distributing-gcc/releases/tag/gcc-12.2.0-x86_64) or [GCC 12.2.0 (aarch64)](https://github.com/simonjwright/distributing-gcc/releases/tag/gcc-12.2.0-aarch64). Having set that up, `alr build` will built the tool.

## Example ##

As an example of the output, this code
``` ada
package Demo is
   procedure Square (X : in out Integer);
end Demo;
```
generates
``` xml
<CompilationUnit>
  <AdaNodeList/>
  <LibraryItem>
    <PrivateAbsent/>
    <PackageDecl>
      <DefiningName>
        <Id>Demo</Id>
      </DefiningName>
      <PublicPart>
        <AdaNodeList>
          <SubpDecl>
            <OverridingUnspecified/>
            <SubpSpec>
              <SubpKindProcedure>procedure</SubpKindProcedure>
              <DefiningName>
                <Id>Square</Id>
              </DefiningName>
              <Params>
                <ParamSpecList>
                  <ParamSpec>
                    <DefiningNameList>
                      <DefiningName>
                        <Id>X</Id>
                      </DefiningName>
                    </DefiningNameList>
                    <AliasedAbsent/>
                    <ModeInOut>in out</ModeInOut>
                    <SubtypeIndication>
                      <NotNullAbsent/>
                      <Id>Integer</Id>
                    </SubtypeIndication>
                  </ParamSpec>
                </ParamSpecList>
              </Params>
            </SubpSpec>
          </SubpDecl>
        </AdaNodeList>
      </PublicPart>
      <EndName>
        <Id>Demo</Id>
      </EndName>
    </PackageDecl>
  </LibraryItem>
  <PragmaNodeList/>
</CompilationUnit>
```
"""
version = "1.0.0"

authors = ["Simon Wright"]
maintainers = ["Simon Wright <simon@pushface.org>"]
maintainers-logins = ["simonjwright"]
licenses = "GPL-3.0-or-later"
website = "https://github.com/simonjwright/libadalang2xml"
tags = ["ada", "xml"]

executables = ["libadalang2xml"]

[environment.'case(os)'.macos]
# This code was originally developed on macOS, which is why the CFLAGS
# setting specifies where the includes for external libraries used by
# GNATCOLL are to be found (Homebrew places items it manages in
# /usr/local or /opt/homebrew on Intel or Apple silicon respectively).
CFLAGS.set = "-I/usr/local/include -I/opt/homebrew/include"

# Similarly for libraries; note that Libadalang and Langkit_Support
# don't (yet) reference this variable.
LDFLAGS.set = "-L/usr/local/lib -L/opt/homebrew/lib"

# Libadalang and Langkit_Support attempt to build stand-alone
# libraries even for static builds; this Will Not Work, see
# https://github.com/AdaCore/gprbuild/issues/97.
LIBRARY_TYPE.set = "relocatable"

[build-switches]
development.contracts = "yes"
"*".ada_version = "ada2022"

[[depends-on]]

[depends-on.'case(os)'.macos]
# The gnat_native compilers don't provide libgmp, and there's no
# current way of making it visible to the Libadalang/Langkit_Support
# relocatable library builds.
gnat_external = ">=12.2.0"

[depends-on.'case(os)'.'...']
libadalang = "^23.0.0"


[origin]
commit = "6f93873ff4bd379d5c6ae9d8dcdb36d7271c3f25"
url = "git+https://github.com/simonjwright/libadalang2xml.git"

