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

Support passing additional template variables to the cFS backend. Refs #106. #236

Merged
merged 5 commits into from
Feb 4, 2025

Conversation

ivanperez-keera
Copy link
Member

Extend cfs command and the cFS backend to accept and use an optional JSON file containing additional variables to expand in the template, as prescribed in the solution proposed for #106.

@ivanperez-keera ivanperez-keera marked this pull request as ready for review February 4, 2025 03:56
…efs nasa#106.

The generated cFS application may need definitions that come from external
files, such as message IDs from other applications, or structs defined
elsewhere. Users may also want to customize additional aspects of the generated
application without having to modify the template, such as passing additional
variables to be expanded in the template.

This commit extends the cFS backend to expect an additional argument denoting a
JSON file with an object whose keys will be expanded as variables in the cFS
template.
…asa#106.

The generated cFS application may need definitions that come from external
files, such as message IDs from other applications, or structs defined
elsewhere. Users may also want to customize additional aspects of the generated
application without having to modify the template, such as passing additional
variables to be expanded in the template.

A prior commit has extended the cFS backend to expect an additional argument
filename containing a JSON object, whose keys are expanded as variables in the
cFS template.

This commit exposes the argument to the user in the command-line via an
optional CLI argument.
…asa#106.

The generated cFS application may need definitions that come from external
files, such as message IDs from other applications, or structs defined
elsewhere. Users may also want to customize additional aspects of the generated
application without having to modify the template, such as passing additional
variables to be expanded in the template.

Prior commit have extended the `cfs` command to accept an optional argument
with a filename containing a JSON object, whose keys are expanded as variables
in the cFS template.

This commit documents the new argument to the `cfs` command, and how variables
are expanded in cFS application templates.
@ivanperez-keera ivanperez-keera changed the title Support passing additional template variables to the cFS backend Support passing additional template variables to the cFS backend. Refs #106. Feb 4, 2025
@ivanperez-keera
Copy link
Member Author

ivanperez-keera commented Feb 4, 2025

Change Manager: Verified that:

  • Solution is implemented:
    • The code proposed compiles and passes all tests. Details:
    • The solution proposed produces the expected result. Details:
      The following dockerfile first checks that passing the additional extra variables files does not affect the result unless the variable is mentioned in the template, by comparing the result to a run without passing any extra vars. It later adds a file with a custom variable, and then passes an extra template variable using the new flag, after which it prints the message "Success":
      FROM ubuntu:focal
      
      ENV DEBIAN_FRONTEND=noninteractive
      RUN apt-get update
      
      RUN apt-get install --yes \
            curl g++ gcc git libgmp3-dev libz-dev make pkg-config
      
      RUN mkdir -p $HOME/.local/bin
      ENV PATH=$PATH:/root/.local/bin/
      
      RUN curl https://downloads.haskell.org/~ghcup/0.1.17.7/x86_64-linux-ghcup-0.1.17.7 -o $HOME/.local/bin/ghcup
      RUN chmod a+x $HOME/.local/bin/ghcup
      
      ENV PATH=$PATH:/root/.ghcup/bin/
      RUN ghcup install ghc 9.10
      RUN ghcup install cabal 3.12
      RUN ghcup set ghc 9.10.1
      RUN cabal update
      
      SHELL ["/bin/bash", "-c"]
      CMD git clone $REPO \
          && cd $NAME \
          && git checkout $COMMIT \
          && cabal install ogma-cli:ogma \
          && ogma cfs --variable-file ogma-cli/examples/cfs-variables --variable-db ogma-cli/examples/cfs-variable-db --app-target-dir original --handlers-file ogma-cli/examples/cfs-handlers \
          && cp -r ogma-core/templates/copilot-cfs custom \
          && find custom -iname '.gitignore' -delete \
          && echo '{ "message": "Success" }' >> template-vars \
          && ogma cfs --variable-file ogma-cli/examples/cfs-variables --variable-db ogma-cli/examples/cfs-variable-db --app-target-dir new --handlers-file ogma-cli/examples/cfs-handlers \
              --app-template-dir custom --template-vars template-vars \
          && diff -rq original new \
          && echo '{{message}}' >> custom/fsw/result \
          && rm -rf new \
          && ogma cfs --variable-file ogma-cli/examples/cfs-variables --variable-db ogma-cli/examples/cfs-variable-db --app-target-dir new --handlers-file ogma-cli/examples/cfs-handlers \
              --app-template-dir custom --template-vars template-vars \
          && cat new/fsw/result
      Command (substitute variables based on new path after merge):
      $ docker run -e "REPO=https://github.com/ivanperez-keera/ogma" -e "NAME=ogma" -e "COMMIT=08b63d220710f42bcea1e95c1087ae89fce4fad6" -it ogma-verify-106
      
  • Implementation is documented. Details:
    All new top-level definitions are documented. The README is updated to also document new arguments, and how they can be used in custom templates.
  • Change history is clear.
  • Commit messages are clear.
  • Changelogs are updated.
  • Examples are updated. Details:
    Updates not needed; change does not affect the examples.
  • Author is internal or has provided signed CLA.
  • Required version bumps are evaluated. Details:
    Bump needed; the change affects the API of ogma-core.

@ivanperez-keera ivanperez-keera merged commit 7f25259 into nasa:develop Feb 4, 2025
2 checks passed
@ivanperez-keera ivanperez-keera deleted the develop-cfs-extravars branch February 4, 2025 06:26
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.

1 participant