Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: okTurtles/strings
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0
Choose a base ref
...
head repository: okTurtles/strings
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Aug 10, 2022

  1. Minor cleanups

    SGrondin committed Aug 10, 2022
    Copy the full SHA
    37a82a8 View commit details

Commits on Sep 3, 2022

  1. Copy the full SHA
    176aafe View commit details

Commits on Sep 7, 2022

  1. Parse .html files

    SGrondin committed Sep 7, 2022
    Copy the full SHA
    2a0da92 View commit details

Commits on Sep 10, 2022

  1. Copy the full SHA
    aa00f90 View commit details

Commits on Sep 11, 2022

  1. Project upgrades

    SGrondin committed Sep 11, 2022
    Copy the full SHA
    73014a4 View commit details
  2. Cleanups

    SGrondin committed Sep 11, 2022
    Copy the full SHA
    04021e7 View commit details
  3. Copy the full SHA
    bd39903 View commit details

Commits on Sep 14, 2022

  1. Copy the full SHA
    788dbaf View commit details

Commits on Sep 17, 2022

  1. Copy the full SHA
    f893f71 View commit details

Commits on Sep 18, 2022

  1. Build improvements

    SGrondin committed Sep 18, 2022
    Copy the full SHA
    88cfd43 View commit details
  2. Fixes and optimizations

    SGrondin committed Sep 18, 2022
    Copy the full SHA
    d68e2e6 View commit details

Commits on Jan 21, 2023

  1. Copy the full SHA
    4e87c08 View commit details
  2. C++ is a peculiar language

    SGrondin committed Jan 21, 2023
    Copy the full SHA
    695e90a View commit details
  3. 2.2.0

    SGrondin committed Jan 21, 2023
    Copy the full SHA
    7d70385 View commit details
  4. Fix Linux build

    SGrondin committed Jan 21, 2023
    Copy the full SHA
    ad38803 View commit details

Commits on Jun 6, 2023

  1. Minor updates

    SGrondin committed Jun 6, 2023
    Copy the full SHA
    bff0933 View commit details
  2. Copy the full SHA
    ce2e3d8 View commit details

Commits on Jun 8, 2023

  1. Upgrade to OCaml 5.0.0

    SGrondin committed Jun 8, 2023
    Copy the full SHA
    47a17b2 View commit details

Commits on Jun 11, 2023

  1. Port from Lwt to Eio

    SGrondin committed Jun 11, 2023
    Copy the full SHA
    c273a94 View commit details

Commits on Jun 12, 2023

  1. Angstrom_eio

    SGrondin committed Jun 12, 2023
    Copy the full SHA
    cc4601d View commit details

Commits on Jun 17, 2023

  1. Add parallelism

    SGrondin committed Jun 17, 2023
    Copy the full SHA
    b092a58 View commit details
  2. Add docs to dispatcher.mli

    SGrondin committed Jun 17, 2023
    Copy the full SHA
    b13e7d5 View commit details

Commits on Jun 18, 2023

  1. Minor refactors

    SGrondin committed Jun 18, 2023
    Copy the full SHA
    462c14a View commit details

Commits on Aug 6, 2023

  1. Finish refactor to Eio

    SGrondin committed Aug 6, 2023
    Copy the full SHA
    ddc8ca6 View commit details

Commits on Sep 9, 2023

  1. Fix result relative paths

    SGrondin committed Sep 9, 2023
    Copy the full SHA
    7a4e710 View commit details
  2. Update to Eio 0.12

    SGrondin committed Sep 9, 2023
    Copy the full SHA
    6fb4792 View commit details

Commits on Apr 6, 2024

  1. Copy the full SHA
    a9b17b8 View commit details
  2. Upgrade to Eio 1.0

    SGrondin committed Apr 6, 2024
    Copy the full SHA
    c37ba48 View commit details
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -9,11 +9,13 @@ quickjs/
src/flow_parser
src/prototype
*.strings
*.txt
*.exe
*.mac
*.mac*
*.linux
*.tar.gz
strings/
strings-backup/
lib/
flow/
test/
17 changes: 9 additions & 8 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# "Asemio Style" v1.1
# Last updated for ocamlformat 0.19.0
# "Asemio Style" v1.3
# Last updated for ocamlformat 0.25.1
ocaml-version=5.0.0

# All available options are listed.
# An option is commented out when the value matches the default
@@ -8,13 +9,11 @@
# - try out new values for existing options
# - if a default changed, see if we should follow it or not

# align-cases = false
align-constructors-decl = true
align-variants-decl = true
# assignment-operator = end-line
# break-before-in = fit-or-vertical
break-cases = all
# break-collection-expressions = fit-or-vertical
# break-colon = after
# break-fun-decl = wrap
# break-fun-sig = wrap
break-infix = fit-or-vertical
@@ -37,24 +36,26 @@ function-indent = 0
# function-indent-nested = never
if-then-else = keyword-first
# indent-after-in = 0
# indicate-multiline-delimiters = no
indicate-multiline-delimiters = space
indicate-nested-or-patterns = space
# infix-precedence = indent
# leading-nested-match-parens = false
let-and = sparse
# let-binding-indent = 2
# let-binding-spacing = compact
# let-module = compact
# line-endings = lf
margin = 106
# match-indent = 0
# match-indent-nested = never
max-indent = 3
# module-item-spacing = sparse
max-indent = 2
module-item-spacing = sparse
# nested-match = wrap
parens-ite = true
parens-tuple = multi-line-only
# parens-tuple-patterns = multi-line-only
# parse-docstrings = false
# parse-toplevel-phrases = false
# sequence-blank-line = preserve-one
# sequence-style = terminator
single-case = sparse
19 changes: 14 additions & 5 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@
### Setup
From the root of the repo:
```sh
brew install opam llvm # llvm for the linker
brew install opam libomp llvm

opam switch create . ocaml-variants.4.13.1+options --no-install
opam switch create . ocaml-variants.5.1.1+options --no-install
opam install . --deps-only -t

# Remove old Flow version
@@ -18,7 +18,7 @@ ln -s "$(pwd)/flow/src/third-party/sedlex" src/sedlex
ln -s "$(pwd)/flow/src/hack_forked/utils/collections" src/collections

# JS dependencies
npm install --no-save typescript browserify
npm install --no-save typescript browserify pug-lexer pug-parser pug-walk

# Install QuickJS
curl https://bellard.org/quickjs/quickjs-2021-03-27.tar.xz > quickjs.tar.xz
@@ -27,11 +27,20 @@ mv quickjs-2021-03-27 quickjs
cd quickjs && make && cd -
```

### MacOS - Development
```sh
# Build
dune build src/cli/strings.exe -w

# Run (separate terminal)
cp _build/default/src/cli/strings.exe strings.mac && ./strings.mac
```

### MacOS - Build & Run
```sh
# Don't forget to update the version number in [strings.ml]

DUNE_PROFILE=release rm strings.mac && dune build src/cli/strings.exe && cp _build/default/src/cli/strings.exe strings.mac && strip strings.mac
rm -f strings.mac && dune clean && DUNE_PROFILE=release dune build src/cli/strings.exe && cp _build/default/src/cli/strings.exe strings.mac && chmod 755 strings.mac && strip strings.mac

./strings.mac ../group-income-simple/
```
@@ -49,7 +58,7 @@ STRINGS_CID="$(docker create strings:latest)" \
&& docker rm "$STRINGS_CID" \
&& tar czvf strings.linux.tar.gz strings.linux lib

# Trying it on Ubuntu 18.04
# Trying it on Ubuntu 20.04
docker run -it --rm \
-v "$(pwd):/app" \
-v "$(realpath "$(pwd)/../group-income-simple"):/repo" \
31 changes: 23 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
FROM asemio/mountain-caravan:2.0.0
####################
### build_shared ###
####################
FROM asemio/mountain-caravan:2.1.0 AS build_shared
WORKDIR /app
RUN sudo apk update \
&& sudo apk upgrade \
&& sudo apk add --no-cache perl cmake npm xz patchelf

#####################
### build_quickjs ###
#####################
FROM build_shared AS build_quickjs
RUN echo '=== Installing QuickJS ===' \
&& curl https://bellard.org/quickjs/quickjs-2021-03-27.tar.xz > quickjs.tar.xz \
&& tar xvf quickjs.tar.xz && rm quickjs.tar.xz \
&& mv quickjs-2021-03-27 quickjs \
&& cd quickjs && make

#############
### build ###
#############
FROM build_shared AS build
COPY strings.opam .

ENV DUNE_PROFILE release
@@ -14,14 +31,12 @@ RUN opam update \
RUN echo '=== Installing Flow ===' \
&& git clone --branch v0.183.1 --depth 1 https://github.com/facebook/flow.git flow

RUN echo '=== Installing TypeScript ===' \
&& npm install --no-save typescript browserify
RUN echo '=== Installing JS dependencies ===' \
&& npm install --no-save typescript browserify pug-lexer pug-parser pug-walk

RUN echo '=== Installing QuickJS ===' \
&& curl https://bellard.org/quickjs/quickjs-2021-03-27.tar.xz > quickjs.tar.xz \
&& tar xvf quickjs.tar.xz && rm quickjs.tar.xz \
&& mv quickjs-2021-03-27 quickjs \
&& cd quickjs && make && cd -
COPY --from=build_quickjs /app/quickjs/libquickjs.a /app/quickjs/libquickjs.a
COPY --from=build_quickjs /app/quickjs/quickjs.h /app/quickjs/quickjs.h
COPY --from=build_quickjs /app/quickjs/qjsc /app/quickjs/qjsc

COPY src src
COPY dune dune
2 changes: 1 addition & 1 deletion dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(data_only_dirs node_modules)
(data_only_dirs node_modules quickjs)
(env
(dev
(flags (:standard -warn-error -A))
3 changes: 2 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
(lang dune 2.0)
(lang dune 2.8)
(name strings)
(use_standard_c_and_cxx_flags true)
8 changes: 4 additions & 4 deletions src/cli/dune
Original file line number Diff line number Diff line change
@@ -6,16 +6,16 @@
utils

stdlib-shims
angstrom-lwt-unix
core
lwt
lwt.unix
core_unix
core_unix.command_unix
eio_main
ppx_deriving_yojson.runtime
)
(preprocess (pps
ppx_jane
ppx_deriving_yojson
))
(modes exe)
(link_flags (:include link_flags.%{system}.dune))
(link_flags (:include link_flags.%{system}.%{profile}.dune))
)
121 changes: 121 additions & 0 deletions src/cli/generate.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
open! Core
open Eio.Std

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

let fmt s = Yojson.Basic.to_string (`String s)

let json_pair left right first =
sprintf "%s\n %s: %s"
( if !first
then (
first := false;
"" )
else "," )
left right

let write_english ~fs ~stdout ~version ~outdir english =
let time = Utils.Timing.start () in
let path_strings = Filename.concat outdir "english.strings" in
let path_json = Filename.concat outdir "english.json" in
let first = ref true in
Switch.run (fun sw ->
let file_strings =
Eio.Path.open_out ~sw ~create:Utils.Io.flags Eio.Path.(fs / outdir / "english.strings")
in
let file_json =
Eio.Path.open_out ~sw ~create:Utils.Io.flags Eio.Path.(fs / outdir / "english.json")
in
let module W = Eio.Buf_write in
W.with_flow file_strings @@ fun w_strings ->
W.with_flow file_json @@ fun w_json ->
(* Write headers of both *)
W.string w_strings (header ~version);
W.char w_json '{';
(* Switch to a map to preserve order as much as possible and therefore reduce merge conflicts *)
let map =
Hashtbl.fold english ~init:String.Map.empty ~f:(fun ~key ~data acc -> Map.set acc ~key ~data)
in
Map.iteri map ~f:(fun ~key ~data ->
let fmt_key = fmt key in
W.string w_strings (sprintf "/* %s */\n%s = %s;\n\n" data fmt_key fmt_key);
W.string w_json (json_pair fmt_key fmt_key first) );
W.string w_json "\n}\n" );

Eio.Flow.copy_string
(sprintf
!"✅ [%{Int63}ms] Generated '%s' and '%s' with:\n- %d unique strings\n\n"
(time `Stop) path_strings path_json (Hashtbl.length english) )
stdout

let write_other ~fs ~stdout ~version ~outdir ~language english other =
let time = Utils.Timing.start () in
let path_strings = Filename.concat outdir (sprintf "%s.strings" language) in
let path_json = Filename.concat outdir (sprintf "%s.json" language) in
let n_left, n_right, n_both =
Switch.run @@ fun sw ->
let file_strings =
Eio.Path.open_out ~sw ~create:Utils.Io.flags Eio.Path.(fs / outdir / sprintf "%s.strings" language)
in
let file_json =
Eio.Path.open_out ~sw ~create:Utils.Io.flags Eio.Path.(fs / outdir / sprintf "%s.json" language)
in
let module W = Eio.Buf_write in
W.with_flow file_strings @@ fun w_strings ->
W.with_flow file_json @@ fun w_json ->
let english_only = ref String.Map.empty in
let other_only = ref String.Map.empty in
let both = ref String.Map.empty in
let add_entry map_ref ~line_strings ~line_json =
map_ref := Map.set !map_ref ~key:line_strings ~data:line_json;
None
in
let missing_translation key x =
let fmt_key = fmt key in
let line_strings = sprintf "/* MISSING TRANSLATION - %s */\n%s = %s;\n\n" x fmt_key fmt_key in
add_entry english_only ~line_strings ~line_json:(fmt_key, fmt_key)
in
let _table =
Hashtbl.merge english other ~f:(fun ~key -> function
| `Left x -> missing_translation key x
| `Both (x, y) when String.(key = y) -> missing_translation key x
| `Both (x, y) ->
let fmt_key = fmt key in
let fmt_y = fmt y in
let line_strings = sprintf "/* %s */\n%s = %s;\n\n" x fmt_key fmt_y in
add_entry both ~line_strings ~line_json:(fmt_key, fmt_y)
| `Right y when String.(key = y) -> None
| `Right y ->
(* No need to write "deprecated translations" to JSON *)
let line_strings = sprintf "/* Not currently used */\n%s = %s;\n\n" (fmt key) (fmt y) in
add_entry other_only ~line_strings ~line_json:() )
in
let first = ref true in
(* Write headers *)
W.string w_strings (header ~version);
W.char w_json '{';
let write_pairs map =
Map.fold map ~init:0 ~f:(fun ~key:line_strings ~data:(x, y) acc ->
W.string w_strings line_strings;
W.string w_json (json_pair x y first);
acc + 1 )
in
let n_left = write_pairs !english_only in
let n_both = write_pairs !both in
let n_right =
Map.fold !other_only ~init:0 ~f:(fun ~key:line_strings ~data:() acc ->
W.string w_strings line_strings;
acc + 1 )
in
W.string w_json "\n}\n";
n_left, n_right, n_both
in

Eio.Flow.copy_string
(sprintf
!"✅ [%{Int63}ms] Generated '%s' and '%s' with:\n\
- %d new strings\n\
- %d existing strings\n\
- %d unused strings\n\n"
(time `Stop) path_strings path_json n_left n_both n_right )
stdout
File renamed without changes.
8 changes: 8 additions & 0 deletions src/cli/link_flags.macosx.dev.dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; mold (requires `mold`) fastest
; (-cclib -fuse-ld=mold -cc clang++)

; llvm lld (requires `llvm`) 20% faster than the default
(-cclib -fuse-ld=/usr/local/opt/llvm/bin/ld64.lld -cc clang++)

; system default
; ()
8 changes: 0 additions & 8 deletions src/cli/link_flags.macosx.dune

This file was deleted.

1 change: 1 addition & 0 deletions src/cli/link_flags.macosx.release.dune
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
()
Loading