Skip to content

Commit c805325

Browse files
authored
Static ctypes; building with dune (#28)
Signed-off-by: Michael Greenberg <michael@greenberg.science>
1 parent 4928fc1 commit c805325

16 files changed

+607
-287
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,11 @@ jobs:
8383
uses: avsm/setup-ocaml@v2
8484
with:
8585
ocaml-compiler: ${{ matrix.ocaml-compiler }}
86+
dune-cache: true
8687

87-
- name: Install OCaml bindings
88-
run: opam install .
88+
- name: Install and test OCaml bindings
89+
run: opam install --with-test --working-dir .
8990

90-
- name: Test OCaml bindings
91-
run: opam exec -- make -C ocaml test
92-
9391
# we don't reuse the wheels so that all of the CI runs can happen concurrently
9492
- name: Install Python directly
9593
run: sudo pip3 install .

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,15 @@ Makefile
2222
/stamp-h1
2323

2424
# generated by make
25+
/src/builtins.h
26+
/src/nodes.h
27+
/src/syntax.h
28+
/src/token.h
2529
/src/token_vars.h
2630

31+
# generated by dune
32+
_build
33+
2734
# Apple debug symbol bundles
2835
*.dSYM/
2936

dune

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
(data_only_dirs src)
2+
3+
(rule
4+
(deps (source_tree src) configure.ac Makefile.am)
5+
(targets libdash.a dlldash.so
6+
builtins.h nodes.h syntax.h token.h token_vars.h
7+
)
8+
(action
9+
(bash
10+
"\
11+
\n set -e\
12+
\n if [ \"$(uname -s)\" = \"Darwin\" ]; then glibtoolize; else libtoolize; fi\
13+
\n aclocal && autoheader && automake --add-missing && autoconf\
14+
\n ./configure --prefix=\"$(pwd)\"\
15+
\n %{make}\
16+
\n %{make} install\
17+
\n cp lib/libdash.a libdash.a\
18+
\n cp lib/dlldash.so dlldash.so\
19+
\n cp src/{builtins,nodes,syntax,token,token_vars}.h .\
20+
\n")))
21+
22+
(subdir src
23+
(rule
24+
(deps ../builtins.h ../nodes.h ../syntax.h ../token.h ../token_vars.h)
25+
(targets builtins.h nodes.h syntax.h token.h token_vars.h)
26+
(action
27+
(progn
28+
(copy ../builtins.h builtins.h)
29+
(copy ../nodes.h nodes.h)
30+
(copy ../syntax.h syntax.h)
31+
(copy ../token.h token.h)
32+
(copy ../token_vars.h token_vars.h)))))
33+
34+
(library
35+
(name dash)
36+
(foreign_archives dash))

dune-project

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(lang dune 3.12)
2+
(name libdash)
3+
(using ctypes 0.3)
4+
5+
(source (github mgree/libdash))
6+
(license BSD-3-Clause)
7+
(authors "Michael Greenberg")
8+
(maintainers "michael@greenberg.science")
9+
10+
(package
11+
(name libdash)
12+
(synopsis "Bindings to the dash shell's parser")
13+
(depends
14+
("ctypes" (>= "0.21.1"))
15+
("ctypes-foreign" (>= "0.21.1"))
16+
("atdgen" (>= "2.15.0"))
17+
("conf-autoconf" (>= 0.1))
18+
("conf-aclocal" (>= 2))
19+
("conf-automake" (>= 1))
20+
("conf-libtool" (>= 1))))
21+
22+
(generate_opam_files)

dune-workspace

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(lang dune 3.12)
2+
(env
3+
(dev
4+
(flags (:standard -warn-error -27))))

libdash.opam

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
1+
# This file is generated by dune, edit dune-project instead
12
opam-version: "2.0"
23
synopsis: "Bindings to the dash shell's parser"
3-
maintainer: "Michael Greenberg <michael.greenberg@pomona.edu>"
4-
authors: "Michael Greenberg <michael.greenberg@pomona.edu>"
4+
maintainer: ["michael@greenberg.science"]
5+
authors: ["Michael Greenberg"]
56
license: "BSD-3-Clause"
67
homepage: "https://github.com/mgree/libdash"
78
bug-reports: "https://github.com/mgree/libdash/issues"
89
depends: [
9-
"ocaml" {>= "4.07"}
10-
"ocamlfind" {>= "1.8.0"}
11-
"ctypes" {>= "0.18.0"}
12-
"ctypes-foreign" {>= "0.18.0"}
13-
"atdgen" {>= "2.3.2"}
14-
"conf-autoconf" {build}
15-
"conf-aclocal" {build}
16-
"conf-automake" {build}
17-
"conf-libtool" {build}
10+
"dune" {>= "3.12"}
11+
"ctypes" {>= "0.21.1"}
12+
"ctypes-foreign" {>= "0.21.1"}
13+
"atdgen" {>= "2.15.0"}
14+
"conf-autoconf" {>= "0.1"}
15+
"conf-aclocal" {>= "2"}
16+
"conf-automake" {>= "1"}
17+
"conf-libtool" {>= "1"}
18+
"odoc" {with-doc}
1819
]
1920
build: [
20-
["libtoolize"] {os != "macos"}
21-
["glibtoolize"] {os = "macos"}
22-
["aclocal"]
23-
["autoheader"]
24-
["automake" "--add-missing"]
25-
["autoconf"]
26-
["mkdir" "_build"]
27-
["./configure" "--prefix=%{build}%/_build"]
28-
[make]
29-
[make "install"] # into _build
30-
["ocaml/mk_meta.sh" "%{_:lib}%"] # pass along the lib directory for the rpath in the META
31-
[make "-C" "ocaml" "all"]
32-
["./mk_dot_install.sh"]
33-
["./ldconfig.sh"] # fix up .so files if ldconfig didn't do it
34-
[make "-C" "ocaml" "test"] {with-test}
21+
["dune" "subst"] {dev}
22+
[
23+
"dune"
24+
"build"
25+
"-p"
26+
name
27+
"-j"
28+
jobs
29+
"@install"
30+
"@runtest" {with-test}
31+
"@doc" {with-doc}
32+
]
3533
]
36-
dev-repo: "git+https:///github.com/mgree/libdash"
37-
url {
38-
src: "https://github.com/mgree/libdash/archive/v0.3.tar.gz"
39-
}
40-
34+
dev-repo: "git+https://github.com/mgree/libdash.git"

ocaml/ast.ml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,20 @@ let string_of_var_type = function
8686

8787

8888
open Ctypes
89-
open Foreign
9089
open Dash
9190

9291
let rec last = function
9392
| [] -> None
9493
| [x] -> Some x
95-
| x::xs -> last xs
94+
| _::xs -> last xs
9695

9796
let skip = Command (-1,[],[],[])
9897

99-
let special_chars : char list = explode "|&;<>()$`\\\"'"
100-
10198
type quote_mode =
10299
QUnquoted
103100
| QQuoted
104101
| QHeredoc
105102

106-
let needs_escaping c = List.mem c special_chars
107-
108103
let rec of_node (n : node union ptr) : t =
109104
if nullptr n
110105
then skip
@@ -225,7 +220,7 @@ and of_binary (n : node union ptr) =
225220
(of_node (getf n nbinary_ch1), of_node (getf n nbinary_ch2))
226221

227222
and to_arg (n : narg structure) : arg =
228-
let a,s,bqlist,stack = parse_arg ~tilde_ok:true ~assign:false (explode (getf n narg_text)) (getf n narg_backquote) [] in
223+
let a,s,bqlist,stack = parse_arg ~assign:false (explode (getf n narg_text)) (getf n narg_backquote) [] in
229224
(* we should have used up the string and have no backquotes left in our list *)
230225
assert (s = []);
231226
assert (nullptr bqlist);
@@ -304,6 +299,7 @@ and parse_arg ?tilde_ok:(tilde_ok=false) ~assign:(assign:bool) (s : char list) (
304299
then (* we're in arithmetic or double quotes, so tilde is ignored *)
305300
arg_char assign (C '~') s bqlist stack
306301
else
302+
let _ = tilde_ok in (* unused? *)
307303
let uname,s' = parse_tilde [] s in
308304
arg_char assign (T uname) s' bqlist stack
309305
(* ordinary character *)
@@ -325,7 +321,7 @@ and parse_tilde acc s =
325321
and arg_char assign c s bqlist stack =
326322
let tilde_ok =
327323
match c with
328-
| C c -> assign && (match last s with
324+
| C _ -> assign && (match last s with
329325
| Some ':' -> true
330326
| _ -> false)
331327
| _ -> false

ocaml/ast_atd.atd

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
type char <ocaml predef module="Ast"> = int <ocaml repr="char">
1+
type char <ocaml predef module="Libdash.Ast"> = int <ocaml repr="char">
22

3-
type linno <ocaml predef module="Ast"> = int
3+
type linno <ocaml predef module="Libdash.Ast"> = int
44

5-
type t <ocaml predef module="Ast"> = [
5+
type t <ocaml predef module="Libdash.Ast"> = [
66
Command of (linno * assign list * args * redirection list) (* assign, args, redir *)
77
| Pipe of (bool * t list) (* background?, commands *)
88
| Redir of (linno * t * redirection list)
@@ -19,37 +19,37 @@ type t <ocaml predef module="Ast"> = [
1919
| Defun of (linno * string * t) (* name, body *)
2020
] <ocaml repr="classic">
2121

22-
type assign <ocaml predef module="Ast"> = (string * arg) <ocaml repr="classic">
22+
type assign <ocaml predef module="Libdash.Ast"> = (string * arg) <ocaml repr="classic">
2323

24-
type redirection <ocaml predef module="Ast"> = [
24+
type redirection <ocaml predef module="Libdash.Ast"> = [
2525
File of (redir_type * int * arg)
2626
| Dup of (dup_type * int * arg)
2727
| Heredoc of (heredoc_type * int * arg)
2828
] <ocaml repr="classic">
2929

30-
type redir_type <ocaml predef module="Ast"> = [
30+
type redir_type <ocaml predef module="Libdash.Ast"> = [
3131
To
3232
| Clobber
3333
| From
3434
| FromTo
3535
| Append
3636
] <ocaml repr="classic">
3737

38-
type dup_type <ocaml predef module="Ast"> = [
38+
type dup_type <ocaml predef module="Libdash.Ast"> = [
3939
ToFD
4040
| FromFD
4141
] <ocaml repr="classic">
4242

43-
type heredoc_type <ocaml predef module="Ast"> = [
43+
type heredoc_type <ocaml predef module="Libdash.Ast"> = [
4444
Here
4545
| XHere (* for when in a quote... not sure when this comes up *)
4646
] <ocaml repr="classic">
4747

48-
type args <ocaml predef module="Ast"> = arg list
48+
type args <ocaml predef module="Libdash.Ast"> = arg list
4949

50-
type arg <ocaml predef module="Ast"> = arg_char list
50+
type arg <ocaml predef module="Libdash.Ast"> = arg_char list
5151

52-
type arg_char <ocaml predef module="Ast"> = [
52+
type arg_char <ocaml predef module="Libdash.Ast"> = [
5353
C of char
5454
| E of char (* escape... necessary for expansion *)
5555
| T of string option (* tilde *)
@@ -59,7 +59,7 @@ type arg_char <ocaml predef module="Ast"> = [
5959
| B of t (* backquote *)
6060
] <ocaml repr="classic">
6161

62-
type var_type <ocaml predef module="Ast"> = [
62+
type var_type <ocaml predef module="Libdash.Ast"> = [
6363
Normal
6464
| Minus
6565
| Plus
@@ -72,7 +72,7 @@ type var_type <ocaml predef module="Ast"> = [
7272
| Length
7373
] <ocaml repr="classic">
7474

75-
type case <ocaml predef module="Ast"> = {
75+
type case <ocaml predef module="Libdash.Ast"> = {
7676
cpattern : arg list;
7777
cbody : t
7878
}

0 commit comments

Comments
 (0)