Skip to content

Commit

Permalink
Merge pull request #8 from NathanReb/upgrade-ppxlib-0-18
Browse files Browse the repository at this point in the history
Make ppx_getenv compatible with ppxlib.0.18.0
  • Loading branch information
kit-ty-kate committed Oct 23, 2020
2 parents 4b75f60 + 3afef28 commit e4adf6e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
22 changes: 10 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
language: c
install: wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-docker.sh
script: bash -ex .travis-docker.sh
services:
- docker
install: wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-opam.sh
script: bash -ex .travis-opam.sh
env:
global:
- PACKAGE="ppx_getenv"
matrix:
- DISTRO=debian-stable OCAML_VERSION=4.04
- DISTRO=debian-stable OCAML_VERSION=4.05
- DISTRO=debian-stable OCAML_VERSION=4.06
- DISTRO=debian-stable OCAML_VERSION=4.07
- DISTRO=debian-stable OCAML_VERSION=4.08
- DISTRO=debian-stable OCAML_VERSION=4.09
- DISTRO=debian-stable OCAML_VERSION=4.10
- DISTRO=debian-stable OCAML_VERSION=4.11.0+trunk OCAML_BETA=enable
- OCAML_VERSION=4.04
- OCAML_VERSION=4.05
- OCAML_VERSION=4.06
- OCAML_VERSION=4.07
- OCAML_VERSION=4.08
- OCAML_VERSION=4.09
- OCAML_VERSION=4.10
- OCAML_VERSION=4.11
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
(tags ("syntax"))
(depends
(ocaml (>= 4.04.0))
(ppxlib (>= 0.9.0))
(ppxlib (>= 0.18.0))
(ounit2 :with-test)
(odoc :with-doc)))
2 changes: 1 addition & 1 deletion ppx_getenv.opam
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ bug-reports: "https://github.com/ocaml-ppx/ppx_getenv/issues"
depends: [
"dune" {>= "2.0"}
"ocaml" {>= "4.04.0"}
"ppxlib" {>= "0.9.0"}
"ppxlib" {>= "0.18.0"}
"ounit2" {with-test}
"odoc" {with-doc}
]
Expand Down
5 changes: 2 additions & 3 deletions src/ppx_getenv.ml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
open Ppxlib
open Ppxlib.Ast_helper

let getenv s = try Sys.getenv s with Not_found -> ""

let expander ~loc ~path:_ = function
| (* 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 (Pconst_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 (Pconst_string (getenv sym, None))
Ast_builder.Default.estring ~loc (getenv sym)
| _ ->
Location.raise_errorf ~loc "[%%getenv] accepts a string, e.g. [%%getenv \"USER\"]"

Expand Down

0 comments on commit e4adf6e

Please sign in to comment.