Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: templates_parser for file initializations #1890

Merged
merged 7 commits into from
Mar 23, 2025

Conversation

mosteo
Copy link
Member

@mosteo mosteo commented Mar 11, 2025

The idea is to use Templates_Parser to generate files (currently only during alr init), which enhances maintenance, and opens the door to user templates (not in this PR, this only deals with our own hardcoded initializations).

This is achieved this way:

  • Files under templates replicate the trees we want to generate. These can contain TP variables/filters/etc.
  • A new support/embedder/embedder.sh script generates embedded resources under src/templates. It relies on awsres from AWS, but since this is done independently of Alire's build, it doesn't introduce new dependencies (in particular I didn't want to depend on AWS from alr).
    • There's a hash-based check to avoid regenerating resources, so normal builds of Alire shouldn't need AWS nor regenerate anything. Contributors can continue building alr with the same simplicity.
  • Alire.Templates provides a couple of wrappers over TP to use the embedded resources.
  • Alire.Templates.Builtins constants define the structure of folders we want to generate.

User templates could be had e.g. via alr init --template=<url> with little extra effort now that the basis is in place.

This makes the only new dependency to be templates_parser, and it doesn't require special compilation as I forked their repo to have the preconfiguration done, so gprbuild is still enough to build.

Edit: I initially thought xmlada was also required but it can be disabled in templates_parser.

Fixes #11.
Fixes #1896.

commit 72eff5c
Author: Alejandro R. Mosteo <amosteo@unizar.es>
Date:   Mon Mar 10 23:55:41 2025 +0100

    Self-review

commit 4174977
Author: Alejandro R. Mosteo <amosteo@unizar.es>
Date:   Mon Mar 10 23:21:52 2025 +0100

    Downgrade templates parser to avoid GNAT>=11

commit 9cece27
Author: Alejandro R. Mosteo <amosteo@unizar.es>
Date:   Mon Mar 10 23:17:50 2025 +0100

    Hash to avoid arbitrary regeneration

commit bd24060
Author: Alejandro R. Mosteo <amosteo@unizar.es>
Date:   Mon Mar 10 23:06:53 2025 +0100

    Tests passing

commit b37e33e
Author: Alejandro R. Mosteo <amosteo@unizar.es>
Date:   Mon Mar 10 14:45:27 2025 +0100

    update init to use templates

commit ffd90a0
Author: Alejandro R. Mosteo <amosteo@unizar.es>
Date:   Sun Mar 9 23:15:35 2025 +0100

    Proof of concept working

commit 9551420
Author: Alejandro R. Mosteo <amosteo@unizar.es>
Date:   Sun Mar 9 22:46:06 2025 +0100

    Templated file trees

commit 557e67e
Author: Alejandro R. Mosteo <amosteo@unizar.es>
Date:   Sun Mar 9 21:15:56 2025 +0100

    Remove custom experiments in main

commit f0c573d
Author: Alejandro R. Mosteo <amosteo@unizar.es>
Date:   Sun Mar 9 21:12:23 2025 +0100

    Write file with templating

commit 947d1db
Author: Alejandro R. Mosteo <amosteo@unizar.es>
Date:   Sun Mar 9 20:12:23 2025 +0100

    Embedded resource writing (no templating)

commit 5e533d5
Author: Alejandro R. Mosteo <amosteo@unizar.es>
Date:   Sun Mar 9 11:30:06 2025 +0100

    Template registration

commit fc19c09
Author: Alejandro R. Mosteo <amosteo@unizar.es>
Date:   Sun Mar 9 10:55:06 2025 +0100

    embedder script

commit 90d0778
Author: Alejandro R. Mosteo <amosteo@unizar.es>
Date:   Sun Mar 9 10:32:14 2025 +0100

    Sample binary crate

commit ce9ef50
Author: Alejandro R. Mosteo <amosteo@unizar.es>
Date:   Sun Nov 10 19:00:53 2024 +0100

    wip: on track to 1st prototype

commit 1e52e58
Author: Alejandro R. Mosteo <amosteo@unizar.es>
Date:   Sun Oct 27 20:05:57 2024 +0100

    WIP: experimenting with embedded resources
@mosteo mosteo force-pushed the feat/templates branch 2 times, most recently from de4c522 to 419790e Compare March 14, 2025 19:01
@mosteo mosteo marked this pull request as ready for review March 14, 2025 19:37
@mosteo mosteo requested a review from Fabien-Chouteau March 14, 2025 19:37
Copy link
Member

@Fabien-Chouteau Fabien-Chouteau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about the use of ARE for this use case. We have another way to handle resources for native applications: https://github.com/alire-project/resources

@@ -69,3 +69,6 @@
[submodule "deps/yeison"]
path = deps/yeison
url = https://github.com/mosteo/yeison
[submodule "deps/templates-parser"]
path = deps/templates-parser
url = https://github.com/alire-project/templates-parser
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the official repo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the official repo is missing a project file which is generated with make, and I don't want to introduce that dependency in the build of alr from scratch without alr... I like depending only on gprbuild for as long as possible.

An alternative to templates parser could be JinTP which I just became aware of the other day. It looks more like the liquid templates in jekyll, and seems to be quite light. I don't know if you have experience with it, I don't know how mature it is in real use.

@mosteo
Copy link
Member Author

mosteo commented Mar 20, 2025

I am not sure about the use of ARE for this use case. We have another way to handle resources for native applications: https://github.com/alire-project/resources

This is to make alr self-contained, as we talked about. It's true that we could clone resources like we clone the community index, but that seems a larger departure from the current situation I don't feel comfortable moving away (yet?)

Or if for example we started using templates for the long help descriptions, it would also be nice not to depend on external files.

@mosteo mosteo force-pushed the feat/templates branch 2 times, most recently from 1054113 to 0d7d688 Compare March 23, 2025 13:06
@mosteo mosteo merged commit ea80aa4 into alire-project:master Mar 23, 2025
33 checks passed
@mosteo mosteo deleted the feat/templates branch March 24, 2025 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace example test with a more useful one Use Templates_Parser for cleaner file generation
2 participants