Skip to content

Commit

Permalink
Updates, small fixes, Linux build
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Grondin committed Aug 9, 2020
1 parent 7a4155c commit b26226c
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 26 deletions.
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Dockerfile
**/.DS_Store
.vscode
_opam/
_build/
**/.merlin
vue/
src/flow_parser
src/prototype
*.strings
*.exe
*.mac
*.linux
strings/
flow/
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ vue/
src/flow_parser
src/prototype
*.strings
strings.exe
*.exe
*.mac
*.linux
strings/
flow/
38 changes: 38 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Local development

### Setup
From the root of the repo:
```bash
opam switch create . ocaml-variants.4.10.0+flambda --deps-only

git clone --branch v0.120.1 --depth 1 [email protected]:facebook/flow.git flow
ln -s "$(pwd)/flow/src/parser" src/flow_parser

# MacOS
sed -i '' 's/Pervasives/Stdlib/g' flow/src/parser/parser_flow.ml
# Linux
sed -i 's/Pervasives/Stdlib/g' flow/src/parser/parser_flow.ml
```

### MacOS - Build & Run
```bash
dune build src/cli/strings.exe && cp _build/default/src/cli/strings.exe strings.mac && strip strings.mac

./strings.mac ../group-income-simple/
```

### Docker (Linux) - Build & Run
```bash
docker build . -t strings:latest
STRINGS_CID="$(docker create strings:latest)"
docker cp "$STRINGS_CID":/app/strings.exe strings.linux
docker rm "$STRINGS_CID"

# Trying it on Ubuntu 18.04
docker run -it --rm \
-v "$(pwd):/app" \
-v "$(realpath "$(pwd)/../group-income-simple"):/repo" \
-w /repo \
ubuntu:18.04
# Then run: '/app/strings.linux .'
```
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM ocaml/opam2:debian-8-opam
WORKDIR /home/opam/opam-repository

RUN sudo apt-get update \
&& sudo apt-get install -y m4 pkg-config libev-dev \
&& git pull origin master \
&& opam-sandbox-disable \
&& opam init -k git -a /home/opam/opam-repository --bare \
&& opam init --bare \
&& opam switch create 4.10 4.10.0+flambda \
&& opam switch 4.10 \
&& opam install -y opam-depext

RUN opam repository set-url default https://opam.ocaml.org \
&& opam update \
&& OPAMYES=1 opam install core \
&& opam clean

WORKDIR /app

COPY strings.opam .

RUN OPAMYES=1 opam install . --deps-only

RUN sudo chown -R opam /app \
&& git clone --branch v0.120.1 --depth 1 https://github.com/facebook/flow.git flow

COPY . .

ENV DUNE_PROFILE release

RUN sudo chown -R opam /app \
&& ln -s "$(pwd)/flow/src/parser" src/flow_parser \
&& sed -i 's/Pervasives/Stdlib/g' flow/src/parser/parser_flow.ml \
&& opam exec -- dune build src/cli/strings.exe \
&& cp /app/_build/default/src/cli/strings.exe . \
&& chmod 755 strings.exe \
&& strip strings.exe
9 changes: 0 additions & 9 deletions Makefile

This file was deleted.

9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ Place it at the root of the repository.

Simply run it before submitting a Pull Request!
```sh
./strings.exe frontend
./strings.mac frontend
```

At the moment only MacOS (Mojave and later) is supported.
**MacOS**: Mojave and later.
**Linux** and **WSL**:
- Ubuntu 14.04+
- Debian 8+
- Your distribution is supported if `ldd --version` displays `GLIBC 2.19` or later.
2 changes: 1 addition & 1 deletion src/cli/dune
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

stdlib-shims
angstrom-lwt-unix
core_kernel
core
lwt
lwt.unix
lwt_ppx
Expand Down
9 changes: 5 additions & 4 deletions src/cli/strings.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Core_kernel
open Core

let version = "1.0.2"
let version = "1.0.4"
let header = sprintf "/* Generated by okTurtles/strings v%s */\n\n" version

let () = Lwt.async_exception_hook := (fun ex ->
Expand Down Expand Up @@ -34,7 +34,8 @@ let process_file ~root (strings, count) filename =
let rec traverse ~root strings directory =
let%lwt entries = Lwt_pool.use pool (fun () -> Lwt_unix.files_of_directory directory |> Lwt_stream.to_list) in
Lwt_list.iter_p (function
| filename when String.is_prefix ~prefix:"." filename -> Lwt.return_unit
| filename when String.is_prefix ~prefix:"." filename || String.(=) filename "node_modules" ->
Lwt.return_unit
| filename ->
let path = sprintf "%s/%s" directory filename in
begin match%lwt Lwt_unix.lstat path with
Expand Down Expand Up @@ -203,7 +204,7 @@ let main args =
let () =
Lwt_main.run (
try%lwt
main (Sys.argv |> Array.to_list)
main (Sys.get_argv () |> Array.to_list)
with
| (Failure _ as ex) | (Unix.Unix_error _ as ex) | (Exn.Reraised _ as ex) ->
let message = Utils.Exception.human ex in
Expand Down
2 changes: 1 addition & 1 deletion src/cli/vue.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ let parse ~filename ic ~f =
begin match result with
| Ok (parsed, "") -> f ~filename parsed
| Ok (_, unparsed) ->
failwithf "Could not process data starting at:\n%s"
failwithf "Could not process [%s] starting at:\n%s" filename
(Yojson.Basic.to_string (`String (String.slice unparsed 0 Int.(min 20 (String.length unparsed))))) ()
| Error err -> failwithf "Syntax Error: %s" err ()
end
3 changes: 2 additions & 1 deletion src/parsing/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
(libraries
core_kernel

angstrom-lwt-unix
flow_parser

angstrom-lwt-unix
lwt
lwt_ppx
)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(library
(name utils)
(libraries
core_kernel
core
lwt
lwt.unix
lwt_ppx
Expand Down
4 changes: 2 additions & 2 deletions src/utils/utils.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Core_kernel
open Core

module Exception = struct
let human = function
Expand All @@ -9,7 +9,7 @@ module Exception = struct
"Timed out."

| Unix.Unix_error (c, n, p) ->
sprintf {s|System Error "%s" during '%s("%s")'|s} (String.uppercase (Unix.error_message c)) n p
sprintf {s|System Error "%s" during '%s("%s")'|s} (String.uppercase (Unix.Error.message c)) n p

| unknown ->
Exn.to_string unknown
Expand Down
5 changes: 2 additions & 3 deletions strings.opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

opam-version: "2.0"
maintainer: ""
maintainer: "Simon Grondin"
authors: [
"Simon Grondin"
]
Expand All @@ -18,15 +18,14 @@ depends: [

"angstrom"
"angstrom-lwt-unix"
"core"
"core" { = "v0.14.0" }
"lwt"
"lwt_ppx"
"ppx_deriving"
"ppx_deriving_yojson"
"ppx_gen_rec"
"sedlex"
"stdlib-shims"
"utop"
"yojson"
"wtf8"
]

0 comments on commit b26226c

Please sign in to comment.