Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop-fprime-templates' into develop. Close #185.
**Description** The F' application generation backend uses a fixed template to generate the f' application. 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. Allowing users to pick their own F' template would make Ogma more versatile. **Type** - Feature: Enable customizing output produced. **Additional context** None. **Requester** - Ivan Perez. **Method to check presence of bug** Not applicable (not a bug). **Expected result** Ogma allows users to pick the custom F' application template they want to use instead of relying on the one provided by default. 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): ```sh $ docker run -v $PWD/fprime_demo/:/new -e "REPO=https://github.com/NASA/ogma" -e "NAME=ogma" -e "PAT=ogma" -e "COMMIT=<HASH>" -it ogma-verify-185 $ cd fprime_demo $ docker build -t ogma-verify-185-fprime -f Dockerfile . ``` **Solution implemented** Modify `ogma-core` to use variable expansion based on mustache to create the output files. Modify `ogma-core`'s template to use the variables used by the F' component generation module. Modify `ogma-core` to give users the ability to pick a template directory via an optional input argument. Modify `ogma-cli` to give users the ability to pick a template directory via an optional input argument (exposing the corresponding argument from `ogma-core`). Modify `README` to demonstrate new capability. Deprecate functions from `ogma-extra` that no package needs anymore. **Further notes** None.
- Loading branch information