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-equalize' into develop. Close #248.
**Description** Currently, the cFS, ROS, F' and standalone backends perform similar functionality and are built around similar ideas, but are built slightly differently. This causes an unnecessary amount of code replication, and makes it hard to factorize code out, to incorporate features from a backend into others, and to connect all 4 backends to the GUI. To make the code easier to maintain and help introduce new features in Ogma, we should modify the implementation of all four of those backends to have the same structure, use similar types, and ideally use the same auxiliary functions. This will help us meet existing requirements in terms of features that need to be implemented in Ogma, and in terms of code cleaning. **Type** - Management: Code cleaning and re-architecturing. **Additional context** None. **Requester** - Ivan Perez. **Method to check presence of bug** Not applicable (not a bug). **Expected result** The cFS, ROS, FPrime and standalone backend use the same types to manage failure, and rely on the same auxiliary functions for the common features they implement. The following Dockerfile checks that generating a FPrime, cFS, ROS, and standalone applications, with different data souces and with and without the feature proposed renders the same result for each backend, 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 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 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 \ && git checkout $COMMIT \ && cabal install --overwrite-policy=always ogma-cli:ogma \ && ogma fprime --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-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-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-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 --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 \ && echo "Success" ``` Command (substitute variables based on new path after merge): ```sh $ docker run -e "REPO=https://github.com/NASA/ogma" -e "NAME=ogma" -e "BASE_COMMIT=f1da8cabc6c9437396db20ac26f3356d9a68a465" -e "COMMIT=<HASH>" -it ogma-verify-248 ``` **Solution implemented** Make all the aforementioned backends be built around the `ExceptT` monad, using just `ErrorTriplet` to capture errors. Make all the aforementioned backends define a top-level command and provide a record to pass all options, named accordingly. Re-define `ExprPair` to be a wrapper over a non-existential type, and define the spec parsing function so that it is polymorphic. Externalize the spec parsing feature into its own function in the standalone backend. Pack results in a data structure prior to turning it into JSON in the standalone backend. List auxiliary functions in each file using the same names across backends, and list them in the same order. List exports and imports in the same way across backends. Rename options to have the same names. Make the variables file optional in the cFS backend. Adjust the tests and CLI to match the new interface. **Further notes** None.
- Loading branch information