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-template-vars' into develop. Close #250.
**Description** The generated ROS, FPrime and standalone application may need definitions that come from external files, such as topic names from other applications, or structs defined elsewhere. Users may also want to customize additional aspects of the generated applications without having to modify the template, such as passing additional variables to be expanded in the template. There should be a setting to expand other variables so that the generated app never has to be modified. **Type** - Feature: facilitate customizing generated applications. **Additional context** None. **Requester** - Ivan Perez. **Method to check presence of bug** Not applicable (not a bug). **Expected result** Ogma provides a mechanism to provide additional variables to be expanded in ROS, FPrime and standalone applications. The following dockerfile first checks that passing the additional extra variables files to different backends 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 to each custom template mentioning a new variable, and then passes an extra template variable using the new flag, after which it prints the message "Success" 5 times (one for each combination of backends and options tried), indicating that the new variable was expanded as expected: ``` --- Dockerfile-250 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 $COMMIT \ && cabal install ogma-cli:ogma \ && ogma fprime --app-target-dir fprime_original --handlers-file /tmp/fprime-handlers --input-file /tmp/document.json -f /tmp/json-format.cfg -p literal --variable-db /tmp/fprime-variable-db \ && ogma ros --app-target-dir ros_spec_original --handlers-file ogma-cli/examples/ros-copilot/handlers --input-file /tmp/document.json -f /tmp/json-format.cfg -p literal --variable-db ogma-cli/examples/ros-copilot/vars-db \ && ogma ros --app-target-dir ros_variables_original --handlers-file ogma-cli/examples/ros-copilot/handlers --variable-db ogma-cli/examples/ros-copilot/vars-db --variable-file ogma-cli/examples/ros-copilot/variables \ && ogma cfs --app-target-dir cfs_original --handlers-file ogma-cli/examples/cfs-handlers --variable-db ogma-cli/examples/cfs-variable-db --variable-file ogma-cli/examples/cfs-variables \ && ogma standalone --target-dir standalone_original --file-name /tmp/document.json -f /tmp/json-format.cfg -p literal --target-file-name copilot \ && cp -r ogma-core/templates custom \ && find custom -iname '.gitignore' -delete \ && echo '{ "message": "Success" }' >> template-vars \ && ogma fprime --app-template-dir custom/fprime --template-vars template-vars --app-target-dir fprime_updated --handlers-file /tmp/fprime-handlers --input-file /tmp/document.json -f /tmp/json-format.cfg -p literal --variable-db /tmp/fprime-variable-db \ && ogma ros --app-template-dir custom/ros --template-vars template-vars --app-target-dir ros_spec_updated --handlers-file ogma-cli/examples/ros-copilot/handlers --input-file /tmp/document.json -f /tmp/json-format.cfg -p literal --variable-db ogma-cli/examples/ros-copilot/vars-db \ && ogma ros --app-template-dir custom/ros --template-vars template-vars --app-target-dir ros_variables_updated --handlers-file ogma-cli/examples/ros-copilot/handlers --variable-db ogma-cli/examples/ros-copilot/vars-db --variable-file ogma-cli/examples/ros-copilot/variables \ && ogma cfs --app-template-dir custom/copilot-cfs --template-vars template-vars --app-target-dir cfs_updated --handlers-file ogma-cli/examples/cfs-handlers --variable-db ogma-cli/examples/cfs-variable-db --variable-file ogma-cli/examples/cfs-variables \ && ogma standalone --template-dir custom/standalone --template-vars template-vars --target-dir standalone_updated --file-name /tmp/document.json -f /tmp/json-format.cfg -p literal --target-file-name copilot \ && diff -rq fprime_original fprime_updated \ && diff -rq ros_variables_original ros_variables_updated \ && diff -rq ros_spec_original ros_spec_updated \ && diff -rq cfs_original cfs_updated \ && diff -rq standalone_original standalone_updated \ && rm -rf *_updated \ && echo '{{message}}' >> custom/copilot-cfs/fsw/result \ && echo '{{message}}' >> custom/ros/result \ && echo '{{message}}' >> custom/fprime/result \ && echo '{{message}}' >> custom/standalone/result \ && ogma fprime --app-template-dir custom/fprime --template-vars template-vars --app-target-dir fprime_updated --handlers-file /tmp/fprime-handlers --input-file /tmp/document.json -f /tmp/json-format.cfg -p literal --variable-db /tmp/fprime-variable-db \ && ogma ros --app-template-dir custom/ros --template-vars template-vars --app-target-dir ros_spec_updated --handlers-file ogma-cli/examples/ros-copilot/handlers --input-file /tmp/document.json -f /tmp/json-format.cfg -p literal --variable-db ogma-cli/examples/ros-copilot/vars-db \ && ogma ros --app-template-dir custom/ros --template-vars template-vars --app-target-dir ros_variables_updated --handlers-file ogma-cli/examples/ros-copilot/handlers --variable-db ogma-cli/examples/ros-copilot/vars-db --variable-file ogma-cli/examples/ros-copilot/variables \ && ogma cfs --app-template-dir custom/copilot-cfs --template-vars template-vars --app-target-dir cfs_updated --handlers-file ogma-cli/examples/cfs-handlers --variable-db ogma-cli/examples/cfs-variable-db --variable-file ogma-cli/examples/cfs-variables \ && ogma standalone --template-dir custom/standalone --template-vars template-vars --target-dir standalone_updated --file-name /tmp/document.json -f /tmp/json-format.cfg -p literal --target-file-name copilot \ && cat fprime_updated/result \ && cat ros_spec_updated/result \ && cat ros_variables_updated/result \ && cat cfs_updated/fsw/result \ && cat standalone_updated/result \ && echo "Complete Success" --- document.json { "Example": { "internal_variables": [], "external_variables": [ {"name":"input", "type":"Float", "meaning": "Input from the system"} ], "properties": [ { "id": "MyProperty", "formula": "PTLTL.alwaysBeen (input /= 30.0)", "text": "Input is never 30" } ] } } --- fprime-handlers handlerMyProperty --- fprime-variable-db ("pullup", "bool") ("input", "float") --- json-format.cfg JSONFormat { specInternalVars = Just "..internal_variables[*]" , specInternalVarId = ".name" , specInternalVarExpr = ".meaning" , specInternalVarType = Just ".type" , specExternalVars = Just "..external_variables[*]" , specExternalVarId = ".name" , specExternalVarType = Just ".type" , specRequirements = "..properties[*]" , specRequirementId = ".id" , specRequirementDesc = Just ".text" , specRequirementExpr = ".formula" } ``` Command (substitute variables based on new path after merge): ```sh $ docker run -e "REPO=https://github.com/NASA/ogma" -e "NAME=ogma" -e "COMMIT=<HASH>" -it ogma-verify-250 ``` **Solution implemented** Expand the ROS, FPrime and standalone backends in `ogma-core` to expect and use an additional optional argument pointing to a JSON file with additional variables to expand in the template. Adjust tests in `ogma-core` based on the new API. Provide a CLI flag for the ROS, FPrime and standalone backends that allows filling in additional template variables. Document new flag in the README. **Further notes** None.
- Loading branch information