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

Make structured data available to FPrime template. Refs #246. #247

Merged
merged 5 commits into from
Feb 8, 2025

Conversation

ivanperez-keera
Copy link
Member

Modify FPrime backend to make more structured data directly available to the FPrime template, as prescribed in the solution proposed for #246.

…sa#246.

The current FPrime backend is overly specific, complex and composes data
manually. For example, it assumes a specific structure for the message
handlers. It also extracts data from data structures, manually converts
it to strings, and then packs it into a JSON structure. This limits
user's abilities to adjust the template to fit their needs, since most
of the data is given as fixed strings, rather than letting users access
each variable declaration and, within them, each type and name
individually.

This commit simplifies the FPrime backend by packing all the raw data
that may be relevant for the FPrime application in a data structure,
converting it to JSON, and then passing it to the template expansion
system.
…Refs nasa#246.

The current FPrime backend is overly specific, complex and composes data
manually. For example, it assumes a specific structure for the message
handlers. It also extracts data from data structures, manually converts
it to strings, and then packs it into a JSON structure. This limits
user's abilities to adjust the template to fit their needs, since most
of the data is given as fixed strings, rather than letting users access
each variable declaration and, within them, each type and name
individually.

A prior commit has modified the FPrime backend to use provide more raw
data to the FPrime template, making it more versatile.

This commit updates the template to make use of such data, by moving to
the template some of the constructs that the prior FPrime backend was
providing as code snippets in strings. The template is modified such
that it generates the exact same final FPrime application as before.
…#246.

The current FPrime backend is overly specific, complex and composes data
manually. For example, it assumes a specific structure for the message
handlers. It also extracts data from data structures, manually converts
it to strings, and then packs it into a JSON structure. This limits
user's abilities to adjust the template to fit their needs, since most
of the data is given as fixed strings, rather than letting users access
each variable declaration and, within them, each type and name
individually.

Prior commits have modified the FPrime backend to provide more raw data
to the FPrime template, and have adjusted the default template
accordingly.

This commit updates the README to document the new variables available
to the template.
@ivanperez-keera
Copy link
Member Author

ivanperez-keera commented Feb 8, 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 checks that generating an FPrime application with and without the feature proposed renders the same result, after which it prints the message "Success". We manually adjust a small difference using awk and sed, because it's unimportant and it would complicate the F' backend unnecessarily. It requires an additional BASE_COMMIT variable pointing to a commit prior to merging this feature.
      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
      
      ADD document.json      /tmp/document.json
      ADD json-format.cfg    /tmp/json-format.cfg
      ADD fprime-variable-db /tmp/fprime-variable-db
      ADD fprime-handlers    /tmp/fprime-handlers
      
      SHELL ["/bin/bash", "-c"]
      CMD git clone $REPO \
          && cd $NAME \
          && git checkout $BASE_COMMIT \
          && cabal install ogma-cli:ogma \
          && ogma fprime --app-target-dir original --handlers-file /tmp/fprime-handlers --input-file /tmp/document.json -f /tmp/json-format.cfg -p literal --variable-db /tmp/fprime-variable-db \
          && git checkout $COMMIT \
          && cabal install --overwrite-policy=always ogma-cli:ogma \
          && ogma fprime --app-target-dir updated  --handlers-file /tmp/fprime-handlers --input-file /tmp/document.json -f /tmp/json-format.cfg -p literal --variable-db /tmp/fprime-variable-db \
          && awk '/^.*event HANDLERMYPROPERTY/{printf "%s",$$0;next}1' original/Copilot.fpp | sed -e 's/\(event HANDLERMYPROPERTY.*(\) *\().*\)/\1\2/g' > original/Copilot.fpp.adjusted \
          && mv original/Copilot.fpp.adjusted original/Copilot.fpp \
          && diff -rq original updated \
          && echo "Success"
      Command (substitute variables based on new path after merge):
      $ docker run -e "REPO=https://github.com/ivanperez-keera/ogma" -e "NAME=ogma" -e "BASE_COMMIT=eae76d0c573042ca7252629535524af82cad700f" -e "COMMIT=947799cbdfe4fcd9360d967ee511066fc791ec28" -it ogma-verify-246
      
  • Implementation is documented. Details:
    All new top-level definitions are documented. The README is updated to explain the new variables available in the FPrime template.
  • Change history is clear.
  • Commit messages are clear.
  • Changelogs are updated.
  • Examples are updated. Details:
    No updates 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 does not affect the API or user interface so long as they use the default template, but it does affect custom templates that may be used by users, which need to be adapted to use the new variable names.

@ivanperez-keera ivanperez-keera merged commit f1da8ca into nasa:develop Feb 8, 2025
2 checks passed
@ivanperez-keera ivanperez-keera deleted the develop-fprime-logic branch February 8, 2025 03: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.

1 participant