Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject a source identifer into moc #1631

Merged
merged 7 commits into from
Jun 21, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ let ocaml_exe = name: bin:
buildInputs = commonBuildInputs staticpkgs;

buildPhase = ''
patchShebangs .
make DUNE_OPTS="--display=short --profile ${profile}" ${bin}
'';

Expand Down Expand Up @@ -312,6 +313,7 @@ rec {
nixpkgs.nodejs-10_x
];
buildPhase = ''
patchShebangs .
make ${n}.js
'';
installPhase = ''
Expand Down
39 changes: 26 additions & 13 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ DESER_TARGET = _build/default/exes/deser.exe

DUNE_OPTS ?=

ALL_TARGETS = $(MO_IDE_TARGET) $(MO_LD_TARGET) $(MO_DOC_TARGET) $(MOC_TARGET) $(MOC_JS_TARGET) $(DIDC_TARGET) $(DESER_TARGET) ($DIDC_JS_TARGET)
ALL_TARGETS = $(MO_IDE_TARGET) $(MO_LD_TARGET) $(MO_DOC_TARGET) $(MOC_TARGET) $(MOC_JS_TARGET) $(DIDC_TARGET) $(DESER_TARGET) $(DIDC_JS_TARGET)

.PHONY: all clean moc mo-doc mo-ide mo-ld moc.js didc deser unit-tests didc.js

# let make update check this file every time
SOURCE_ID = source_id/source_id.ml

# This targets is spelled out so that `make`
# only invokes `dune` once, much faster
all: grammar
all: $(SOURCE_ID) grammar
dune build $(DUNE_OPTS) $(ALL_TARGETS)
@ln -fs $(MOC_TARGET) moc
@ln -fs $(MO_IDE_TARGET) mo-ide
Expand All @@ -28,47 +31,58 @@ all: grammar
@ln -fs $(MOC_JS_TARGET) moc.js
@ln -fs $(DIDC_TARGET) didc
@ln -fs $(DESER_TARGET) deser
@ln -fs $(DIDC_JS_TARGET) didc.js

moc:
moc: $(SOURCE_ID)
dune build $(DUNE_OPTS) $(MOC_TARGET)
@ln -fs $(MOC_TARGET) moc

mo-ide:
mo-ide: $(SOURCE_ID)
dune build $(DUNE_OPTS) $(MO_IDE_TARGET)
@ln -fs $(MO_IDE_TARGET) mo-ide

mo-ld:
mo-ld: $(SOURCE_ID)
dune build $(DUNE_OPTS) $(MO_LD_TARGET)
@ln -fs $(MO_LD_TARGET) mo-ld

mo-doc:
mo-doc: $(SOURCE_ID)
dune build $(DUNE_OPTS) $(MO_DOC_TARGET)
@ln -fs $(MO_DOC_TARGET) mo-doc

moc.js:
moc.js: $(SOURCE_ID)
dune build $(DUNE_OPTS) $(MOC_JS_TARGET)
@ln -fs $(MOC_JS_TARGET) moc.js

didc.js:
didc.js: $(SOURCE_ID)
dune build $(DUNE_OPTS) $(DIDC_JS_TARGET)
@ln -fs $(DIDC_JS_TARGET) didc.js

didc:
didc: $(SOURCE_ID)
dune build $(DUNE_OPTS) $(DIDC_TARGET)
@ln -fs $(DIDC_TARGET) didc

deser:
deser: $(SOURCE_ID)
dune build $(DUNE_OPTS) $(DESER_TARGET)
@ln -fs $(DESER_TARGET) deser

.PHONY: $(SOURCE_ID)

# only actually touch the file if changed
$(SOURCE_ID):
source_id/gen.sh

unit-tests:
dune runtest $(DUNE_OPTS)

format:
ocamlformat --inplace docs/*.mli docs/*.ml languageServer/*.ml languageServer/*.mli
ocamlformat --inplace \
docs/*.mli \
docs/*.ml \
languageServer/*.ml \
languageServer/*.mli

clean:
rm -f moc mo-ide mo-ld moc.js didc deser
rm -f moc mo-ide mo-ld moc.js didc deser $(SOURCE_ID)
dune clean

test: $(NAME)
Expand All @@ -78,7 +92,6 @@ test: $(NAME)
test-quick: $(NAME)
make -C ../test MOC=$(MOC) quick


grammar: ../doc/modules/language-guide/examples/grammar.txt

../doc/modules/language-guide/examples/grammar.txt: mo_frontend/parser.mly gen-grammar/gen-grammar.sh gen-grammar/grammar.sed
Expand Down
3 changes: 1 addition & 2 deletions src/exes/deser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,7 @@ end
(* CLI *)

let name = "deser"
let version = "0.1"
let banner = "Interface Description Language (IDL) " ^ version ^ " message dumper"
let banner = "Candid toolkit (revision " ^ Source_id.id ^ ")"
let usage = "Usage: " ^ name ^ " [option] [file ...]"

let mode = ref Nary
Expand Down
3 changes: 1 addition & 2 deletions src/exes/didc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ open Idllib
open Printf

let name = "didc"
let version = "0.1"
let banner = "Interface Description Language (IDL) " ^ version ^ " interpreter"
let banner = "Candid compiler (revision " ^ Source_id.id ^ ")"
let usage = "Usage: " ^ name ^ " [option] [file ...]"


Expand Down
6 changes: 3 additions & 3 deletions src/exes/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(executable
(name moc)
(modules moc)
(libraries profiler pipeline)
(libraries profiler pipeline source_id)
)
(executable
(name mo_ide)
Expand All @@ -21,10 +21,10 @@
(executable
(name didc)
(modules didc)
(libraries idllib)
(libraries idllib source_id)
)
(executable
(name deser)
(modules deser)
(libraries stdio num)
(libraries stdio num source_id)
)
3 changes: 1 addition & 2 deletions src/exes/moc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ open Mo_config
open Printf

let name = "moc"
let version = "0.1"
let banner = "Motoko " ^ version ^ " interpreter"
let banner = "Motoko compiler (revision " ^ Source_id.id ^ ")"
let usage = "Usage: " ^ name ^ " [option] [file ...]"


Expand Down
1 change: 1 addition & 0 deletions src/source_id/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source_id.ml
1 change: 1 addition & 0 deletions src/source_id/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(library (name source_id))
18 changes: 18 additions & 0 deletions src/source_id/gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

cd "$(dirname "$BASH_SOURCE")"

file="source_id.ml"

if [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ]
then echo "let id = \"$(git describe --always --dirty)\"" > $file.tmp
elif [ -n "$out" ]
then echo "let id = \"$(echo $out|cut -d/ -f4|cut -d- -f1|fold -w8 | paste -sd'-' -)\"" > $file.tmp
else echo "let id = \"unidentified version\"" > $file.tmp
fi
if [ ! -e $file ] || ! cmp -s $file.tmp $file
then mv $file.tmp $file
else rm -f $file.tmp
fi


2 changes: 1 addition & 1 deletion test/repl/ok/double-import.stdout.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Motoko 0.1 interpreter
Motoko compiler (revision XXX)
-- Parsing stdin:
> -- Parsing lib/empty.mo:
-- Checking empty.mo:
Expand Down
2 changes: 1 addition & 1 deletion test/repl/ok/file-and-repl.stdout.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Motoko 0.1 interpreter
Motoko compiler (revision XXX)
-- Parsing /dev/fd/63:
-- Checking /dev/fd/63:
-- Definedness /dev/fd/63:
Expand Down
2 changes: 1 addition & 1 deletion test/repl/ok/outrange-int-nat.stdout.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Motoko 0.1 interpreter
Motoko compiler (revision XXX)
> let Prim : module {...}
> +127 : Int8
> prim:___: execution error, numeric overflow
Expand Down
2 changes: 1 addition & 1 deletion test/repl/ok/stateful.stdout.ok
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Motoko 0.1 interpreter
Motoko compiler (revision XXX)
> let x : Nat = 42
> > > >
2 changes: 1 addition & 1 deletion test/repl/ok/triangle-import.stdout.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Motoko 0.1 interpreter
Motoko compiler (revision XXX)
-- Parsing stdin:
> -- Parsing lib/b.mo:
-- Parsing lib/c.mo:
Expand Down
2 changes: 1 addition & 1 deletion test/repl/ok/type-lub-repl.stdout.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Motoko 0.1 interpreter
Motoko compiler (revision XXX)
> [null, ?42, ?(-25)] : [(?Int)]
> [null, null] : [Null]
> [{a = 42}, {b = 42}] : [{}]
Expand Down
2 changes: 1 addition & 1 deletion test/repl/ok/variant-shorthand.stdout.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Motoko 0.1 interpreter
Motoko compiler (revision XXX)
> #bar : {#bar}
> #foo(#bar) : {#foo : {#bar}}
> [#Monday, #Tuesday, #Wednesday, #Thursday, #Friday, #Saturday, #Sunday] : [{#Friday; #Monday; #Saturday; #Sunday; #Thursday; #Tuesday; #Wednesday}]
Expand Down
1 change: 1 addition & 0 deletions test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function normalize () {
sed 's/trap at 0x[a-f0-9]*/trap at 0x___:/g' |
sed 's/source location: @[a-f0-9]*/source location: @___:/g' |
sed 's/Ignore Diff:.*/Ignore Diff: (ignored)/ig' |
sed 's/compiler (revision .*)/compiler (revision XXX)/ig' |
cat > $1.norm
mv $1.norm $1
fi
Expand Down