diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6d3b35e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +Dockerfile +**/.DS_Store +.vscode +_opam/ +_build/ +**/.merlin +vue/ +src/flow_parser +src/prototype +*.strings +*.exe +*.mac +*.linux +strings/ +flow/ diff --git a/.gitignore b/.gitignore index e023786..6a06a6f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,8 @@ vue/ src/flow_parser src/prototype *.strings -strings.exe +*.exe +*.mac +*.linux strings/ +flow/ diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 0000000..1228b74 --- /dev/null +++ b/DEVELOPMENT.md @@ -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 git@github.com: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 .' +``` diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5562b22 --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/Makefile b/Makefile deleted file mode 100644 index 18c6da7..0000000 --- a/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -SHELL := /usr/bin/env bash - -build: - opam exec -- dune build src/cli/strings.exe - cp _build/default/src/cli/strings.exe . - strip strings.exe - -clean: - opam exec -- dune clean diff --git a/README.md b/README.md index 2676ed8..d23648b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/cli/dune b/src/cli/dune index 1836698..92649cc 100644 --- a/src/cli/dune +++ b/src/cli/dune @@ -6,7 +6,7 @@ stdlib-shims angstrom-lwt-unix - core_kernel + core lwt lwt.unix lwt_ppx diff --git a/src/cli/strings.ml b/src/cli/strings.ml index 0969ba3..c51eb74 100644 --- a/src/cli/strings.ml +++ b/src/cli/strings.ml @@ -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 -> @@ -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 @@ -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 diff --git a/src/cli/vue.ml b/src/cli/vue.ml index 6f79584..b38e8c0 100644 --- a/src/cli/vue.ml +++ b/src/cli/vue.ml @@ -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 diff --git a/src/parsing/dune b/src/parsing/dune index 74781b0..e9c04ba 100644 --- a/src/parsing/dune +++ b/src/parsing/dune @@ -3,8 +3,9 @@ (libraries core_kernel - angstrom-lwt-unix flow_parser + + angstrom-lwt-unix lwt lwt_ppx ) diff --git a/src/utils/dune b/src/utils/dune index f1b328b..0ebb218 100644 --- a/src/utils/dune +++ b/src/utils/dune @@ -1,7 +1,7 @@ (library (name utils) (libraries - core_kernel + core lwt lwt.unix lwt_ppx diff --git a/src/utils/utils.ml b/src/utils/utils.ml index 19791cb..c7db2d4 100644 --- a/src/utils/utils.ml +++ b/src/utils/utils.ml @@ -1,4 +1,4 @@ -open Core_kernel +open Core module Exception = struct let human = function @@ -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 diff --git a/strings.opam b/strings.opam index ed198a8..060a9b1 100644 --- a/strings.opam +++ b/strings.opam @@ -1,6 +1,6 @@ opam-version: "2.0" -maintainer: "" +maintainer: "Simon Grondin" authors: [ "Simon Grondin" ] @@ -18,7 +18,7 @@ depends: [ "angstrom" "angstrom-lwt-unix" - "core" + "core" { = "v0.14.0" } "lwt" "lwt_ppx" "ppx_deriving" @@ -26,7 +26,6 @@ depends: [ "ppx_gen_rec" "sedlex" "stdlib-shims" - "utop" "yojson" "wtf8" ] \ No newline at end of file