Skip to content

Commit a487121

Browse files
authored
Merge pull request #5105 from IntersectMBO/coot/cddlc
Introduced cddlc tool
2 parents 7b8fa0c + f13f293 commit a487121

23 files changed

+197
-93
lines changed

docs/network-spec/network-spec.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ \section*{Version history}
223223

224224
\chapter{Common CDDL definitions}
225225
\label{cddl-common}
226-
\lstinputlisting[style=cddl]{../../ouroboros-network-protocols/cddl/specs/common.cddl}
226+
\lstinputlisting[style=cddl]{../../ouroboros-network-protocols/cddl/specs/network.base.cddl}
227227

228228
\chapter{Historical protocol versions}
229229
\label{historical-protocol-versions}

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

network-mux/network-mux.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ benchmark socket-read-write-benchmarks
202202
main-is: Main.hs
203203
other-modules:
204204
build-depends:
205-
base >=4.14 && <4.21,
205+
base >=4.14 && <4.22,
206206
bytestring,
207207
contra-tracer,
208208
io-classes,

nix/cddlc/Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source 'https://rubygems.org'
2+
gem 'cddlc'

nix/cddlc/Gemfile.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
cddlc (0.4.2)
5+
neatjson (~> 0.10)
6+
treetop (~> 1)
7+
neatjson (0.10.5)
8+
polyglot (0.3.5)
9+
treetop (1.6.14)
10+
polyglot (~> 0.3)
11+
12+
PLATFORMS
13+
ruby
14+
15+
DEPENDENCIES
16+
cddlc
17+
18+
BUNDLED WITH
19+
2.6.2

nix/cddlc/gemset.nix

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
cddlc = {
3+
dependencies = [
4+
"neatjson"
5+
"treetop"
6+
];
7+
groups = [ "default" ];
8+
platforms = [ ];
9+
source = {
10+
remotes = [ "https://rubygems.org" ];
11+
sha256 = "1s3fbgd5yqgji162zsmlwnva1v1r3zc1qiyv6im7karv5f08r8m3";
12+
type = "gem";
13+
};
14+
version = "0.4.2";
15+
};
16+
neatjson = {
17+
groups = [ "default" ];
18+
platforms = [ ];
19+
source = {
20+
remotes = [ "https://rubygems.org" ];
21+
sha256 = "0wm1lq8yl6rzysh3wg6fa55w5534k6ppiz0qb7jyvdy582mk5i0s";
22+
type = "gem";
23+
};
24+
version = "0.10.5";
25+
};
26+
polyglot = {
27+
groups = [ "default" ];
28+
platforms = [ ];
29+
source = {
30+
remotes = [ "https://rubygems.org" ];
31+
sha256 = "1bqnxwyip623d8pr29rg6m8r0hdg08fpr2yb74f46rn1wgsnxmjr";
32+
type = "gem";
33+
};
34+
version = "0.3.5";
35+
};
36+
treetop = {
37+
dependencies = [ "polyglot" ];
38+
groups = [ "default" ];
39+
platforms = [ ];
40+
source = {
41+
remotes = [ "https://rubygems.org" ];
42+
sha256 = "1m5fqy7vq6y7bgxmw7jmk7y6pla83m16p7lb41lbqgg53j8x2cds";
43+
type = "gem";
44+
};
45+
version = "1.6.14";
46+
};
47+
}

nix/cddlc/package.nix

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{ lib
2+
, bundlerApp
3+
, bundlerUpdateScript
4+
,
5+
}:
6+
7+
bundlerApp {
8+
pname = "cddlc";
9+
10+
gemdir = ./.;
11+
12+
exes = [ "cddlc" ];
13+
14+
passthru.updateScript = bundlerUpdateScript "cddlc";
15+
16+
meta = {
17+
description = "CDDL conversion utilities";
18+
homepage = "https://github.com/cabo/cddlc";
19+
license = lib.licenses.mit;
20+
maintainers = with lib.maintainers; [ amesgen ];
21+
platforms = lib.platforms.unix;
22+
mainProgram = "cddlc";
23+
};
24+
}

nix/ouroboros-network.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ let
9595
doCheck = !pkgs.stdenv.hostPlatform.isWindows;
9696

9797
# pkgs are instantiated for the host platform
98-
packages.ouroboros-network-protocols.components.tests.cddl.build-tools = [ pkgs.cddl pkgs.cbor-diag ];
98+
packages.ouroboros-network-protocols.components.tests.cddl.build-tools = [ pkgs.cddl pkgs.cbor-diag pkgs.cddlc ];
9999
packages.ouroboros-network-protocols.components.tests.cddl.preCheck = "export HOME=`pwd`";
100100

101101
# don't run checks using Wine when cross compiling

nix/tools.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ in
1818
inherit (final.ouroboros-network.args) compiler-nix-name;
1919
index-state = tool-index-state;
2020
};
21+
# remove once our nixpkgs contains https://github.com/NixOS/nixpkgs/pull/394873
22+
cddlc = final.callPackage ./cddlc/package.nix { };
2123
}
22-

ouroboros-network-protocols/cddl/Main.hs

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import Data.Text qualified as Text
4444
import Data.Word (Word16)
4545

4646
import System.Directory (doesDirectoryExist)
47+
import System.Environment (setEnv)
4748
import System.Exit (ExitCode (..))
4849
import System.FilePath
4950
import System.IO (hClose)
@@ -246,47 +247,47 @@ data CDDLSpecs = CDDLSpecs {
246247
}
247248

248249

250+
-- | Use `cddlc` to resolve module directives (`;# include` and `;# import`).
251+
--
252+
-- The `CDDL_INCLUDE_PATH` environment variable must be set.
253+
cddlc :: FilePath -> IO BL.ByteString
254+
cddlc path = do
255+
(_, cddl, _) <- readProcessWithExitCode "cddlc" ["-u", "-2", "-t", "cddl", path] mempty
256+
return cddl
257+
249258
readCDDLSpecs :: IO CDDLSpecs
250259
readCDDLSpecs = do
251260
dir <- bool ( "cddl" </> "specs") -- False
252261
("ouroboros-network-protocols" </> "cddl" </> "specs") -- True
253262
<$> doesDirectoryExist "ouroboros-network-protocols"
254-
common <- BL.readFile (dir </> "common.cddl")
255-
handshakeNodeToClient <- BL.readFile (dir </> "handshake-node-to-client.cddl")
256-
handshakeNodeToNodeV14ToLast <- BL.readFile (dir </> "handshake-node-to-node-v14.cddl")
257-
chainSync <- BL.readFile (dir </> "chain-sync.cddl")
258-
blockFetch <- BL.readFile (dir </> "block-fetch.cddl")
259-
txSubmission2 <- BL.readFile (dir </> "tx-submission2.cddl")
260-
keepAlive <- BL.readFile (dir </> "keep-alive.cddl")
261-
localTxSubmission <- BL.readFile (dir </> "local-tx-submission.cddl")
262-
localTxMonitor <- BL.readFile (dir </> "local-tx-monitor.cddl")
263-
localStateQuery <- BL.readFile (dir </> "local-state-query.cddl")
264-
265-
peerSharingNodeToNodeV14ToLast <- BL.readFile (dir </> "peer-sharing-v14.cddl")
266-
267-
nodeToNodeVersionDataV14ToLast <- BL.readFile (dir </> "node-to-node-version-data-v14.cddl")
268-
-- append common definitions; they must be appended since the first
269-
-- definition is the entry point for a cddl spec.
263+
setEnv "CDDL_INCLUDE_PATH" (dir <> ":")
264+
265+
handshakeNodeToClient <- cddlc (dir </> "handshake-node-to-client.cddl")
266+
handshakeNodeToNodeV14ToLast
267+
<- cddlc (dir </> "handshake-node-to-node-v14.cddl")
268+
chainSync <- cddlc (dir </> "chain-sync.cddl")
269+
blockFetch <- cddlc (dir </> "block-fetch.cddl")
270+
txSubmission2 <- cddlc (dir </> "tx-submission2.cddl")
271+
keepAlive <- cddlc (dir </> "keep-alive.cddl")
272+
localTxSubmission <- cddlc (dir </> "local-tx-submission.cddl")
273+
localTxMonitor <- cddlc (dir </> "local-tx-monitor.cddl")
274+
localStateQuery <- cddlc (dir </> "local-state-query.cddl")
275+
276+
peerSharingNodeToNodeV14ToLast <- cddlc (dir </> "peer-sharing-v14.cddl")
277+
nodeToNodeVersionDataV14ToLast <- cddlc (dir </> "node-to-node-version-data-v14.cddl")
278+
270279
return CDDLSpecs {
271-
cddlHandshakeNodeToClient = CDDLSpec handshakeNodeToClient,
272-
cddlHandshakeNodeToNodeV14ToLast = CDDLSpec handshakeNodeToNodeV14ToLast,
273-
cddlChainSync = CDDLSpec $ chainSync
274-
<> common,
275-
cddlBlockFetch = CDDLSpec $ blockFetch
276-
<> common,
277-
cddlTxSubmission2 = CDDLSpec $ txSubmission2
278-
<> common,
280+
cddlHandshakeNodeToClient = CDDLSpec handshakeNodeToClient,
281+
cddlHandshakeNodeToNodeV14ToLast = CDDLSpec handshakeNodeToNodeV14ToLast,
282+
cddlChainSync = CDDLSpec chainSync,
283+
cddlBlockFetch = CDDLSpec blockFetch,
284+
cddlTxSubmission2 = CDDLSpec txSubmission2,
279285
cddlKeepAlive = CDDLSpec keepAlive,
280-
cddlLocalTxSubmission = CDDLSpec $ localTxSubmission
281-
<> common,
282-
cddlLocalTxMonitor = CDDLSpec $ localTxMonitor
283-
<> common,
284-
cddlLocalStateQuery = CDDLSpec $ localStateQuery
285-
<> common,
286-
287-
cddlPeerSharingNodeToNodeV14ToLast = CDDLSpec $ peerSharingNodeToNodeV14ToLast
288-
<> common,
286+
cddlLocalTxSubmission = CDDLSpec localTxSubmission,
287+
cddlLocalTxMonitor = CDDLSpec localTxMonitor,
288+
cddlLocalStateQuery = CDDLSpec localStateQuery,
289289

290+
cddlPeerSharingNodeToNodeV14ToLast = CDDLSpec peerSharingNodeToNodeV14ToLast,
290291
cddlNodeToNodeVersionDataV14ToLast = CDDLSpec nodeToNodeVersionDataV14ToLast
291292
}
292293

@@ -846,7 +847,7 @@ unit_decodeChainSync spec =
846847
[ SomeAgency ChainSync.SingIdle
847848
, SomeAgency (ChainSync.SingNext ChainSync.SingCanAwait)
848849
, SomeAgency (ChainSync.SingNext ChainSync.SingMustReply)
849-
, SomeAgency (ChainSync.SingIntersect)
850+
, SomeAgency ChainSync.SingIntersect
850851
]
851852
100
852853

@@ -873,8 +874,8 @@ unit_decodeTxSubmission2 spec =
873874
[ SomeAgency TxSubmission2.SingInit
874875
, SomeAgency $ TxSubmission2.SingTxIds TxSubmission2.SingBlocking
875876
, SomeAgency $ TxSubmission2.SingTxIds TxSubmission2.SingNonBlocking
876-
, SomeAgency $ TxSubmission2.SingTxs
877-
, SomeAgency $ TxSubmission2.SingIdle
877+
, SomeAgency TxSubmission2.SingTxs
878+
, SomeAgency TxSubmission2.SingIdle
878879
]
879880
100
880881

0 commit comments

Comments
 (0)