Skip to content

Commit e54ecd3

Browse files
authored
CI: add Github Action workflow for MacOS and Windows (ocaml-ppx#2055)
1 parent 984534d commit e54ecd3

31 files changed

+245
-36
lines changed

.github/workflows/build.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Build
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
jobs:
8+
build:
9+
strategy:
10+
matrix:
11+
os:
12+
- macos-latest
13+
- ubuntu-latest
14+
- windows-latest
15+
ocaml-compiler:
16+
# Don't include every versions. OCaml-CI already covers that
17+
- 4.13.x
18+
19+
runs-on: ${{ matrix.os }}
20+
21+
steps:
22+
# Clone the project
23+
- uses: actions/checkout@v2
24+
25+
# Setup
26+
- name: Setup OCaml ${{ matrix.ocaml-version }}
27+
uses: ocaml/setup-ocaml@v2
28+
with:
29+
ocaml-compiler: ${{ matrix.ocaml-compiler }}
30+
31+
- name: Opam dependencies
32+
run: opam install --deps-only -t .
33+
34+
- name: Runtest
35+
run: opam exec -- dune runtest
36+
37+
- name: Check help files
38+
run: opam exec -- dune build @help --auto-promote

lib/Eol_compat.ml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCamlFormat *)
4+
(* *)
5+
(* Copyright (c) Facebook, Inc. and its affiliates. *)
6+
(* *)
7+
(* This source code is licensed under the MIT license found in *)
8+
(* the LICENSE file in the root directory of this source tree. *)
9+
(* *)
10+
(**************************************************************************)
11+
12+
let normalize_eol ?(exclude_locs = []) ~line_endings s =
13+
let buf = Buffer.create (String.length s) in
14+
let add_cr n = Buffer.add_string buf (String.make n '\r') in
15+
let rec normalize_segment ~seen_cr i stop =
16+
if i = stop then add_cr seen_cr
17+
else
18+
match s.[i] with
19+
| '\r' -> normalize_segment ~seen_cr:(seen_cr + 1) (i + 1) stop
20+
| '\n' ->
21+
( match line_endings with
22+
| `Crlf -> Buffer.add_char buf '\r'
23+
| `Lf -> () ) ;
24+
Buffer.add_char buf '\n' ;
25+
normalize_segment ~seen_cr:0 (i + 1) stop
26+
| c ->
27+
add_cr seen_cr ;
28+
Buffer.add_char buf c ;
29+
normalize_segment ~seen_cr:0 (i + 1) stop
30+
in
31+
let rec loop locs i =
32+
match locs with
33+
| [] ->
34+
normalize_segment ~seen_cr:0 i (String.length s) ;
35+
Buffer.contents buf
36+
| (start, stop) :: xs ->
37+
normalize_segment ~seen_cr:0 i start ;
38+
Buffer.add_substring buf s ~pos:start ~len:(stop - start) ;
39+
loop xs stop
40+
in
41+
loop exclude_locs 0

lib/Eol_compat.mli

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCamlFormat *)
4+
(* *)
5+
(* Copyright (c) Facebook, Inc. and its affiliates. *)
6+
(* *)
7+
(* This source code is licensed under the MIT license found in *)
8+
(* the LICENSE file in the root directory of this source tree. *)
9+
(* *)
10+
(**************************************************************************)
11+
12+
val normalize_eol :
13+
?exclude_locs:(int * int) list
14+
-> line_endings:[`Crlf | `Lf]
15+
-> string
16+
-> string

lib/Toplevel_lexer.mll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ open Migrate_ast
1616
let newline lexbuf = Lexing.new_line lexbuf
1717
}
1818

19-
let eol = '\n'
19+
let eol = ('\013'* '\010')
2020
let ws = ' ' | '\t' | eol
2121

2222
rule token = parse
@@ -42,11 +42,11 @@ and phrase buf = parse
4242
| eof {
4343
let msg = "a toplevel phrase must end with `;;`." in
4444
raise (Syntaxerr.Error (Expecting (Location.curr lexbuf, msg))) }
45-
| (("\n"* "\n") as nl) (" " | "\t")
46-
{ for _ = 1 to (String.length nl) do
47-
newline lexbuf
45+
| ((eol* eol) as nl) (" " | "\t")
46+
{ for _ = 1 to (Base.String.count ~f:(Char.equal '\n') nl) do
47+
newline lexbuf;
48+
Buffer.add_char buf '\n'
4849
done;
49-
Buffer.add_string buf nl;
5050
phrase buf lexbuf }
5151
| ";;" { Buffer.add_string buf ";;"; Buffer.contents buf }
5252
| _ as c { Buffer.add_char buf c; phrase buf lexbuf }

lib/Translation_unit.ml

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -448,35 +448,6 @@ let parse_result ?disable_w50 f fragment conf ~source ~input_name =
448448
| exception exn -> Error (Error.Invalid_source {exn; input_name})
449449
| parsed -> Ok parsed
450450

451-
let normalize_eol ~strlocs ~line_endings s =
452-
let buf = Buffer.create (String.length s) in
453-
let add_cr n = Buffer.add_string buf (String.init n ~f:(fun _ -> '\r')) in
454-
let rec normalize_segment ~seen_cr i stop =
455-
if i = stop then add_cr seen_cr
456-
else
457-
match s.[i] with
458-
| '\r' -> normalize_segment ~seen_cr:(seen_cr + 1) (i + 1) stop
459-
| '\n' ->
460-
Buffer.add_string buf
461-
(match line_endings with `Crlf -> "\r\n" | `Lf -> "\n") ;
462-
normalize_segment ~seen_cr:0 (i + 1) stop
463-
| c ->
464-
add_cr seen_cr ;
465-
Buffer.add_char buf c ;
466-
normalize_segment ~seen_cr:0 (i + 1) stop
467-
in
468-
let rec loop locs i =
469-
match locs with
470-
| [] ->
471-
normalize_segment ~seen_cr:0 i (String.length s) ;
472-
Buffer.contents buf
473-
| (start, stop) :: xs ->
474-
normalize_segment ~seen_cr:0 i start ;
475-
Buffer.add_substring buf s ~pos:start ~len:(stop - start) ;
476-
loop xs stop
477-
in
478-
loop strlocs 0
479-
480451
let parse_and_format (type a b) (fg : a Extended_ast.t)
481452
(std_fg : b Std_ast.t) ?output_file ~input_name ~source (conf : Conf.t) =
482453
Location.input_name := input_name ;
@@ -493,7 +464,7 @@ let parse_and_format (type a b) (fg : a Extended_ast.t)
493464
format fg std_fg ?output_file ~input_name ~prev_source:source ~parsed
494465
~std_parsed conf
495466
in
496-
Ok (normalize_eol ~strlocs ~line_endings formatted)
467+
Ok (Eol_compat.normalize_eol ~exclude_locs:strlocs ~line_endings formatted)
497468

498469
let parse_and_format = function
499470
| Syntax.Structure -> parse_and_format Structure Structure

test/cli/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
(deps %{bin:ocamlformat}))
44

55
(cram
6-
(applies_to large_string)
6+
(applies_to large_string conf removed_option repl_file_errors)
77
(enabled_if
88
(<> %{os_type} Win32)))

test/failing/dune

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
(deps
55
(source_tree .))
66
(package ocamlformat)
7+
(enabled_if
8+
(<> %{os_type} Win32))
79
(action
810
(with-stdout-to
911
dune.inc.gen
@@ -12,5 +14,7 @@
1214
(rule
1315
(alias runtest)
1416
(package ocamlformat)
17+
(enabled_if
18+
(<> %{os_type} Win32))
1519
(action
1620
(diff dune.inc dune.inc.gen)))

test/passing/dune

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
(deps
55
(source_tree .))
66
(package ocamlformat)
7+
(enabled_if
8+
(<> %{os_type} Win32))
79
(action
810
(with-stdout-to
911
dune.inc.gen
@@ -12,5 +14,7 @@
1214
(rule
1315
(alias runtest)
1416
(package ocamlformat)
17+
(enabled_if
18+
(<> %{os_type} Win32))
1519
(action
1620
(diff dune.inc dune.inc.gen)))

0 commit comments

Comments
 (0)