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-core: Enable using user-provided file as format definition spec. Refs #200. #201

Merged

Conversation

ivanperez-keera
Copy link
Member

@ivanperez-keera ivanperez-keera commented Jan 19, 2025

Modify ogma-core's standalone backend to treat the format name as a local file name when applicable, as prescribed in the solution proposed for #200.

… Refs nasa#200.

Ogma allows users to select the format used for the JSON file, but only
known formats can be selected. Users should be able to pass a local file
containing a JSON format specification as an argument.

This commit modifies the standalone backend so that, if a file exists
with the name of the format selected, or if the format name contains a
path separator, then it is treated as a local file. Otherwise, Ogma
finds the file in the package's data directory.
@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 checks that a known format can still be used, and that, if a custom provided format is specified in the command line, it is picked up instead and used to parse the input file, in both cases checking also that the resulting monitor compiles successfully, after which it prints the message "Success":
      --- Dockerfile-verify-200
      FROM ubuntu:trusty
      
      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 --constraint='happy < 2.0'
      RUN apt-get install --yes git
      
      ADD json-custom-format /tmp/json-custom-format
      ADD properties.json /tmp/properties.json
      
      CMD git clone $REPO && \
          cd $NAME && \
          git checkout $COMMIT && \
          cd .. && \
          cabal v1-install copilot-4.2 $NAME/$PAT**/ && \
          ogma standalone --input-format fdb --file-name $NAME/ogma-cli/examples/DB.json --target-dir output1 && \
          cabal v1-exec -- runhaskell -XPartialTypeSignatures -Wno-partial-type-signatures output1/Copilot.hs && \
          ogma standalone --input-format /tmp/json-custom-format --file-name /tmp/properties.json --target-dir output2 && \
          cabal v1-exec -- runhaskell output2/Copilot.hs && \
          echo "Success"
      
      --- json-custom-format
      JSONFormat
         { specInternalVars    = Just "..internal_vars[*]"
         , specInternalVarId   = ".name"
         , specInternalVarExpr = ".meaning"
         , specInternalVarType = Just ".type"
         , specExternalVars    = Just "..other_vars[*]"
         , specExternalVarId   = ".name"
         , specExternalVarType = Just ".type"
         , specRequirements    = "..requirements[*]"
         , specRequirementId   = ".id"
         , specRequirementDesc = Just ".text"
         , specRequirementExpr = ".formula"
         }
      
      -- properties.json
      {
        "spec": {
          "internal_vars": [],
          "other_vars": [
            {"name":"param", "type":"bool"}
          ],
          "requirements": [
            {
              "id":      "req001",
              "formula": "(H param)",
              "text":    "param is always true"
            }
          ]
        }
      }
      
      Command (substitute variables based on new path after merge):
      $ docker run -e "REPO=https://github.com/ivanperez-keera/ogma" -e "NAME=ogma" -e "PAT=ogma" -e "COMMIT=b1316063bc6ca4e930722d064be430c37cbbbb98" -it ogma-verify-200
      
  • Implementation is documented. Details:
    The code that implements this feature includes comments that explain what is being done, and all top-level definitions introduce include haddock documentation.
  • Change history is clear.
  • Commit messages are clear.
  • Changelogs are updated.
  • Examples are updated. Details:
    No updates needed.
  • Required version bumps are evaluated. Details:
    Bump not required (API is backwards compatible).

@ivanperez-keera ivanperez-keera merged commit 4ba1d4b into nasa:develop Jan 19, 2025
2 checks passed
@ivanperez-keera ivanperez-keera deleted the develop-format-localfile branch January 19, 2025 17:03
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