From 28c3353e499a1abfe33a58131d483f953ee0929d Mon Sep 17 00:00:00 2001 From: Vasilis Papavasileiou Date: Mon, 12 Dec 2016 17:54:21 +0100 Subject: [PATCH 1/8] Add -reason flag to tools --- src/tools/eliomc.ml | 3 +++ src/tools/eliomdep.ml | 3 +++ src/tools/eliomdoc.ml | 3 +++ src/tools/utils.ml | 12 ++++++++++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/tools/eliomc.ml b/src/tools/eliomc.ml index 23b5c9a36f..4633789e6d 100644 --- a/src/tools/eliomc.ml +++ b/src/tools/eliomc.ml @@ -423,6 +423,9 @@ let process_option () = if !i+1 >= Array.length Sys.argv then usage (); process_eliom ~impl_intf:`Impl Sys.argv.(!i+1); i := !i+2 + | "-reason" -> + use_refmt := true; + incr i | arg when Filename.check_suffix arg ".mli" -> process_ocaml ~impl_intf:`Intf arg; incr i diff --git a/src/tools/eliomdep.ml b/src/tools/eliomdep.ml index 59006a5713..47f3386d50 100644 --- a/src/tools/eliomdep.ml +++ b/src/tools/eliomdep.ml @@ -275,6 +275,9 @@ let process_option () = else compile_eliom ~impl_intf:`Impl arg; i := !i+2 + | "-reason" -> + use_refmt := true; + incr i | arg when Filename.check_suffix arg ".mli" -> if not (do_sort ()) then compile_intf arg; diff --git a/src/tools/eliomdoc.ml b/src/tools/eliomdoc.ml index 07b7bcd89b..83b505c89d 100644 --- a/src/tools/eliomdoc.ml +++ b/src/tools/eliomdoc.ml @@ -179,6 +179,9 @@ let process_option () = let arg = Sys.argv.(!i+1) in compile_eliom ~impl_intf:`Impl arg; i := !i+2 + | "-reason" -> + use_refmt := true; + incr i | arg when Filename.check_suffix arg ".mli" -> compile_intf arg; incr i diff --git a/src/tools/utils.ml b/src/tools/utils.ml index b1549e1c3f..178c89a422 100644 --- a/src/tools/utils.ml +++ b/src/tools/utils.ml @@ -71,6 +71,8 @@ let default_server_types_ext = let build_dir : string ref = ref "" let type_dir : string ref = ref default_type_dir +let use_refmt = ref false + let get_kind k = match k with | Some k -> k @@ -362,6 +364,12 @@ let get_ppopts ~impl_intf file = type_opt impl_intf file @ !ppopt let preprocess_opt ?(ocaml = false) ?kind opts = + let refmt () = + if !use_refmt then + [ "-pp" ; "refmt -parse re -print ml" ] + else + [] + in match !pp_mode with | `Camlp4 -> let pkg = match ocaml, simplify_kind ?kind () with @@ -372,14 +380,14 @@ let preprocess_opt ?(ocaml = false) ?kind opts = in [ "-pp"; get_pp pkg ^ " " ^ String.concat " " opts ] | `Ppx when ocaml -> - [] + refmt () | `Ppx -> let pkg = match simplify_kind ?kind () with | `Client -> "eliom.ppx.client" | `Server -> "eliom.ppx.server" | `Types -> "eliom.ppx.type" in - [ "-ppx"; get_ppx pkg ^ " " ^ String.concat " " opts ] + refmt () @ [ "-ppx"; get_ppx pkg ^ " " ^ String.concat " " opts ] (** Process *) From 48fab6025d74d08bcbf150d2aca33d4def364b98 Mon Sep 17 00:00:00 2001 From: Vasilis Papavasileiou Date: Mon, 12 Dec 2016 17:58:22 +0100 Subject: [PATCH 2/8] Add a basic.reason template --- pkg/distillery/basic.reason/Makefile | 240 ++++++++++++++++++ pkg/distillery/basic.reason/Makefile.options | 64 +++++ .../basic.reason/PROJECT_NAME.conf.in | 28 ++ .../basic.reason/PROJECT_NAME.eliom | 28 ++ pkg/distillery/basic.reason/README | 82 ++++++ .../basic.reason/static!css!PROJECT_NAME.css | 3 + 6 files changed, 445 insertions(+) create mode 100644 pkg/distillery/basic.reason/Makefile create mode 100644 pkg/distillery/basic.reason/Makefile.options create mode 100644 pkg/distillery/basic.reason/PROJECT_NAME.conf.in create mode 100644 pkg/distillery/basic.reason/PROJECT_NAME.eliom create mode 100644 pkg/distillery/basic.reason/README create mode 100644 pkg/distillery/basic.reason/static!css!PROJECT_NAME.css diff --git a/pkg/distillery/basic.reason/Makefile b/pkg/distillery/basic.reason/Makefile new file mode 100644 index 0000000000..f4d8fa2507 --- /dev/null +++ b/pkg/distillery/basic.reason/Makefile @@ -0,0 +1,240 @@ + +##---------------------------------------------------------------------- +## DISCLAIMER +## +## This file contains the rules to make an Eliom project. The project is +## configured through the variables in the file Makefile.options. +##---------------------------------------------------------------------- + +include Makefile.options + +##---------------------------------------------------------------------- +## Internals + +## Required binaries +ELIOMC := eliomc -reason -ppx +ELIOMOPT := eliomopt -reason -ppx +JS_OF_ELIOM := js_of_eliom -reason -ppx +ELIOMDEP := eliomdep +OCSIGENSERVER := ocsigenserver +OCSIGENSERVER.OPT := ocsigenserver.opt + +## Where to put intermediate object files. +## - ELIOM_{SERVER,CLIENT}_DIR must be distinct +## - ELIOM_CLIENT_DIR must not be the local dir. +## - ELIOM_SERVER_DIR could be ".", but you need to +## remove it from the "clean" rules... +export ELIOM_SERVER_DIR := _server +export ELIOM_CLIENT_DIR := _client +export ELIOM_TYPE_DIR := _server +DEPSDIR := _deps + +ifeq ($(DEBUG),yes) + GENERATE_DEBUG ?= -g + RUN_DEBUG ?= "-v" + DEBUG_JS ?= -jsopt -pretty -jsopt -noinline -jsopt -debuginfo +endif + +##---------------------------------------------------------------------- +## General + +.PHONY: all byte opt +all: byte opt +byte opt:: $(TEST_PREFIX)$(ELIOMSTATICDIR)/${PROJECT_NAME}.js +byte opt:: $(TEST_PREFIX)$(ETCDIR)/$(PROJECT_NAME).conf +byte opt:: $(TEST_PREFIX)$(ETCDIR)/$(PROJECT_NAME)-test.conf +byte:: $(TEST_PREFIX)$(LIBDIR)/${PROJECT_NAME}.cma +opt:: $(TEST_PREFIX)$(LIBDIR)/${PROJECT_NAME}.cmxs + +DIST_DIRS = $(ETCDIR) $(DATADIR) $(LIBDIR) $(LOGDIR) $(STATICDIR) $(ELIOMSTATICDIR) $(shell dirname $(CMDPIPE)) + +##---------------------------------------------------------------------- +## Testing + +DIST_FILES = $(ELIOMSTATICDIR)/$(PROJECT_NAME).js $(LIBDIR)/$(PROJECT_NAME).cma + +.PHONY: test.byte test.opt +test.byte: $(addprefix $(TEST_PREFIX),$(ETCDIR)/$(PROJECT_NAME)-test.conf $(DIST_DIRS) $(DIST_FILES)) + $(OCSIGENSERVER) $(RUN_DEBUG) -c $< +test.opt: $(addprefix $(TEST_PREFIX),$(ETCDIR)/$(PROJECT_NAME)-test.conf $(DIST_DIRS) $(patsubst %.cma,%.cmxs, $(DIST_FILES))) + $(OCSIGENSERVER.OPT) $(RUN_DEBUG) -c $< + +$(addprefix $(TEST_PREFIX), $(DIST_DIRS)): + mkdir -p $@ + +##---------------------------------------------------------------------- +## Installing & Running + +.PHONY: install install.byte install.byte install.opt install.static install.etc install.lib install.lib.byte install.lib.opt run.byte run.opt +install: install.byte install.opt +install.byte: install.lib.byte install.etc install.static | $(addprefix $(PREFIX),$(DATADIR) $(LOGDIR) $(shell dirname $(CMDPIPE))) +install.opt: install.lib.opt install.etc install.static | $(addprefix $(PREFIX),$(DATADIR) $(LOGDIR) $(shell dirname $(CMDPIPE))) +install.lib: install.lib.byte install.lib.opt +install.lib.byte: $(TEST_PREFIX)$(LIBDIR)/$(PROJECT_NAME).cma | $(PREFIX)$(LIBDIR) + install $< $(PREFIX)$(LIBDIR) +install.lib.opt: $(TEST_PREFIX)$(LIBDIR)/$(PROJECT_NAME).cmxs | $(PREFIX)$(LIBDIR) + install $< $(PREFIX)$(LIBDIR) +install.static: $(TEST_PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).js | $(PREFIX)$(STATICDIR) $(PREFIX)$(ELIOMSTATICDIR) + cp -r $(LOCAL_STATIC)/* $(PREFIX)$(STATICDIR) + [ -z $(WWWUSER) ] || chown -R $(WWWUSER) $(PREFIX)$(STATICDIR) + install $(addprefix -o ,$(WWWUSER)) $< $(PREFIX)$(ELIOMSTATICDIR) +install.etc: $(TEST_PREFIX)$(ETCDIR)/$(PROJECT_NAME).conf | $(PREFIX)$(ETCDIR) + install $< $(PREFIX)$(ETCDIR)/$(PROJECT_NAME).conf + +.PHONY: +print-install-files: + @echo $(PREFIX)$(LIBDIR) + @echo $(PREFIX)$(STATICDIR) + @echo $(PREFIX)$(ELIOMSTATICDIR) + @echo $(PREFIX)$(ETCDIR) + +$(addprefix $(PREFIX),$(ETCDIR) $(LIBDIR)): + install -d $@ +$(addprefix $(PREFIX),$(DATADIR) $(LOGDIR) $(STATICDIR) $(ELIOMSTATICDIR) $(shell dirname $(CMDPIPE))): + install $(addprefix -o ,$(WWWUSER)) -d $@ + +run.byte: + $(OCSIGENSERVER) $(RUN_DEBUG) -c ${PREFIX}${ETCDIR}/${PROJECT_NAME}.conf +run.opt: + $(OCSIGENSERVER.OPT) $(RUN_DEBUG) -c ${PREFIX}${ETCDIR}/${PROJECT_NAME}.conf + +##---------------------------------------------------------------------- +## Aux + +# Use `eliomdep -sort' only in OCaml>4 +ifeq ($(shell ocamlc -version|cut -c1),4) +eliomdep=$(shell $(ELIOMDEP) $(1) -reason -ppx -sort $(2) $(filter %.eliom %.ml,$(3)))) +else +eliomdep=$(3) +endif +objs=$(patsubst %.ml,$(1)/%.$(2),$(patsubst %.eliom,$(1)/%.$(2),$(filter %.eliom %.ml,$(3)))) +depsort=$(call objs,$(1),$(2),$(call eliomdep,$(3),$(4),$(5))) + +##---------------------------------------------------------------------- +## Config files + +FINDLIB_PACKAGES=$(patsubst %,\,$(SERVER_PACKAGES)) +EDIT_WARNING=DON\'T EDIT THIS FILE! It is generated from $(PROJECT_NAME).conf.in, edit that one, or the variables in Makefile.options +SED_ARGS := -e "/^ *%%%/d" +SED_ARGS += -e "s|%%PROJECT_NAME%%|$(PROJECT_NAME)|g" +SED_ARGS += -e "s|%%DATABASE_NAME%%|$(DATABASE_NAME)|g" +SED_ARGS += -e "s|%%DATABASE_USER%%|$(DATABASE_USER)|g" +SED_ARGS += -e "s|%%CMDPIPE%%|%%PREFIX%%$(CMDPIPE)|g" +SED_ARGS += -e "s|%%LOGDIR%%|%%PREFIX%%$(LOGDIR)|g" +SED_ARGS += -e "s|%%DATADIR%%|%%PREFIX%%$(DATADIR)|g" +SED_ARGS += -e "s|%%PERSISTENT_DATA_BACKEND%%|$(PERSISTENT_DATA_BACKEND)|g" +SED_ARGS += -e "s|%%LIBDIR%%|%%PREFIX%%$(LIBDIR)|g" +SED_ARGS += -e "s|%%WARNING%%|$(EDIT_WARNING)|g" +SED_ARGS += -e "s|%%PACKAGES%%|$(FINDLIB_PACKAGES)|g" +SED_ARGS += -e "s|%%ELIOMSTATICDIR%%|%%PREFIX%%$(ELIOMSTATICDIR)|g" +ifeq ($(DEBUG),yes) + SED_ARGS += -e "s|%%DEBUGMODE%%|\|g" +else + SED_ARGS += -e "s|%%DEBUGMODE%%||g" +endif + +LOCAL_SED_ARGS := -e "s|%%PORT%%|$(TEST_PORT)|g" +LOCAL_SED_ARGS += -e "s|%%STATICDIR%%|$(LOCAL_STATIC)|g" +LOCAL_SED_ARGS += -e "s|%%USERGROUP%%||g" +GLOBAL_SED_ARGS := -e "s|%%PORT%%|$(PORT)|g" +GLOBAL_SED_ARGS += -e "s|%%STATICDIR%%|%%PREFIX%%$(STATICDIR)|g" +ifeq ($(WWWUSER)$(WWWGROUP),) + GLOBAL_SED_ARGS += -e "s|%%USERGROUP%%||g" +else + GLOBAL_SED_ARGS += -e "s|%%USERGROUP%%|$(WWWUSER)$(WWWGROUP)|g" +endif + +$(TEST_PREFIX)${ETCDIR}/${PROJECT_NAME}.conf: ${PROJECT_NAME}.conf.in Makefile.options | $(TEST_PREFIX)$(ETCDIR) + sed $(SED_ARGS) $(GLOBAL_SED_ARGS) $< | sed -e "s|%%PREFIX%%|$(PREFIX)|g" > $@ +$(TEST_PREFIX)${ETCDIR}/${PROJECT_NAME}-test.conf: ${PROJECT_NAME}.conf.in Makefile.options | $(TEST_PREFIX)$(ETCDIR) + sed $(SED_ARGS) $(LOCAL_SED_ARGS) $< | sed -e "s|%%PREFIX%%|$(TEST_PREFIX)|g" > $@ + +##---------------------------------------------------------------------- +## Server side compilation + +SERVER_INC := ${addprefix -package ,${SERVER_PACKAGES}} + +${ELIOM_TYPE_DIR}/%.type_mli: %.eliom + ${ELIOMC} -infer ${SERVER_INC} $< + +$(TEST_PREFIX)$(LIBDIR)/$(PROJECT_NAME).cma: $(call objs,$(ELIOM_SERVER_DIR),cmo,$(SERVER_FILES)) | $(TEST_PREFIX)$(LIBDIR) + ${ELIOMC} -a -o $@ $(GENERATE_DEBUG) \ + $(call depsort,$(ELIOM_SERVER_DIR),cmo,-server,$(SERVER_INC),$(SERVER_FILES)) + +$(TEST_PREFIX)$(LIBDIR)/$(PROJECT_NAME).cmxa: $(call objs,$(ELIOM_SERVER_DIR),cmx,$(SERVER_FILES)) | $(TEST_PREFIX)$(LIBDIR) + ${ELIOMOPT} -a -o $@ $(GENERATE_DEBUG) \ + $(call depsort,$(ELIOM_SERVER_DIR),cmx,-server,$(SERVER_INC),$(SERVER_FILES)) + +%.cmxs: %.cmxa + $(ELIOMOPT) -shared -linkall -o $@ $(GENERATE_DEBUG) $< + +${ELIOM_SERVER_DIR}/%.cmi: %.mli + ${ELIOMC} -c ${SERVER_INC} $(GENERATE_DEBUG) $< + +${ELIOM_SERVER_DIR}/%.cmi: %.eliomi + ${ELIOMC} -c ${SERVER_INC} $(GENERATE_DEBUG) $< + +${ELIOM_SERVER_DIR}/%.cmo: %.ml + ${ELIOMC} -c ${SERVER_INC} $(GENERATE_DEBUG) $< +${ELIOM_SERVER_DIR}/%.cmo: %.eliom + ${ELIOMC} -c ${SERVER_INC} $(GENERATE_DEBUG) $< + +${ELIOM_SERVER_DIR}/%.cmx: %.ml + ${ELIOMOPT} -c ${SERVER_INC} $(GENERATE_DEBUG) $< +${ELIOM_SERVER_DIR}/%.cmx: %.eliom + ${ELIOMOPT} -c ${SERVER_INC} $(GENERATE_DEBUG) $< + + +##---------------------------------------------------------------------- +## Client side compilation + +CLIENT_LIBS := ${addprefix -package ,${CLIENT_PACKAGES}} +CLIENT_INC := ${addprefix -package ,${CLIENT_PACKAGES}} + +CLIENT_OBJS := $(filter %.eliom %.ml, $(CLIENT_FILES)) +CLIENT_OBJS := $(patsubst %.eliom,${ELIOM_CLIENT_DIR}/%.cmo, ${CLIENT_OBJS}) +CLIENT_OBJS := $(patsubst %.ml,${ELIOM_CLIENT_DIR}/%.cmo, ${CLIENT_OBJS}) + +$(TEST_PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).js: $(call objs,$(ELIOM_CLIENT_DIR),cmo,$(CLIENT_FILES)) | $(TEST_PREFIX)$(ELIOMSTATICDIR) + ${JS_OF_ELIOM} -o $@ $(GENERATE_DEBUG) $(CLIENT_INC) $(DEBUG_JS) \ + $(call depsort,$(ELIOM_CLIENT_DIR),cmo,-client,$(CLIENT_INC),$(CLIENT_FILES)) + +${ELIOM_CLIENT_DIR}/%.cmi: %.mli + ${JS_OF_ELIOM} -c ${CLIENT_INC} $(GENERATE_DEBUG) $< + +${ELIOM_CLIENT_DIR}/%.cmo: %.eliom + ${JS_OF_ELIOM} -c ${CLIENT_INC} $(GENERATE_DEBUG) $< +${ELIOM_CLIENT_DIR}/%.cmo: %.ml + ${JS_OF_ELIOM} -c ${CLIENT_INC} $(GENERATE_DEBUG) $< + +${ELIOM_CLIENT_DIR}/%.cmi: %.eliomi + ${JS_OF_ELIOM} -c ${CLIENT_INC} $(GENERATE_DEBUG) $< + +##---------------------------------------------------------------------- +## Dependencies + +include .depend + +.depend: $(patsubst %,$(DEPSDIR)/%.server,$(SERVER_FILES)) $(patsubst %,$(DEPSDIR)/%.client,$(CLIENT_FILES)) + cat $^ > $@ + +$(DEPSDIR)/%.server: % | $(DEPSDIR) + $(ELIOMDEP) -server -reason -ppx $(SERVER_INC) $< > $@ + +$(DEPSDIR)/%.client: % | $(DEPSDIR) + $(ELIOMDEP) -client -reason -ppx $(CLIENT_INC) $< > $@ + +$(DEPSDIR): + mkdir $@ + +##---------------------------------------------------------------------- +## Clean up + +clean: + -rm -f *.cm[ioax] *.cmxa *.cmxs *.o *.a *.annot + -rm -f *.type_mli + -rm -f ${PROJECT_NAME}.js + -rm -rf ${ELIOM_CLIENT_DIR} ${ELIOM_SERVER_DIR} + +distclean: clean + -rm -rf $(TEST_PREFIX) $(DEPSDIR) .depend diff --git a/pkg/distillery/basic.reason/Makefile.options b/pkg/distillery/basic.reason/Makefile.options new file mode 100644 index 0000000000..00a1b9e176 --- /dev/null +++ b/pkg/distillery/basic.reason/Makefile.options @@ -0,0 +1,64 @@ + +#---------------------------------------------------------------------- +# SETTINGS FOR THE ELIOM PROJECT %%%PROJECT_NAME%%% +#---------------------------------------------------------------------- + +PROJECT_NAME := %%%PROJECT_NAME%%% + +# Source files for the server +SERVER_FILES := $(wildcard *.eliomi *.eliom) +# Source files for the client +CLIENT_FILES := $(wildcard *.eliomi *.eliom) + +# OCamlfind packages for the server +SERVER_PACKAGES := lwt.ppx js_of_ocaml.deriving.ppx +# OCamlfind packages for the client +CLIENT_PACKAGES := lwt.ppx js_of_ocaml.ppx js_of_ocaml.deriving.ppx + +# Directory with files to be statically served +LOCAL_STATIC = static + +# The backend for persistent data. Can be dbm or sqlite. +# Make sure you have the following packages installed +# - *dbm* if you use dbm --> opam install dbm. +# - *sqlite3* if you use sqlite --> opam install sqlite3. +PERSISTENT_DATA_BACKEND = %%%PROJECT_DB%%% + +# Debug application (yes/no): Debugging info in compilation, +# JavaScript, ocsigenserver +DEBUG := no + +# User to run server with (make run.*) +WWWUSER := www-data +WWWGROUP := www-data + +# Port for running the server (make run.*) +PORT := 80 + +# Port for testing (make test.*) +TEST_PORT := 8080 + +# Root of installation (must end with /) +PREFIX := /usr/local/ + +# Local folder for make test.* (must end with /) +# Do not add files manually in this directory. +# It is just here to test your installation before installing in / +TEST_PREFIX := local/ + +# The installation tree (relative to $(PREFIX) when +# installing/running or $(TEST_PREFIX) when testing). +# Configuration file $(PROJECT_NAME).conf +ETCDIR := etc/${PROJECT_NAME} +# Project's library $(PROJECT_NAME).cma (cmxs) +LIBDIR := lib/${PROJECT_NAME} +# Command pipe, eg. $ echo reload > $(INSTALL_PREFIX)$(CMDPIPE) +CMDPIPE := var/run/${PROJECT_NAME}-cmd +# Ocsigenserver's logging files +LOGDIR := var/log/${PROJECT_NAME} +# Ocsigenserver's persistent data files +DATADIR := var/data/${PROJECT_NAME} +# Copy of $(LOCAL_STATIC) +STATICDIR := var/www/${PROJECT_NAME}/static +# Project's JavaScript file +ELIOMSTATICDIR := var/www/${PROJECT_NAME}/eliom diff --git a/pkg/distillery/basic.reason/PROJECT_NAME.conf.in b/pkg/distillery/basic.reason/PROJECT_NAME.conf.in new file mode 100644 index 0000000000..13a8a1fdbb --- /dev/null +++ b/pkg/distillery/basic.reason/PROJECT_NAME.conf.in @@ -0,0 +1,28 @@ +%%% This is the template for your configuration file. The %%VALUES%% below are +%%% taken from the Makefile to generate the actual configuration files. +%%% This comment will disappear. + + + + %%PORT%% + %%% Only set for running, not for testing + %%USERGROUP%% + %%LOGDIR%% + %%DATADIR%% + utf-8 + %%% Only set when debugging + %%DEBUGMODE%% + %%CMDPIPE%% + + + + %%% This will include the packages defined as SERVER_PACKAGES in your Makefile: + %%PACKAGES%% + + + + + + + + diff --git a/pkg/distillery/basic.reason/PROJECT_NAME.eliom b/pkg/distillery/basic.reason/PROJECT_NAME.eliom new file mode 100644 index 0000000000..fab29c263c --- /dev/null +++ b/pkg/distillery/basic.reason/PROJECT_NAME.eliom @@ -0,0 +1,28 @@ +[%%shared + open Eliom_lib; + open Eliom_content; + open Html.D +]; + +let module %%%MODULE_NAME%%%_app = Eliom_registration.App { + let application_name = "%%%PROJECT_NAME%%%"; + let global_data_path = None; +}; + +let main_service = + Eliom_service.create + path::(Eliom_service.Path []) + meth::(Eliom_service.Get Eliom_parameter.unit) + (); + +let () = + %%%MODULE_NAME%%%_app.register + service::main_service + ( + fun () () => Lwt.return ( + Eliom_tools.F.html + title::"%%%PROJECT_NAME%%%" + css::[["css", "%%%PROJECT_NAME%%%.css"]] + Html.F.(body [h1 [pcdata "Welcome from Eliom's distillery!"]]) + ) + ); diff --git a/pkg/distillery/basic.reason/README b/pkg/distillery/basic.reason/README new file mode 100644 index 0000000000..6c48aa8af2 --- /dev/null +++ b/pkg/distillery/basic.reason/README @@ -0,0 +1,82 @@ + +Instructions +============ + +This project is (initially) generated by eliom-distillery as the basic +project "%%%PROJECT_NAME%%%". + +Generally, you can compile it and run ocsigenserver on it by + $ make test.byte (or test.opt) +See below for other useful targets for make. + +Generated files +--------------- + +The following files in this directory have been generated by +eliom-distillery: + + - %%%PROJECT_NAME%%%.eliom + This is your initial source file. +%%%ifdef OCAML4%%% + All Eliom files (*.eliom, *.eliomi) in this directory are + automatically considered. To add a .ml/.mli file to your project, + append it to the variable SERVER_FILES or CLIENT_FILES. +%%%endif%%% +%%%ifdef OCAML3%%% + To add more source files (.ml,.mli,.eliom,.eliomi) to your project, + add it to the variables SERVER_FILES and/or CLIENT_FILES. +%%%endif%%% + + - static/ + The content of this folder is statically served. Put your CSS or + additional JavaScript files here! + + - Makefile.options + Configure your project here! + + - %%%PROJECT_NAME%%%.conf.in + This file is a template for the configuration file for + ocsigenserver. You will rarely have to edit itself - it takes its + variables from the Makefile.options. This way, the installation + rules and the configuration files are synchronized with respect to + the different folders. + + - Makefile + This contains all rules necessary to build, test, and run your + Eliom application. You better don't touch it ;) See below for the + relevant targets. + + - local/ + This directory is the target of the temporary installation of + your application, to test locally before doing a system-wide + installation in /. Do not put anything manually here. + + - README + Not completely describable here. + + +Makefile targets +---------------- + +Here's some help on how to work with this basic distillery project: + + - Test your application by compiling it and running ocsigenserver locally + $ make test.byte (or test.opt) + + - Compile it only + $ make all (or byte or opt) + + - Deploy your project on your system + $ sudo make install (or install.byte or install.opt) + + - Run the server on the deployed project + $ sudo make run.byte (or run.opt) + + If WWWUSER in the Makefile.options is you, you don't need the + `sudo'. If Eliom isn't installed globally, however, you need to + re-export some environment variables to make this work: + $ sudo PATH=$PATH OCAMLPATH=$OCAMLPATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH make run.byte/run.opt + + - If you need a findlib package in your project, add it to the + variables SERVER_PACKAGES and/or CLIENT_PACKAGES. The configuration + file will be automatically updated. diff --git a/pkg/distillery/basic.reason/static!css!PROJECT_NAME.css b/pkg/distillery/basic.reason/static!css!PROJECT_NAME.css new file mode 100644 index 0000000000..b71fa50add --- /dev/null +++ b/pkg/distillery/basic.reason/static!css!PROJECT_NAME.css @@ -0,0 +1,3 @@ +* { + font-family: sans-serif; +} From d7dd8cf92cdcb1dfc15817147d4e4e1e7dd6bba7 Mon Sep 17 00:00:00 2001 From: Vasilis Papavasileiou Date: Tue, 13 Dec 2016 15:33:55 +0100 Subject: [PATCH 3/8] Pass original file name to PPX When using refmt, we end up with intermediate filenames that break our identifier generation. --- src/ppx/ppx_eliom_utils.ml | 24 ++++++++++++++++++++---- src/tools/eliomc.ml | 1 + src/tools/utils.ml | 10 +++++++++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/ppx/ppx_eliom_utils.ml b/src/ppx/ppx_eliom_utils.ml index 9105a34a63..b01229fd47 100644 --- a/src/ppx/ppx_eliom_utils.ml +++ b/src/ppx/ppx_eliom_utils.ml @@ -37,6 +37,8 @@ let pat_args = function | [p] -> p | l -> Pat.tuple l +let override_file_name = ref None + (* We use a strong hash (MD5) of the file name. We only keep the first 36 bit, which should be well enough: with 256 files, the likelihood of a collision is about one in two @@ -44,7 +46,14 @@ let pat_args = function These bits are encoded using an OCaml-compatible variant of Base 64, as the hash is used to generate OCaml identifiers. *) let file_hash loc = - let s = Digest.string loc.Location.loc_start.pos_fname in + let file_name = + match !override_file_name with + | Some file_name -> + file_name + | None -> + loc.Location.loc_start.pos_fname + in + let s = Digest.string file_name in let e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_'" in let o = Bytes.create 6 in let g p = Char.code s.[p] in @@ -287,10 +296,17 @@ module Context = struct end -let match_args = function +let rec match_args = function | [ ] -> () - | [ "-type" ; type_file ] -> Mli.type_file := Some type_file - | [ "-notype" ] -> Mli.type_file := None + | "-orig-file-name" :: file_name :: args -> + override_file_name := Some file_name; + match_args args + | "-type" :: type_file :: args -> + Mli.type_file := Some type_file; + match_args args + | "-notype" :: args -> + Mli.type_file := None; + match_args args | args -> Location.raise_errorf ~loc:Location.(in_file !input_name) "Wrong arguments:@ %s" (String.concat " " args) diff --git a/src/tools/eliomc.ml b/src/tools/eliomc.ml index 4633789e6d..ea656c8068 100644 --- a/src/tools/eliomc.ml +++ b/src/tools/eliomc.ml @@ -322,6 +322,7 @@ let compile_eliom ~impl_intf file = args := !args @ [obj] let process_eliom ~impl_intf file = + if !Utils.use_refmt then Utils.orig_file_name := Some file; match !mode with | `Infer when impl_intf = `Impl -> compile_server_type_eliom file diff --git a/src/tools/utils.ml b/src/tools/utils.ml index 178c89a422..b72a4bedca 100644 --- a/src/tools/utils.ml +++ b/src/tools/utils.ml @@ -73,6 +73,8 @@ let type_dir : string ref = ref default_type_dir let use_refmt = ref false +let orig_file_name = ref None + let get_kind k = match k with | Some k -> k @@ -366,7 +368,7 @@ let get_ppopts ~impl_intf file = let preprocess_opt ?(ocaml = false) ?kind opts = let refmt () = if !use_refmt then - [ "-pp" ; "refmt -parse re -print ml" ] + [ "-pp"; "refmt -parse re -print ml" ] else [] in @@ -386,6 +388,12 @@ let preprocess_opt ?(ocaml = false) ?kind opts = | `Client -> "eliom.ppx.client" | `Server -> "eliom.ppx.server" | `Types -> "eliom.ppx.type" + and opts = + match !orig_file_name, !use_refmt with + | Some orig_file_name, true -> + "-orig-file-name" :: orig_file_name :: opts + | _, _ -> + opts in refmt () @ [ "-ppx"; get_ppx pkg ^ " " ^ String.concat " " opts ] From 252df5531125193392b540e9d2229ce843560551 Mon Sep 17 00:00:00 2001 From: Vasilis Papavasileiou Date: Tue, 13 Dec 2016 17:00:30 +0100 Subject: [PATCH 4/8] Exit gracefully in the abscence of refmt --- src/tools/eliomc.ml | 10 +++++++--- src/tools/utils.ml | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/tools/eliomc.ml b/src/tools/eliomc.ml index ea656c8068..f3ff31aeb9 100644 --- a/src/tools/eliomc.ml +++ b/src/tools/eliomc.ml @@ -235,7 +235,8 @@ let compile_server_type_eliom file = let out = Unix.openfile obj [Unix.O_WRONLY; Unix.O_CREAT; Unix.O_TRUNC] 0o666 in let on_error _ = Unix.close out; - Sys.remove obj + Sys.remove obj; + Utils.exit_no_refmt () in create_process ~out ~on_error !compiler ( [ "-i" ] @@ -303,14 +304,17 @@ let compile_eliom ~impl_intf file = | `Server | `ServerOpt -> obj_ext () in output_prefix file ^ ext + and ppopts = get_ppopts ~impl_intf file in + let on_error _ = + Sys.remove obj; + Utils.exit_no_refmt () in - let ppopts = get_ppopts ~impl_intf file in (* if !do_dump then begin *) (* let camlp4, ppopt = get_pp_dump pkg ("-printer" :: "o" :: ppopts @ [file]) in *) (* create_process camlp4 ppopt; *) (* exit 0 *) (* end; *) - create_process !compiler ( + create_process ~on_error !compiler ( [ "-c" ; "-o" ; obj ] @ preprocess_opt ppopts @ [ "-intf-suffix"; ".eliomi" ] diff --git a/src/tools/utils.ml b/src/tools/utils.ml index b72a4bedca..03183f864c 100644 --- a/src/tools/utils.ml +++ b/src/tools/utils.ml @@ -430,6 +430,13 @@ let create_filter name args f = let ch = Unix.in_channel_of_descr in_ in try f ch with _ -> close_in ch; wait pid +let exit_no_refmt () = + if !use_refmt then ( + Printf.eprintf + "Compiler failed. Have you installed reason and its refmt binary?\n%!"; + exit 1 + ) + let help_filter skip msg ch = for _i = 1 to skip do ignore (input_line ch) done; prerr_endline msg; From cf3ea5d9b2b71500bb3d3a5702af7457eecc1bb6 Mon Sep 17 00:00:00 2001 From: Vasilis Papavasileiou Date: Thu, 15 Jun 2017 16:08:45 +0200 Subject: [PATCH 5/8] New refmt argument syntax --- src/tools/utils.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/utils.ml b/src/tools/utils.ml index 03183f864c..de6bf6b965 100644 --- a/src/tools/utils.ml +++ b/src/tools/utils.ml @@ -368,7 +368,7 @@ let get_ppopts ~impl_intf file = let preprocess_opt ?(ocaml = false) ?kind opts = let refmt () = if !use_refmt then - [ "-pp"; "refmt -parse re -print ml" ] + [ "-pp"; "refmt --parse=re --print=ml" ] else [] in From 86b7384800f1627388d1f8bde429db17ac182ca8 Mon Sep 17 00:00:00 2001 From: Charles Chamberlain Date: Fri, 16 Jun 2017 14:02:01 +0200 Subject: [PATCH 6/8] Add -reason flag to eliom-distillery and update basic.ppx --- pkg/distillery/basic.ppx/Makefile | 12 ++++++------ src/tools/distillery.ml | 22 ++++++++++++++++++---- src/tools/eliomc.ml | 5 ----- src/tools/utils.ml | 8 ++++++++ 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/pkg/distillery/basic.ppx/Makefile b/pkg/distillery/basic.ppx/Makefile index 8c47d3983d..df9a38e019 100644 --- a/pkg/distillery/basic.ppx/Makefile +++ b/pkg/distillery/basic.ppx/Makefile @@ -12,9 +12,9 @@ include Makefile.options ## Internals ## Required binaries -ELIOMC := eliomc -ppx -ELIOMOPT := eliomopt -ppx -JS_OF_ELIOM := js_of_eliom -ppx +ELIOMC := eliomc %%%REASON_FLAG%%% -ppx +ELIOMOPT := eliomopt %%%REASON_FLAG%%% -ppx +JS_OF_ELIOM := js_of_eliom %%%REASON_FLAG%%% -ppx ELIOMDEP := eliomdep OCSIGENSERVER := ocsigenserver OCSIGENSERVER.OPT := ocsigenserver.opt @@ -103,7 +103,7 @@ run.opt: # Use `eliomdep -sort' only in OCaml>4 ifeq ($(shell ocamlc -version|cut -c1),4) -eliomdep=$(shell $(ELIOMDEP) $(1) -ppx -sort $(2) $(filter %.eliom %.ml,$(3)))) +eliomdep=$(shell $(ELIOMDEP) $(1) %%%REASON_FLAG%%% -ppx -sort $(2) $(filter %.eliom %.ml,$(3)))) else eliomdep=$(3) endif @@ -219,10 +219,10 @@ include .depend cat $^ > $@ $(DEPSDIR)/%.server: % | $(DEPSDIR) - $(ELIOMDEP) -server -ppx $(SERVER_INC) $< > $@ + $(ELIOMDEP) -server %%%REASON_FLAG%%% -ppx $(SERVER_INC) $< > $@ $(DEPSDIR)/%.client: % | $(DEPSDIR) - $(ELIOMDEP) -client -ppx $(CLIENT_INC) $< > $@ + $(ELIOMDEP) -client %%%REASON_FLAG%%% -ppx $(CLIENT_INC) $< > $@ $(DEPSDIR): mkdir $@ diff --git a/src/tools/distillery.ml b/src/tools/distillery.ml index a60c8be7c3..85dd471f0b 100644 --- a/src/tools/distillery.ml +++ b/src/tools/distillery.ml @@ -187,7 +187,16 @@ let expand_dest_path ~name ~dest_dir s = |> join_path |> Filename.concat dest_dir -let create_project ?preds ~without_asking ~name ~env ~source_dir ~dest_dir () = +let convert_file_to_reason path = + let extension = Filename.extension path in + if (extension = ".ml" || extension = ".eliom") then + Utils.run_command + ~on_error:(function + | 127 -> Printf.eprintf "Error: refmt is not installed - please install with `opam install reason`\n" + | d -> Printf.eprintf "Unknown error code %d while running refmt\n" d) + ("refmt --parse=ml --print=re --in-place " ^ path) + +let create_project ?preds ~without_asking ~use_refmt ~name ~env ~source_dir ~dest_dir () = let eliom_ignore_files = lines_of_file (Filename.concat source_dir eliomignore_filename) and eliom_verbatim_files = @@ -213,7 +222,8 @@ let create_project ?preds ~without_asking ~name ~env ~source_dir ~dest_dir () = else let src_path = Filename.concat source_dir src_file and dst_path = expand_dest_path ~name ~dest_dir src_file in - copy_file ?preds ~env src_path dst_path + copy_file ?preds ~env src_path dst_path ; + if use_refmt then convert_file_to_reason dst_path ) (Sys.readdir source_dir) @@ -227,7 +237,8 @@ let env name = [ "PROJECT_NAME", name; "MODULE_NAME", String.capitalize name; - "PROJECT_DB", db + "PROJECT_DB", db; + "REASON_FLAG", if !Utils.use_refmt then "-reason" else "" ] let get_templatedirs () = @@ -281,6 +292,7 @@ let compilation_unit_name_regexp = let main () = let dir = ref false in let without_asking = ref false in + let use_refmt = ref false in let shown = ref false in let show_templates () = List.iter (fun (name, path) -> Printf.printf "%s [%s]\n" name path) (get_templates ()); @@ -312,6 +324,8 @@ let main () = " Display the template directories (set through $ELIOM_DISTILLERY_PATH)"; "-y", Set without_asking, " Create the project directory without confirmation."; + "-reason", Set Utils.use_refmt, + " Create the project with reason syntax (defaults to OCaml)"; "-name", String (fun s -> name := Some (check_name s)), " Name of the project (a valid compilation unit name)"; "-template", String select_template, @@ -339,7 +353,7 @@ let main () = (fst template) else let env, source_dir = init_project template name in - create_project ~without_asking:(!without_asking) ~name ~env ~source_dir ~dest_dir () + create_project ~without_asking:(!without_asking) ~use_refmt:(!Utils.use_refmt) ~name ~env ~source_dir ~dest_dir () end let () = main () diff --git a/src/tools/eliomc.ml b/src/tools/eliomc.ml index f3ff31aeb9..d13ff87ba7 100644 --- a/src/tools/eliomc.ml +++ b/src/tools/eliomc.ml @@ -190,11 +190,6 @@ let compile_obj file = (* Process eliom and eliomi files *) -let run_command s = - let v = Sys.command s in - if v != 0 then - failwith (Printf.sprintf "Warning: command [%s] returned %d" s v) - (* WARNING: if you change this, also change inferred_type_prefix in ppx/ppx_eliom_utils.ml and ocamlbuild/ocamlbuild_eliom.ml *) let inferred_type_prefix = "eliom_inferred_type_" diff --git a/src/tools/utils.ml b/src/tools/utils.ml index de6bf6b965..1f9d5ab271 100644 --- a/src/tools/utils.ml +++ b/src/tools/utils.ml @@ -399,6 +399,14 @@ let preprocess_opt ?(ocaml = false) ?kind opts = (** Process *) +let run_command ?on_error s = + let v = Sys.command s in + if v != 0 then + match on_error with + | Some f -> f v + | None -> Printf.eprintf "Error: command [%s] returned [%d]" s v; + exit 255 + let rec wait ?(on_error=fun _ -> ()) pid = let e = snd (Unix.waitpid [] pid) in match e with From 3688d21adc3257a6428365eea6a98945cb8c18e1 Mon Sep 17 00:00:00 2001 From: Charles Chamberlain Date: Fri, 16 Jun 2017 14:19:30 +0200 Subject: [PATCH 7/8] Revert "Add a basic.reason template" This reverts commit 48fab6025d74d08bcbf150d2aca33d4def364b98. The reason is that we can now generate a basic reason template with `-reason -template basic.ppx` --- pkg/distillery/basic.reason/Makefile | 240 ------------------ pkg/distillery/basic.reason/Makefile.options | 64 ----- .../basic.reason/PROJECT_NAME.conf.in | 28 -- .../basic.reason/PROJECT_NAME.eliom | 28 -- pkg/distillery/basic.reason/README | 82 ------ .../basic.reason/static!css!PROJECT_NAME.css | 3 - 6 files changed, 445 deletions(-) delete mode 100644 pkg/distillery/basic.reason/Makefile delete mode 100644 pkg/distillery/basic.reason/Makefile.options delete mode 100644 pkg/distillery/basic.reason/PROJECT_NAME.conf.in delete mode 100644 pkg/distillery/basic.reason/PROJECT_NAME.eliom delete mode 100644 pkg/distillery/basic.reason/README delete mode 100644 pkg/distillery/basic.reason/static!css!PROJECT_NAME.css diff --git a/pkg/distillery/basic.reason/Makefile b/pkg/distillery/basic.reason/Makefile deleted file mode 100644 index f4d8fa2507..0000000000 --- a/pkg/distillery/basic.reason/Makefile +++ /dev/null @@ -1,240 +0,0 @@ - -##---------------------------------------------------------------------- -## DISCLAIMER -## -## This file contains the rules to make an Eliom project. The project is -## configured through the variables in the file Makefile.options. -##---------------------------------------------------------------------- - -include Makefile.options - -##---------------------------------------------------------------------- -## Internals - -## Required binaries -ELIOMC := eliomc -reason -ppx -ELIOMOPT := eliomopt -reason -ppx -JS_OF_ELIOM := js_of_eliom -reason -ppx -ELIOMDEP := eliomdep -OCSIGENSERVER := ocsigenserver -OCSIGENSERVER.OPT := ocsigenserver.opt - -## Where to put intermediate object files. -## - ELIOM_{SERVER,CLIENT}_DIR must be distinct -## - ELIOM_CLIENT_DIR must not be the local dir. -## - ELIOM_SERVER_DIR could be ".", but you need to -## remove it from the "clean" rules... -export ELIOM_SERVER_DIR := _server -export ELIOM_CLIENT_DIR := _client -export ELIOM_TYPE_DIR := _server -DEPSDIR := _deps - -ifeq ($(DEBUG),yes) - GENERATE_DEBUG ?= -g - RUN_DEBUG ?= "-v" - DEBUG_JS ?= -jsopt -pretty -jsopt -noinline -jsopt -debuginfo -endif - -##---------------------------------------------------------------------- -## General - -.PHONY: all byte opt -all: byte opt -byte opt:: $(TEST_PREFIX)$(ELIOMSTATICDIR)/${PROJECT_NAME}.js -byte opt:: $(TEST_PREFIX)$(ETCDIR)/$(PROJECT_NAME).conf -byte opt:: $(TEST_PREFIX)$(ETCDIR)/$(PROJECT_NAME)-test.conf -byte:: $(TEST_PREFIX)$(LIBDIR)/${PROJECT_NAME}.cma -opt:: $(TEST_PREFIX)$(LIBDIR)/${PROJECT_NAME}.cmxs - -DIST_DIRS = $(ETCDIR) $(DATADIR) $(LIBDIR) $(LOGDIR) $(STATICDIR) $(ELIOMSTATICDIR) $(shell dirname $(CMDPIPE)) - -##---------------------------------------------------------------------- -## Testing - -DIST_FILES = $(ELIOMSTATICDIR)/$(PROJECT_NAME).js $(LIBDIR)/$(PROJECT_NAME).cma - -.PHONY: test.byte test.opt -test.byte: $(addprefix $(TEST_PREFIX),$(ETCDIR)/$(PROJECT_NAME)-test.conf $(DIST_DIRS) $(DIST_FILES)) - $(OCSIGENSERVER) $(RUN_DEBUG) -c $< -test.opt: $(addprefix $(TEST_PREFIX),$(ETCDIR)/$(PROJECT_NAME)-test.conf $(DIST_DIRS) $(patsubst %.cma,%.cmxs, $(DIST_FILES))) - $(OCSIGENSERVER.OPT) $(RUN_DEBUG) -c $< - -$(addprefix $(TEST_PREFIX), $(DIST_DIRS)): - mkdir -p $@ - -##---------------------------------------------------------------------- -## Installing & Running - -.PHONY: install install.byte install.byte install.opt install.static install.etc install.lib install.lib.byte install.lib.opt run.byte run.opt -install: install.byte install.opt -install.byte: install.lib.byte install.etc install.static | $(addprefix $(PREFIX),$(DATADIR) $(LOGDIR) $(shell dirname $(CMDPIPE))) -install.opt: install.lib.opt install.etc install.static | $(addprefix $(PREFIX),$(DATADIR) $(LOGDIR) $(shell dirname $(CMDPIPE))) -install.lib: install.lib.byte install.lib.opt -install.lib.byte: $(TEST_PREFIX)$(LIBDIR)/$(PROJECT_NAME).cma | $(PREFIX)$(LIBDIR) - install $< $(PREFIX)$(LIBDIR) -install.lib.opt: $(TEST_PREFIX)$(LIBDIR)/$(PROJECT_NAME).cmxs | $(PREFIX)$(LIBDIR) - install $< $(PREFIX)$(LIBDIR) -install.static: $(TEST_PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).js | $(PREFIX)$(STATICDIR) $(PREFIX)$(ELIOMSTATICDIR) - cp -r $(LOCAL_STATIC)/* $(PREFIX)$(STATICDIR) - [ -z $(WWWUSER) ] || chown -R $(WWWUSER) $(PREFIX)$(STATICDIR) - install $(addprefix -o ,$(WWWUSER)) $< $(PREFIX)$(ELIOMSTATICDIR) -install.etc: $(TEST_PREFIX)$(ETCDIR)/$(PROJECT_NAME).conf | $(PREFIX)$(ETCDIR) - install $< $(PREFIX)$(ETCDIR)/$(PROJECT_NAME).conf - -.PHONY: -print-install-files: - @echo $(PREFIX)$(LIBDIR) - @echo $(PREFIX)$(STATICDIR) - @echo $(PREFIX)$(ELIOMSTATICDIR) - @echo $(PREFIX)$(ETCDIR) - -$(addprefix $(PREFIX),$(ETCDIR) $(LIBDIR)): - install -d $@ -$(addprefix $(PREFIX),$(DATADIR) $(LOGDIR) $(STATICDIR) $(ELIOMSTATICDIR) $(shell dirname $(CMDPIPE))): - install $(addprefix -o ,$(WWWUSER)) -d $@ - -run.byte: - $(OCSIGENSERVER) $(RUN_DEBUG) -c ${PREFIX}${ETCDIR}/${PROJECT_NAME}.conf -run.opt: - $(OCSIGENSERVER.OPT) $(RUN_DEBUG) -c ${PREFIX}${ETCDIR}/${PROJECT_NAME}.conf - -##---------------------------------------------------------------------- -## Aux - -# Use `eliomdep -sort' only in OCaml>4 -ifeq ($(shell ocamlc -version|cut -c1),4) -eliomdep=$(shell $(ELIOMDEP) $(1) -reason -ppx -sort $(2) $(filter %.eliom %.ml,$(3)))) -else -eliomdep=$(3) -endif -objs=$(patsubst %.ml,$(1)/%.$(2),$(patsubst %.eliom,$(1)/%.$(2),$(filter %.eliom %.ml,$(3)))) -depsort=$(call objs,$(1),$(2),$(call eliomdep,$(3),$(4),$(5))) - -##---------------------------------------------------------------------- -## Config files - -FINDLIB_PACKAGES=$(patsubst %,\,$(SERVER_PACKAGES)) -EDIT_WARNING=DON\'T EDIT THIS FILE! It is generated from $(PROJECT_NAME).conf.in, edit that one, or the variables in Makefile.options -SED_ARGS := -e "/^ *%%%/d" -SED_ARGS += -e "s|%%PROJECT_NAME%%|$(PROJECT_NAME)|g" -SED_ARGS += -e "s|%%DATABASE_NAME%%|$(DATABASE_NAME)|g" -SED_ARGS += -e "s|%%DATABASE_USER%%|$(DATABASE_USER)|g" -SED_ARGS += -e "s|%%CMDPIPE%%|%%PREFIX%%$(CMDPIPE)|g" -SED_ARGS += -e "s|%%LOGDIR%%|%%PREFIX%%$(LOGDIR)|g" -SED_ARGS += -e "s|%%DATADIR%%|%%PREFIX%%$(DATADIR)|g" -SED_ARGS += -e "s|%%PERSISTENT_DATA_BACKEND%%|$(PERSISTENT_DATA_BACKEND)|g" -SED_ARGS += -e "s|%%LIBDIR%%|%%PREFIX%%$(LIBDIR)|g" -SED_ARGS += -e "s|%%WARNING%%|$(EDIT_WARNING)|g" -SED_ARGS += -e "s|%%PACKAGES%%|$(FINDLIB_PACKAGES)|g" -SED_ARGS += -e "s|%%ELIOMSTATICDIR%%|%%PREFIX%%$(ELIOMSTATICDIR)|g" -ifeq ($(DEBUG),yes) - SED_ARGS += -e "s|%%DEBUGMODE%%|\|g" -else - SED_ARGS += -e "s|%%DEBUGMODE%%||g" -endif - -LOCAL_SED_ARGS := -e "s|%%PORT%%|$(TEST_PORT)|g" -LOCAL_SED_ARGS += -e "s|%%STATICDIR%%|$(LOCAL_STATIC)|g" -LOCAL_SED_ARGS += -e "s|%%USERGROUP%%||g" -GLOBAL_SED_ARGS := -e "s|%%PORT%%|$(PORT)|g" -GLOBAL_SED_ARGS += -e "s|%%STATICDIR%%|%%PREFIX%%$(STATICDIR)|g" -ifeq ($(WWWUSER)$(WWWGROUP),) - GLOBAL_SED_ARGS += -e "s|%%USERGROUP%%||g" -else - GLOBAL_SED_ARGS += -e "s|%%USERGROUP%%|$(WWWUSER)$(WWWGROUP)|g" -endif - -$(TEST_PREFIX)${ETCDIR}/${PROJECT_NAME}.conf: ${PROJECT_NAME}.conf.in Makefile.options | $(TEST_PREFIX)$(ETCDIR) - sed $(SED_ARGS) $(GLOBAL_SED_ARGS) $< | sed -e "s|%%PREFIX%%|$(PREFIX)|g" > $@ -$(TEST_PREFIX)${ETCDIR}/${PROJECT_NAME}-test.conf: ${PROJECT_NAME}.conf.in Makefile.options | $(TEST_PREFIX)$(ETCDIR) - sed $(SED_ARGS) $(LOCAL_SED_ARGS) $< | sed -e "s|%%PREFIX%%|$(TEST_PREFIX)|g" > $@ - -##---------------------------------------------------------------------- -## Server side compilation - -SERVER_INC := ${addprefix -package ,${SERVER_PACKAGES}} - -${ELIOM_TYPE_DIR}/%.type_mli: %.eliom - ${ELIOMC} -infer ${SERVER_INC} $< - -$(TEST_PREFIX)$(LIBDIR)/$(PROJECT_NAME).cma: $(call objs,$(ELIOM_SERVER_DIR),cmo,$(SERVER_FILES)) | $(TEST_PREFIX)$(LIBDIR) - ${ELIOMC} -a -o $@ $(GENERATE_DEBUG) \ - $(call depsort,$(ELIOM_SERVER_DIR),cmo,-server,$(SERVER_INC),$(SERVER_FILES)) - -$(TEST_PREFIX)$(LIBDIR)/$(PROJECT_NAME).cmxa: $(call objs,$(ELIOM_SERVER_DIR),cmx,$(SERVER_FILES)) | $(TEST_PREFIX)$(LIBDIR) - ${ELIOMOPT} -a -o $@ $(GENERATE_DEBUG) \ - $(call depsort,$(ELIOM_SERVER_DIR),cmx,-server,$(SERVER_INC),$(SERVER_FILES)) - -%.cmxs: %.cmxa - $(ELIOMOPT) -shared -linkall -o $@ $(GENERATE_DEBUG) $< - -${ELIOM_SERVER_DIR}/%.cmi: %.mli - ${ELIOMC} -c ${SERVER_INC} $(GENERATE_DEBUG) $< - -${ELIOM_SERVER_DIR}/%.cmi: %.eliomi - ${ELIOMC} -c ${SERVER_INC} $(GENERATE_DEBUG) $< - -${ELIOM_SERVER_DIR}/%.cmo: %.ml - ${ELIOMC} -c ${SERVER_INC} $(GENERATE_DEBUG) $< -${ELIOM_SERVER_DIR}/%.cmo: %.eliom - ${ELIOMC} -c ${SERVER_INC} $(GENERATE_DEBUG) $< - -${ELIOM_SERVER_DIR}/%.cmx: %.ml - ${ELIOMOPT} -c ${SERVER_INC} $(GENERATE_DEBUG) $< -${ELIOM_SERVER_DIR}/%.cmx: %.eliom - ${ELIOMOPT} -c ${SERVER_INC} $(GENERATE_DEBUG) $< - - -##---------------------------------------------------------------------- -## Client side compilation - -CLIENT_LIBS := ${addprefix -package ,${CLIENT_PACKAGES}} -CLIENT_INC := ${addprefix -package ,${CLIENT_PACKAGES}} - -CLIENT_OBJS := $(filter %.eliom %.ml, $(CLIENT_FILES)) -CLIENT_OBJS := $(patsubst %.eliom,${ELIOM_CLIENT_DIR}/%.cmo, ${CLIENT_OBJS}) -CLIENT_OBJS := $(patsubst %.ml,${ELIOM_CLIENT_DIR}/%.cmo, ${CLIENT_OBJS}) - -$(TEST_PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).js: $(call objs,$(ELIOM_CLIENT_DIR),cmo,$(CLIENT_FILES)) | $(TEST_PREFIX)$(ELIOMSTATICDIR) - ${JS_OF_ELIOM} -o $@ $(GENERATE_DEBUG) $(CLIENT_INC) $(DEBUG_JS) \ - $(call depsort,$(ELIOM_CLIENT_DIR),cmo,-client,$(CLIENT_INC),$(CLIENT_FILES)) - -${ELIOM_CLIENT_DIR}/%.cmi: %.mli - ${JS_OF_ELIOM} -c ${CLIENT_INC} $(GENERATE_DEBUG) $< - -${ELIOM_CLIENT_DIR}/%.cmo: %.eliom - ${JS_OF_ELIOM} -c ${CLIENT_INC} $(GENERATE_DEBUG) $< -${ELIOM_CLIENT_DIR}/%.cmo: %.ml - ${JS_OF_ELIOM} -c ${CLIENT_INC} $(GENERATE_DEBUG) $< - -${ELIOM_CLIENT_DIR}/%.cmi: %.eliomi - ${JS_OF_ELIOM} -c ${CLIENT_INC} $(GENERATE_DEBUG) $< - -##---------------------------------------------------------------------- -## Dependencies - -include .depend - -.depend: $(patsubst %,$(DEPSDIR)/%.server,$(SERVER_FILES)) $(patsubst %,$(DEPSDIR)/%.client,$(CLIENT_FILES)) - cat $^ > $@ - -$(DEPSDIR)/%.server: % | $(DEPSDIR) - $(ELIOMDEP) -server -reason -ppx $(SERVER_INC) $< > $@ - -$(DEPSDIR)/%.client: % | $(DEPSDIR) - $(ELIOMDEP) -client -reason -ppx $(CLIENT_INC) $< > $@ - -$(DEPSDIR): - mkdir $@ - -##---------------------------------------------------------------------- -## Clean up - -clean: - -rm -f *.cm[ioax] *.cmxa *.cmxs *.o *.a *.annot - -rm -f *.type_mli - -rm -f ${PROJECT_NAME}.js - -rm -rf ${ELIOM_CLIENT_DIR} ${ELIOM_SERVER_DIR} - -distclean: clean - -rm -rf $(TEST_PREFIX) $(DEPSDIR) .depend diff --git a/pkg/distillery/basic.reason/Makefile.options b/pkg/distillery/basic.reason/Makefile.options deleted file mode 100644 index 00a1b9e176..0000000000 --- a/pkg/distillery/basic.reason/Makefile.options +++ /dev/null @@ -1,64 +0,0 @@ - -#---------------------------------------------------------------------- -# SETTINGS FOR THE ELIOM PROJECT %%%PROJECT_NAME%%% -#---------------------------------------------------------------------- - -PROJECT_NAME := %%%PROJECT_NAME%%% - -# Source files for the server -SERVER_FILES := $(wildcard *.eliomi *.eliom) -# Source files for the client -CLIENT_FILES := $(wildcard *.eliomi *.eliom) - -# OCamlfind packages for the server -SERVER_PACKAGES := lwt.ppx js_of_ocaml.deriving.ppx -# OCamlfind packages for the client -CLIENT_PACKAGES := lwt.ppx js_of_ocaml.ppx js_of_ocaml.deriving.ppx - -# Directory with files to be statically served -LOCAL_STATIC = static - -# The backend for persistent data. Can be dbm or sqlite. -# Make sure you have the following packages installed -# - *dbm* if you use dbm --> opam install dbm. -# - *sqlite3* if you use sqlite --> opam install sqlite3. -PERSISTENT_DATA_BACKEND = %%%PROJECT_DB%%% - -# Debug application (yes/no): Debugging info in compilation, -# JavaScript, ocsigenserver -DEBUG := no - -# User to run server with (make run.*) -WWWUSER := www-data -WWWGROUP := www-data - -# Port for running the server (make run.*) -PORT := 80 - -# Port for testing (make test.*) -TEST_PORT := 8080 - -# Root of installation (must end with /) -PREFIX := /usr/local/ - -# Local folder for make test.* (must end with /) -# Do not add files manually in this directory. -# It is just here to test your installation before installing in / -TEST_PREFIX := local/ - -# The installation tree (relative to $(PREFIX) when -# installing/running or $(TEST_PREFIX) when testing). -# Configuration file $(PROJECT_NAME).conf -ETCDIR := etc/${PROJECT_NAME} -# Project's library $(PROJECT_NAME).cma (cmxs) -LIBDIR := lib/${PROJECT_NAME} -# Command pipe, eg. $ echo reload > $(INSTALL_PREFIX)$(CMDPIPE) -CMDPIPE := var/run/${PROJECT_NAME}-cmd -# Ocsigenserver's logging files -LOGDIR := var/log/${PROJECT_NAME} -# Ocsigenserver's persistent data files -DATADIR := var/data/${PROJECT_NAME} -# Copy of $(LOCAL_STATIC) -STATICDIR := var/www/${PROJECT_NAME}/static -# Project's JavaScript file -ELIOMSTATICDIR := var/www/${PROJECT_NAME}/eliom diff --git a/pkg/distillery/basic.reason/PROJECT_NAME.conf.in b/pkg/distillery/basic.reason/PROJECT_NAME.conf.in deleted file mode 100644 index 13a8a1fdbb..0000000000 --- a/pkg/distillery/basic.reason/PROJECT_NAME.conf.in +++ /dev/null @@ -1,28 +0,0 @@ -%%% This is the template for your configuration file. The %%VALUES%% below are -%%% taken from the Makefile to generate the actual configuration files. -%%% This comment will disappear. - - - - %%PORT%% - %%% Only set for running, not for testing - %%USERGROUP%% - %%LOGDIR%% - %%DATADIR%% - utf-8 - %%% Only set when debugging - %%DEBUGMODE%% - %%CMDPIPE%% - - - - %%% This will include the packages defined as SERVER_PACKAGES in your Makefile: - %%PACKAGES%% - - - - - - - - diff --git a/pkg/distillery/basic.reason/PROJECT_NAME.eliom b/pkg/distillery/basic.reason/PROJECT_NAME.eliom deleted file mode 100644 index fab29c263c..0000000000 --- a/pkg/distillery/basic.reason/PROJECT_NAME.eliom +++ /dev/null @@ -1,28 +0,0 @@ -[%%shared - open Eliom_lib; - open Eliom_content; - open Html.D -]; - -let module %%%MODULE_NAME%%%_app = Eliom_registration.App { - let application_name = "%%%PROJECT_NAME%%%"; - let global_data_path = None; -}; - -let main_service = - Eliom_service.create - path::(Eliom_service.Path []) - meth::(Eliom_service.Get Eliom_parameter.unit) - (); - -let () = - %%%MODULE_NAME%%%_app.register - service::main_service - ( - fun () () => Lwt.return ( - Eliom_tools.F.html - title::"%%%PROJECT_NAME%%%" - css::[["css", "%%%PROJECT_NAME%%%.css"]] - Html.F.(body [h1 [pcdata "Welcome from Eliom's distillery!"]]) - ) - ); diff --git a/pkg/distillery/basic.reason/README b/pkg/distillery/basic.reason/README deleted file mode 100644 index 6c48aa8af2..0000000000 --- a/pkg/distillery/basic.reason/README +++ /dev/null @@ -1,82 +0,0 @@ - -Instructions -============ - -This project is (initially) generated by eliom-distillery as the basic -project "%%%PROJECT_NAME%%%". - -Generally, you can compile it and run ocsigenserver on it by - $ make test.byte (or test.opt) -See below for other useful targets for make. - -Generated files ---------------- - -The following files in this directory have been generated by -eliom-distillery: - - - %%%PROJECT_NAME%%%.eliom - This is your initial source file. -%%%ifdef OCAML4%%% - All Eliom files (*.eliom, *.eliomi) in this directory are - automatically considered. To add a .ml/.mli file to your project, - append it to the variable SERVER_FILES or CLIENT_FILES. -%%%endif%%% -%%%ifdef OCAML3%%% - To add more source files (.ml,.mli,.eliom,.eliomi) to your project, - add it to the variables SERVER_FILES and/or CLIENT_FILES. -%%%endif%%% - - - static/ - The content of this folder is statically served. Put your CSS or - additional JavaScript files here! - - - Makefile.options - Configure your project here! - - - %%%PROJECT_NAME%%%.conf.in - This file is a template for the configuration file for - ocsigenserver. You will rarely have to edit itself - it takes its - variables from the Makefile.options. This way, the installation - rules and the configuration files are synchronized with respect to - the different folders. - - - Makefile - This contains all rules necessary to build, test, and run your - Eliom application. You better don't touch it ;) See below for the - relevant targets. - - - local/ - This directory is the target of the temporary installation of - your application, to test locally before doing a system-wide - installation in /. Do not put anything manually here. - - - README - Not completely describable here. - - -Makefile targets ----------------- - -Here's some help on how to work with this basic distillery project: - - - Test your application by compiling it and running ocsigenserver locally - $ make test.byte (or test.opt) - - - Compile it only - $ make all (or byte or opt) - - - Deploy your project on your system - $ sudo make install (or install.byte or install.opt) - - - Run the server on the deployed project - $ sudo make run.byte (or run.opt) - - If WWWUSER in the Makefile.options is you, you don't need the - `sudo'. If Eliom isn't installed globally, however, you need to - re-export some environment variables to make this work: - $ sudo PATH=$PATH OCAMLPATH=$OCAMLPATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH make run.byte/run.opt - - - If you need a findlib package in your project, add it to the - variables SERVER_PACKAGES and/or CLIENT_PACKAGES. The configuration - file will be automatically updated. diff --git a/pkg/distillery/basic.reason/static!css!PROJECT_NAME.css b/pkg/distillery/basic.reason/static!css!PROJECT_NAME.css deleted file mode 100644 index b71fa50add..0000000000 --- a/pkg/distillery/basic.reason/static!css!PROJECT_NAME.css +++ /dev/null @@ -1,3 +0,0 @@ -* { - font-family: sans-serif; -} From 267d2bec65a90b03ef6422ba45d8c508934ee645 Mon Sep 17 00:00:00 2001 From: Charles Chamberlain Date: Fri, 16 Jun 2017 16:31:29 +0200 Subject: [PATCH 8/8] Only convert .eliom/.eliomi files --- src/tools/distillery.ml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tools/distillery.ml b/src/tools/distillery.ml index 85dd471f0b..cf43dd8259 100644 --- a/src/tools/distillery.ml +++ b/src/tools/distillery.ml @@ -189,7 +189,7 @@ let expand_dest_path ~name ~dest_dir s = let convert_file_to_reason path = let extension = Filename.extension path in - if (extension = ".ml" || extension = ".eliom") then + if (extension = ".eliom" || extension = ".eliomi") then Utils.run_command ~on_error:(function | 127 -> Printf.eprintf "Error: refmt is not installed - please install with `opam install reason`\n" @@ -292,7 +292,6 @@ let compilation_unit_name_regexp = let main () = let dir = ref false in let without_asking = ref false in - let use_refmt = ref false in let shown = ref false in let show_templates () = List.iter (fun (name, path) -> Printf.printf "%s [%s]\n" name path) (get_templates ());