Skip to content

Commit

Permalink
Add git commit to version; print version for OVSDB converter
Browse files Browse the repository at this point in the history
- Add git commit hash to output of `--version`
- Also add `--version` switch to `ovsdb2ddlog`
  • Loading branch information
ryzhyk committed Jul 16, 2019
1 parent feef165 commit 2e1e42d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 17 deletions.
37 changes: 25 additions & 12 deletions adapters/ovsdb/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,45 @@ import Control.Monad
import qualified Data.Map as M

import Language.DifferentialDatalog.OVSDB.Compile
import Language.DifferentialDatalog.Version

data TOption = OVSFile String
| OutputTable String
| ROColumn String
| KeyColumn String
| ProxyTable String
| Version

data Action = ActionCompile
| ActionVersion
deriving Eq

options :: [OptDescr TOption]
options = [ Option ['f'] ["schema-file"] (ReqArg OVSFile "FILE") "OVSDB schema file"
, Option ['o'] ["output-table"] (ReqArg OutputTable "TABLE") "mark TABLE as output"
, Option [] ["ro"] (ReqArg ROColumn "TABLE.COLUMN") "mark COLUMN as read-only"
, Option ['k'] ["key"] (ReqArg KeyColumn "TABLE.COLUMN") "mark COLUMN as key"
, Option ['p'] ["gen-proxy"] (ReqArg ProxyTable "TABLE") "generate output proxy table for TABLE"
options = [ Option ['v'] ["version"] (NoArg Version) "Display DDlog version."
, Option ['f'] ["schema-file"] (ReqArg OVSFile "FILE") "OVSDB schema file."
, Option ['o'] ["output-table"] (ReqArg OutputTable "TABLE") "Mark TABLE as output."
, Option [] ["ro"] (ReqArg ROColumn "TABLE.COLUMN") "Mark COLUMN as read-only."
, Option ['k'] ["key"] (ReqArg KeyColumn "TABLE.COLUMN") "Mark COLUMN as key."
, Option ['p'] ["gen-proxy"] (ReqArg ProxyTable "TABLE") "Generate output proxy table for TABLE."
]

data Config = Config { confOVSFile :: FilePath
data Config = Config { confAction :: Action
, confOVSFile :: FilePath
, confOutputTables :: [(String, [String])]
, confProxyTables :: [String]
, confKeys :: M.Map String [String]
}

defaultConfig = Config { confOVSFile = ""
defaultConfig = Config { confAction = ActionCompile
, confOVSFile = ""
, confOutputTables = []
, confProxyTables = []
, confKeys = M.empty
}


addOption :: Config -> TOption -> IO Config
addOption config Version = do return config { confAction = ActionVersion }
addOption config (OVSFile f) = do
when (confOVSFile config /= "") $ errorWithoutStackTrace "Multiple input files specified"
return config {confOVSFile = f}
Expand All @@ -76,7 +86,6 @@ addOption config (KeyColumn c) = do
return $ config{confKeys = M.alter (maybe (Just [col]) (\keys -> Just $ nub $ col:keys)) table
$ confKeys config}
_ -> errorWithoutStackTrace $ "Invalid column name " ++ c

addOption config (ROColumn c) = do
case splitOn "." c of
[table, col] -> do
Expand All @@ -89,7 +98,7 @@ addOption config (ROColumn c) = do

validateConfig :: Config -> IO ()
validateConfig Config{..} = do
when (confOVSFile == "") $ errorWithoutStackTrace "Input file not specified"
when (confOVSFile == "" && confAction == ActionCompile) $ errorWithoutStackTrace "Input file not specified"

main = do
args <- getArgs
Expand All @@ -102,6 +111,10 @@ main = do
(\e -> do putStrLn $ usageInfo ("Usage: " ++ prog ++ " [OPTION...]") options
throw (e::SomeException))
_ -> errorWithoutStackTrace $ usageInfo ("Usage: " ++ prog ++ " [OPTION...]") options
dlschema <- compileSchemaFile confOVSFile confOutputTables confProxyTables confKeys
putStrLn $ render dlschema
return ()
if confAction == ActionVersion
then do putStrLn $ "OVSDB-to-DDlog compiler " ++ dDLOG_VERSION ++ " (" ++ gitHash ++ ")"
putStrLn $ "Copyright (c) 2019 VMware, Inc. (MIT License)"
else do
dlschema <- compileSchemaFile confOVSFile confOutputTables confProxyTables confKeys
putStrLn $ render dlschema
return ()
8 changes: 3 additions & 5 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-}

{-# LANGUAGE RecordWildCards, ImplicitParams, LambdaCase, FlexibleContexts #-}
{-# LANGUAGE RecordWildCards, ImplicitParams, LambdaCase, FlexibleContexts, TemplateHaskell #-}

import System.Environment
import System.FilePath.Posix
Expand All @@ -31,15 +31,13 @@ import Control.Monad
import Data.List
import Text.PrettyPrint

import Language.DifferentialDatalog.Version
import Language.DifferentialDatalog.Syntax
import Language.DifferentialDatalog.Module
import Language.DifferentialDatalog.Validate
import Language.DifferentialDatalog.Compile
import Language.DifferentialDatalog.CompileJava

-- Keep this in sync with the binary release version on github
dDLOG_VERSION = "v0.6.2"

data TOption = Help
| Version
| Datalog String
Expand Down Expand Up @@ -135,7 +133,7 @@ main = do
_ -> errorWithoutStackTrace $ usageInfo ("Usage: " ++ prog ++ " [OPTION...]") options
case confAction config of
ActionHelp -> putStrLn $ usageInfo ("Usage: " ++ prog ++ " [OPTION...]") options
ActionVersion -> do putStrLn $ "DDlog " ++ dDLOG_VERSION
ActionVersion -> do putStrLn $ "DDlog " ++ dDLOG_VERSION ++ " (" ++ gitHash ++ ")"
putStrLn $ "Copyright (c) 2019 VMware, Inc. (MIT License)"
ActionValidate -> do { parseValidate config; return () }
ActionCompile -> compileProg config
Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies:
- wide-word
- graphviz
- text
- githash

library:
source-dirs: src
Expand Down
37 changes: 37 additions & 0 deletions src/Language/DifferentialDatalog/Version.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{-
Copyright (c) 2018 VMware, Inc.
SPDX-License-Identifier: MIT
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-}

{-# LANGUAGE TemplateHaskell #-}

module Language.DifferentialDatalog.Version (
dDLOG_VERSION,
gitHash)
where

import GitHash

-- Keep this in sync with the binary release version on github
dDLOG_VERSION = "v0.6.2"

gitHash :: String
gitHash = giHash $$tGitInfoCwd

0 comments on commit 2e1e42d

Please sign in to comment.