Skip to content

Commit

Permalink
Merge branch 'develop-copilot-3.19' into develop. Close #231.
Browse files Browse the repository at this point in the history
**Description**

Copilot 3.19 changed the way that structs are generated. For example, the
function `typename` was removed in favor of `typeName`.

The code currently generated by Ogma requires Copilot < 3.19 to work. We need
to update that.

**Type**

- Management: Update to work with new versions of dependencies.

**Additional context**

None.

**Requester**

- Ivan Perez.

**Method to check presence of bug**

Not applicable (not a bug).

**Expected result**

The code generated by the struct generator compiles with Copilot 4.2, the
current version as of the time of this writing.

The following dockerfile installs Copilot 4.2 and Ogma, and uses the structs
command to generate a Copilot struct definition, and uses Copilot to check that
the code generated compiles, 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

SHELL ["/bin/bash", "-c"]
CMD git clone $REPO \
    && cd $NAME \
    && git checkout $COMMIT \
    && cabal install --lib copilot copilot-c99 copilot-language \
         copilot-theorem copilot-libraries copilot-interpreter \
    && cabal install ogma-cli:ogma \
    && echo '{-# LANGUAGE DataKinds #-}' >> Point.hs \
    && echo 'module Point where'         >> Point.hs \
    && echo 'import Language.Copilot'    >> Point.hs \
    && ogma structs --header-file-name ogma-cli/examples/point.h >> Point.hs \
    && ghc -c Point.hs \
    && 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 "COMMIT=<HASH>" -it ogma-verify-231
```

**Solution implemented**

Modify the code generated by the Copilot struct backend to use the class method
`typeName` instead of the old name `typename`. Adjust local names in the Ogma
code accordingly.

**Further notes**

None.
  • Loading branch information
ivanperez-keera committed Feb 3, 2025
2 parents 5805a67 + 518b051 commit 581ba68
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ogma-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Revision history for ogma-core

## [1.X.Y] - 2025-02-02
## [1.X.Y] - 2025-02-03

* Import liftIO from Control.Monad.IO.Class (#215).
* Remove references to old design of Ogma from hlint files (#220).
* Bump upper version constraint on aeson, text (#225).
* Remove extraneous EOL character (#224).
* Make structured data available to cFS template (#229).
* Update Copilot struct code generator to use new function names (#231).

## [1.6.0] - 2025-01-21

Expand Down
4 changes: 2 additions & 2 deletions ogma-core/src/Language/Trans/CStructs2Copilot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ structInstance cstruct =
instanceHead = "Struct" ++ " " ++ instanceName
instanceName = cStructName2Haskell $ cStructName cstruct

instanceBody = [ instanceTypename, instanceToValues ]
instanceBody = [ instanceTypeName, instanceToValues ]

instanceTypename = "typename" ++ " " ++ "_" ++ " = " ++ show (cStructName cstruct)
instanceTypeName = "typeName" ++ " " ++ "_" ++ " = " ++ show (cStructName cstruct)

instanceToValues =
"toValues" ++ " " ++ "v" ++ " = " ++ "[ " ++ intercalate ", " valueDecls ++ " ]"
Expand Down

0 comments on commit 581ba68

Please sign in to comment.