Skip to content

Commit

Permalink
Split the package into a lib and the line commands
Browse files Browse the repository at this point in the history
  • Loading branch information
jnavila committed Nov 4, 2017
1 parent 2e6c1eb commit 9227cb7
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 31 deletions.
21 changes: 21 additions & 0 deletions kicadsch.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
opam-version: "1.2"
maintainer: "Jean-Noel Avila <jn.avila@free.fr>"
author: "Jean-Noel Avila <jn.avila@free.fr>"
homepage: "https://jnavila.github.io/plotkicadsch/"
bug-reports: "https://github.com/jnavila/plotkicadsch/issues"
license: "ISC"
dev-repo: "https://github.com/jnavila/plotkicadsch.git"
doc: ""
build: [
[ "jbuilder" "subst" ] {pinned}
[ "jbuilder" "build" "-p" name "-j" jobs ]
]
build-test: [["jbuilder" "runtest" "-p" name "-j" jobs]]
depends: [
"jbuilder" {build}
"oUnit" {test}
"pcre"
"tyxml" {>= "4.0.0"}
"base64"
]
available: [ ocaml-version >= "4.03" ]
16 changes: 16 additions & 0 deletions kicadsch/src/jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(jbuild_version 1)

(library
((name kicadsch)
(public_name kicadsch)
(synopsis "Library to plotting KiCAD schematics")
(libraries
(
pcre
tyxml
base64
str
)
)
(flags (:standard -w -3 -safe-string))
))
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions src/kicadsch.ml → kicadsch/src/kicadsch.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
open KicadSch_sigs
module SvgPainter = SvgPainter
module Sigs=KicadSch_sigs
module MakeSchPainter (P: Painter): (SchPainter with type painterContext := P.t) =
struct
module CPainter = Kicadlib.MakePainter(P)
Expand Down Expand Up @@ -57,7 +59,7 @@ struct
| "I"| "Input" -> InputPort
| "B"| "BiDi" -> BiDiPort
| "~" -> NoPort
| _ as s -> ignore (Lwt_io.eprintf "unknown port type %s\n" s); NoPort
| _ as s -> ignore (Printf.printf "unknown port type %s\n" s); NoPort

let justify_of_string s =
match String.get s 0 with
Expand Down Expand Up @@ -254,7 +256,7 @@ struct
(Printf.printf "cannot plot component with missing definitions !";
comp, canevas)
else comp,canevas)
| _ -> (ignore(Lwt_io.eprintf "ignored %s\n" line);
| _ -> (ignore(Printf.printf "ignored %s\n" line);
comp, canevas)

let parse_wire_wire =
Expand Down
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions kicadsch/test/jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

(executable
((name test)
(libraries
(
oUnit
kicadsch
)
)
(flags (:standard -w -27 ))

))

(alias
((name runtest)
(deps (test.exe))
(action (run ${<}))))
8 changes: 4 additions & 4 deletions test/stubPainter.ml → kicadsch/test/stubPainter.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open KicadSch_sigs
open Kicadsch.Sigs

type t = string list

Expand Down Expand Up @@ -46,7 +46,7 @@ let paint_image co s b c =
c
let get_context () = []

let result: string list ref = ref []
let set_canevas_size _ _ c =
c

let write oc c =
result := c; Lwt.return_unit
let write c = c
11 changes: 3 additions & 8 deletions test/test.ml → kicadsch/test/test.ml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
open OUnit
open Lwt.Infix

module MUT = Kicadsch.MakeSchPainter(StubPainter)

let toto = Lwt_io.open_file Lwt_io.Output "/tmp/toto"

let init () = MUT.initial_context ()

let test_printable_F_line () =
let line = "F 0 \"Y1\" V 10004 3631 50 0000 L CNN" in
let u = MUT.parse_line "$Comp" (init ()) in
let v = MUT.parse_line line u in
Lwt_main.run (toto >>= fun t -> MUT.output_context v t);
match !StubPainter.result with
match StubPainter.write (MUT.output_context v) with
| [] -> failwith "Field should have been printed"
| [v] -> assert true
| u::v::w -> failwith "Only one line should be printed"
Expand All @@ -22,17 +19,15 @@ let test_notprintable_F_line () =
let u = MUT.parse_line "$Comp" (init ()) in
let u' = MUT.parse_line line u in
let v = MUT.parse_line "$EndComp" u' in
Lwt_main.run (toto >>= fun t -> MUT.output_context v t);
match !StubPainter.result with
match StubPainter.write (MUT.output_context v) with
| [] -> ()
| _ -> failwith "Field should not have been printed"

let match_wire_line () =
let line = " 5500 1700 5500 2200" in
let u = MUT.parse_line "Wire Wire Line" (init ()) in
let v = MUT.parse_line line u in
Lwt_main.run (toto >>= fun t -> MUT.output_context v t);
match !StubPainter.result with
match StubPainter.write (MUT.output_context v) with
| [v] -> ()
| _ -> failwith "Wire line should have matched"

Expand Down
13 changes: 4 additions & 9 deletions plotkicadsch.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ build: [
[ "jbuilder" "build" "-p" name "-j" jobs ]
]
depends: [
"ocamlfind" {build}
"jbuilder" {build}
"pcre"
"tyxml" {>= "4.0.0"}
"lwt"
"base64"
"sha"
"git"
"git-unix"
"lwt"
"sha"
"git"
"git-unix"
]
available: [ ocaml-version >= "4.03" ]
File renamed without changes.
8 changes: 3 additions & 5 deletions src/jbuild → plotkicadsch/src/jbuild
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@
(package plotkicadsch)
(libraries
(
kicadsch
git-unix
lwt
lwt.unix
sha
pcre
tyxml
base64
str
)
)
(flags (:standard -w -3 -safe-string))
))

(install
((section bin)
((package plotkicadsch)
(section bin)
(files (git-imgdiff))
))
4 changes: 2 additions & 2 deletions src/plotgitsch.ml → plotkicadsch/src/plotgitsch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ open Lwt.Infix
open Git_unix
module Search = Git.Search.Make(FS)

module SvgSchPainter = Kicadsch.MakeSchPainter(SvgPainter)
module SvgSchPainter = Kicadsch.MakeSchPainter(Kicadsch.SvgPainter)
open SvgSchPainter

module type Simple_FS = sig
Expand Down Expand Up @@ -97,7 +97,7 @@ let process_file initctx svg_name content =
initctx >>= fun init ->
content >|= Str.split (Str.regexp "\n") >>= fun lines ->
Lwt_stream.fold parse_line (Lwt_stream.of_list lines) init >>= fun endcontext ->
Lwt_io.with_file ~mode:Lwt_io.Output svg_name (fun o -> Lwt_io.write o (SvgPainter.write @@ output_context endcontext))
Lwt_io.with_file ~mode:Lwt_io.Output svg_name (fun o -> Lwt_io.write o (Kicadsch.SvgPainter.write @@ output_context endcontext))

let rev_parse r =
let open Lwt_process in
Expand Down
3 changes: 2 additions & 1 deletion src/plotkicadsch.ml → plotkicadsch/src/plotkicadsch.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module SvgSchPainter = Kicadsch.MakeSchPainter(SvgPainter)
open Kicadsch
module SvgSchPainter = MakeSchPainter(SvgPainter)
open Lwt
open SvgSchPainter

Expand Down

0 comments on commit 9227cb7

Please sign in to comment.