diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3d81993 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +language: c +env: + - OCAML=4.02.3 + - OCAML=4.03.0 +script: + - echo "yes" | sudo add-apt-repository ppa:avsm/ppa + - sudo apt-get update -qq + - sudo apt-get install -qq opam + - export OPAMYES=1 + - opam init + - opam switch $OCAML + - eval `opam config env` + - opam pin add -n -k path ppx_getenv . + - opam install --deps-only -d -t ppx_getenv + - opam install -d -t -v ppx_getenv \ No newline at end of file diff --git a/_tags b/_tags index 0bce820..b6a2935 100644 --- a/_tags +++ b/_tags @@ -1,4 +1,4 @@ -true: warn(@5@8@10@11@12@14@23@24@26@29@40), bin_annot, safe_string +true: warn(@5@8@10@11@12@14@23@24@26@29@40), bin_annot, safe_string, cppo_V_OCAML : package(ppx_tools.metaquot) : debug, package(oUnit) diff --git a/myocamlbuild.ml b/myocamlbuild.ml index 27884a9..b002f23 100644 --- a/myocamlbuild.ml +++ b/myocamlbuild.ml @@ -4,8 +4,9 @@ open Ocamlbuild_plugin let _ = Unix.putenv "PPX_GETENV_CHECK" "42" -let () = dispatch ( - function +let () = dispatch (fun phase -> + Ocamlbuild_cppo.dispatcher phase; + match phase with | After_rules -> flag ["ocaml"; "compile"; "ppx_byte"] & S[A"-ppx"; A"src/ppx_getenv.byte"]; diff --git a/opam b/opam index f8dd210..ec82b5c 100644 --- a/opam +++ b/opam @@ -15,6 +15,7 @@ build-test: [ "ocamlbuild" "-classic-display" "-use-ocamlfind" "src_test/test_ppx_getenv.byte" "--" ] depends: [ + "cppo" {build} "ppx_tools" {>= "0.99.1"} "ounit" {test} ] diff --git a/pkg/build.ml b/pkg/build.ml index 6af7d29..ad4dc30 100755 --- a/pkg/build.ml +++ b/pkg/build.ml @@ -2,13 +2,16 @@ #directory "pkg" #use "topkg.ml" +let ocamlbuild = + "ocamlbuild -use-ocamlfind -classic-display -plugin-tag 'package(cppo_ocamlbuild)'" + let () = let oc = open_out "src_test/_tags" in output_string oc (if Env.native then "<*.ml>: ppx_native" else "<*.ml>: ppx_byte"); close_out oc let () = - Pkg.describe "ppx_getenv" ~builder:`OCamlbuild [ + Pkg.describe "ppx_getenv" ~builder:(`Other (ocamlbuild, "_build")) [ Pkg.lib "pkg/META"; Pkg.bin ~auto:true "src/ppx_getenv" ~dst:"../lib/ppx_getenv/ppx_getenv"; Pkg.doc "README.md"; diff --git a/src/ppx_getenv.ml b/src/ppx_getenv.cppo.ml similarity index 82% rename from src/ppx_getenv.ml rename to src/ppx_getenv.cppo.ml index 5967179..adccf58 100644 --- a/src/ppx_getenv.ml +++ b/src/ppx_getenv.cppo.ml @@ -1,3 +1,7 @@ +#if OCAML_VERSION < (4, 03, 0) +#define Pconst_string Const_string +#endif + open Ast_mapper open Ast_helper open Asttypes @@ -19,9 +23,9 @@ let getenv_mapper argv = | (* Should have a single structure item, which is evaluation of a constant string. *) PStr [{ pstr_desc = Pstr_eval ({ pexp_loc = loc; - pexp_desc = Pexp_constant (Const_string (sym, None))}, _)}] -> + pexp_desc = Pexp_constant (Pconst_string (sym, None))}, _)}] -> (* Replace with a constant string with the value from the environment. *) - Exp.constant ~loc (Const_string (getenv sym, None)) + Exp.constant ~loc (Pconst_string (getenv sym, None)) | _ -> raise (Location.Error ( Location.error ~loc "[%getenv] accepts a string, e.g. [%getenv \"USER\"]"))