Skip to content

Commit

Permalink
Merge pull request #3 from Khady/4.03.0-compat
Browse files Browse the repository at this point in the history
OCaml 4.03 compatibility
  • Loading branch information
whitequark committed May 3, 2016
2 parents 72b8abb + 1125df4 commit d81d5e3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
15 changes: 15 additions & 0 deletions .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
2 changes: 1 addition & 1 deletion _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

<src/*.{ml,mli,byte,native}>: package(ppx_tools.metaquot)
<src_test/*.{ml,byte,native}>: debug, package(oUnit)
5 changes: 3 additions & 2 deletions myocamlbuild.ml
Expand Up @@ -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"];
Expand Down
1 change: 1 addition & 0 deletions opam
Expand Up @@ -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}
]
Expand Down
5 changes: 4 additions & 1 deletion pkg/build.ml
Expand Up @@ -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";
Expand Down
8 changes: 6 additions & 2 deletions src/ppx_getenv.ml → 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
Expand All @@ -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\"]"))
Expand Down

0 comments on commit d81d5e3

Please sign in to comment.