web analytics
How to create a new component

Short story

The Ada Crate / Lib / App _Template is on AdaForge GitLab

Direct to section:

Direct to 👩🏻‍💻

AdaForge Project Templates

« Stainless Steel Ada code will never Rust » ™ 🤣

🧩 Ada Pkg Units

📦 Sources Repo

💾 Distrib Repo


Objectives

Use cases

  1. 🧩 Structure or integrate a new Ada Lib Package in your code
  2. 📦 Use or publish new Crates / Lib Components
    • Building the Binary exe or library file
  3. 💾 Packaging for download and install
    • Linux APT or RPM
    • FreeBSD Pkg
    • MacOS DMG
    • Windows App Installer

Challenges

✏️ Names-spaces

Define & Structure the 3 name-spaces without name clashing

⚠️ Constraints

  • 🧩 Ada Pkg Units : Give some functional meaning
  • 📦 Sources Repo : Diffenciate 3 (or more) proposals/authors for a same functional domain, say XML, AES, advanced String lib, ...
  • 💾 Distrib Repo : Must be unique all-round on some environnements

Design

📚 3 catalogues with organized levels of hierarchy

🧩 Ada Unit

  • Ada Unit-Name of your code -- or libraries to use
    • Owner + 2 Levels of hierarchy + your_Unit_name

📦 Sources Repo

  • Crate / Lib Component name
    • 2 Levels of hierarchy + your_Unit_name + your_Crate short_name
    • Binary exe or library file short name

💾 Distrib Repo

  • Distrib package name
    • 1 Level of hierarchy ; your Pkg short name must be unique through all packages

🎯 Benchmarking

🧩 Ada Pkg Units

📦 Libs

💾 Distrib


In practice

Base Hierarchy

Owner - Pkg1 - Pkg2 - Component

Note:

  • Owner = Copyright owner
  • Component = generic-functional domain name

🧩 Ada Pkg Units

  • Owner.Pkg1.Pkg2.Component (API Unit)
  • Owner.Pkg1.Pkg2.Component.*
  • Owner.Pkg1.Pkg2.Component_* (for high-level dependencies)
  • Owner _ Pkg1 _ Pkg2 _ Component _ * (main public programs)

📦 Crate / Lib names

Crates / Libs AdaForge's catalogue

  • AdaForge Source Repo (GitLab: 3 sub-groups + project) =
    • AdaForge / pkg1 / pkg2 / component / ownepkg1pkg2comp
    • _Authors / owner
    • _Authors / owner / pkg1
    • _Authors / owner / pkg1 / pkg2

Crate / Lib short name

= ownepkg1pkg2comp

Note: How to hash the short name :

$ gnatkr owner_pkg1_pkg2_component  16
> ownepkg1pkg2comp

. .

ALIRE

  • Crate name in ./ alire .toml file :
    • name = "OwnePkg1Pkg2Comp"
  • Test ALIRE file * ./tests/ alire .toml
    • name = "OwnePkg1Pkg2Comp_Tests"

GPR

  • GPR main build file = : ./ ownepkg1pkg2comp .gpr
  • other GPR build files in ./bld :
    • ./bld/ownepkg1pkg2comp .gpr
    • ./bld/ownepkg1pkg2comp-lib .gpr
    • ./bld/ownepkg1pkg2comp-lib-tests .gpr
    • ./bld/ownepkg1pkg2comp-main .gpr

💾 Distrib Catalogue

Project artefacts are stored in

  • pkg1 / ownepkg1pkg2comp

Project Structure

Recommanded dir-folder name =

component short name =

ownepkg1pkg2comp

📐« Configuration as Code » ™

Base principles :

  1. Follow as much as possible Alire default configuration
  2. All sources under ./src
  3. All tests materils as a sub-project under ./tests
  4. All build configuration and scripts under ./bld
  5. All build artefacts under ./build
  6. Head build files are in ./.
    • alire.toml
    • Makefile
    • owner_pkg1_pkg2_component.gpr

🏠« User feels at home » ™

Base principles :

  1. All UseCases/BDD feature descriptions under ./features
  2. All install, usage or users doc goes under ./doc
  3. All design and implementation docs goes under ./design
  4. All Application resource files (not having merging capabilities) under ./resources
  5. All licenses files in ./LICENSES
  6. Use as possible MarkDown GLFM GitLab flavor syntax for text files
    • README.md
    • NOTICE.md
    • TODO.md
    • ROADMAP.md

📣 « Show what is public » ™

Base principles :

  1. All API files in ./src/lib
  2. All MAIN source files in ./src/main
  3. All TEST main-programs source files and data in ./tests/main ./tests/data

🗄️ « Hide what is private » ™

Base principles :

  1. All other Lib files are under ./src/lib/sub/**
  2. All other MAIN sub-units source files under ./src/main/sub/**
  3. All other TEST sub-units source files are under ./tests/main/sub/**

Custom Alire defaults

  • Main project GPR build file
  • We group all build definitions and scripts under ./bld (no Alire ./config)

So we have to set:

./alire.toml

name = "ownepkg1pkg2comp"

project-files = ["bld/ownepkg1pkg2comp-lib.gpr"]

[build-profiles]
ownepkg1pkg2comp = "Development"

[configuration]
auto_gpr_with = false
output_dir = "bld"

./tests/alire.toml

name = "ownepkg1pkg2comp_tests"

project-files = ["../bld/ownepkg1pkg2comp-lib-tests.gpr"]

[build-profiles]
ownepkg1pkg2comp_tests = "Development"
ownepkg1pkg2comp = "Validation"
sterndevttestunit = "Release"

[configuration]
auto_gpr_with = false
output_dir = "../bld"

[[depends-on]]
ownepkg1pkg2comp = "*"
sterndevttestunit = ">=3.9.0"

[[pins]]
ownepkg1pkg2comp = { path='..' }


Main GPR file

./ownepkg1pkg2comp.gpr

aggregate project ownepkg1pkg2comp is

-- Dependencies
   for Project_Path use (
         --:TODO "../name_of_copyright_owner/bld",
         --:TODO "../name_of_copyright_owner_pkg1/bld",
         --:TODO "../name_of_copyright_owner_pkg1_pkg2/bld",
         "../sterdevttestunit/bld",                                      -- Unit Test framework
         "../other_pkgx_pkgy_somelibdependency",      -- some lib dependency
         "../another_pkgx_pkgy_otherlibdependency",   -- some lib dependency
         "bld");

-- Parts to be built
   for Project_Files use (
         "bld/ownepkg1pkg2comp-lib.gpr",
         "bld/ownepkg1pkg2comp-lib-tests.gpr",
         "bld/ownepkg1pkg2comp-main.gpr",
         "bld/ownepkg1pkg2comp-main-tests.gpr");
  
end ownepkg1pkg2comp;

EEC GDPR compliant