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

ogma-cli: Allow customizing the F' component template. Refs #185. #188

Merged

Conversation

ivanperez-keera
Copy link
Member

@ivanperez-keera ivanperez-keera commented Dec 6, 2024

Adjust ogma-cli and ogma-core to allow customizing the F' monitoring component by using custom-provided templates, as prescribed in the solution proposed for #185 .

…. Refs nasa#185.

The F' backend uses a fixed template to generate the F' component. That
template does not fit all use cases, so we are finding users heavily
modifying the output (which is hard to keep up with when there are
changes), and or not using ogma altogether for that reason.

This commit modifies the ogma-core fprime command to use mustache to
generate the F' monitoring application via a template and variable
expansion. We adapt the template to also use those variables, and we
modify the cabal file to include the new files as data files that are
copied over during installation.
…ration. Refs nasa#185.

The F' backend uses a fixed template to generate the F' component. That
template does not fit all use cases, so we are finding users heavily
modifying the output (which is hard to keep up with when there are
changes), and or not using ogma altogether for that reason.

A recent commit introduced the ability to use mustache to expand
variables in a template. This commit modifies the fprime command to
accept an additional argument that points to a user-provided directory
with a custom template.
…irectory to F' app command. Refs nasa#185.

The F' backend uses a fixed template to generate the F' component. That
template does not fit all use cases, so we are finding users heavily
modifying the output (which is hard to keep up with when there are
changes), and or not using ogma altogether for that reason.

A recent commit introduced into ogma-core the ability to use a custom
provided template and expand variables using mustache.

This commit exposes that new parameter to the user in the CLI.
…on. Refs nasa#185.

The F' backend uses a fixed template to generate the F' component. That
template does not fit all use cases, so we are finding users heavily
modifying the output (which is hard to keep up with when there are
changes), and or not using ogma altogether for that reason.

Prior commits have expanded the command to allow for customization of
the template using a user-provided directory and expanding variables in
the template using mustache.

This commit documents the new feature in the README.
The functions copyDirectoryRecursive and copyFile' are no longer needed,
now that all parts of ogma-core use the template expansion system.

This commit deprecates both functions so that they can be removed in a
future version of ogma-extra.
@ivanperez-keera
Copy link
Member Author

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 generates the F' component using the default template and using a copy and the default template and checks that both are the same. It then adds a file to the copy of the template and checks that the file is copied to the target directory when the custom template is used, after which it prints the message "Success". Compiling the produced component completes successfully:
      --- fprime-handlers
      handlerMyProperty
      
      --- fprime-variable-dbs
      ("pullup", "bool")
      ("input", "float")
      
      --- fprime-variables
      variables
      
      --- Monitor.hs
      import           Copilot.Compile.C99
      import           Copilot.Language      hiding (prop)
      import qualified Copilot.Library.PTLTL as PTLTL
      import           Language.Copilot      (reify)
      import           Prelude               hiding (not, (/=))
      
      input :: Stream Float
      input = extern "input" Nothing
      
      myProperty :: Stream Bool
      myProperty = PTLTL.alwaysBeen (input /= 30.0)
      
      spec :: Spec
      spec = do
        trigger "handlerMyProperty" (not myProperty) []
      
      main :: IO ()
      main = reify spec >>= compile "copilot"
      
      --- Dockerfile
      FROM ubuntu:trusty
      
      ENV DEBIAN_FRONTEND=noninteractive
      
      RUN apt-get update
      
      RUN apt-get install --yes software-properties-common
      RUN add-apt-repository ppa:hvr/ghc
      RUN apt-get update
      
      RUN apt-get install --yes ghc-8.6.5 cabal-install-2.4
      RUN apt-get install --yes libz-dev
      
      ENV PATH=/opt/ghc/8.6.5/bin:/opt/cabal/2.4/bin:$PWD/.cabal-sandbox/bin:$PATH
      
      RUN cabal update
      RUN cabal v1-sandbox init
      RUN cabal v1-install alex happy
      RUN apt-get install --yes git
      
      ADD fprime-variables    /tmp/fprime-variables
      ADD fprime-handlers     /tmp/fprime-handlers
      ADD fprime-variable-dbs /tmp/fprime-variable-dbs
      ADD Monitor.hs          /tmp/Monitor.hs
      
      CMD git clone $REPO                                                              && \
          cd $NAME                                                                     && \
          git checkout $COMMIT                                                         && \
          cd ..                                                                        && \
          cp -r $NAME/ogma-core/templates/fprime custom-template-fprime                && \
          cabal v1-sandbox init                                                        && \
          cabal v1-install copilot $NAME/$PAT**/                                          \
            --constraint="aeson>=2.0.3.0"                                                 \
            --constraint="copilot>=4.1"                                                   \
            --constraint="copilot-core>=4.1"                                              \
            --constraint="copilot-language>=4.1"                                          \
            --constraint="copilot-theorem>=4.1"                                           \
            --constraint="copilot-c99>=4.1"                                               \
            --constraint="copilot-interpreter>=4.1"                                       \
            --constraint="copilot-prettyprinter>=4.1"                                  && \
          ./.cabal-sandbox/bin/ogma fprime --app-target-dir original                      \
                                           --variable-file /tmp/fprime-variables          \
                                           --handlers-file /tmp/fprime-handlers           \
                                           --variable-db /tmp/fprime-variable-dbs      && \
          ./.cabal-sandbox/bin/ogma fprime --app-target-dir new                           \
                                           --app-template-dir custom-template-fprime      \
                                           --variable-file /tmp/fprime-variables          \
                                           --handlers-file /tmp/fprime-handlers           \
                                           --variable-db /tmp/fprime-variable-dbs      && \
          diff -rq original new                                                        && \
          rm -rf new/*                                                                 && \
          echo "Success" >> custom-template-fprime/test                                && \
          ./.cabal-sandbox/bin/ogma fprime --app-target-dir new                           \
                                           --app-template-dir custom-template-fprime      \
                                           --variable-file /tmp/fprime-variables          \
                                           --handlers-file /tmp/fprime-handlers           \
                                           --variable-db /tmp/fprime-variable-dbs      && \
          cabal v1-exec -- runhaskell /tmp/Monitor.hs                                  && \
          mv copilot* new/                                                             && \
          cat new/test
      
      Command (substitute variables based on new path after merge):
      $ docker run -v $PWD/fprime_demo/:/new -e "REPO=https://github.com/ivanperez-keera/ogma" -e "NAME=ogma" -e "PAT=ogma"  -e "COMMIT=56e24677f821ca31dc7af63a5d596ad4d55dca31" -it ogma-verify-185
      $ cd fprime_demo
      $ docker build -t ogma-verify-185-fprime -f Dockerfile .
      
  • Implementation is documented. Details:
    The new code has comments.
  • Change history is clear.
  • Commit messages are clear.
  • Changelogs are updated.
  • Examples are updated. Details:
    No updates needed.
  • Required version bumps are evaluated. Details:
    No bump needed. New feature is backwards compatible.

@ivanperez-keera ivanperez-keera merged commit c4060bf into nasa:develop Dec 6, 2024
2 checks passed
@ivanperez-keera ivanperez-keera deleted the develop-fprime-templates branch December 6, 2024 17:44
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