Skip to content

Commit

Permalink
Add jbuilder support
Browse files Browse the repository at this point in the history
  • Loading branch information
dra27 committed Aug 4, 2017
1 parent ce85d0d commit 7c9955b
Show file tree
Hide file tree
Showing 24 changed files with 320 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
_build/
_obuild/
_opam/
_olint/
bootstrap/
tests/tmp/
.*.swp
src_ext/_build
src_ext/lib
src_ext/cudf/
src_ext/cppo/
Expand Down Expand Up @@ -76,6 +76,7 @@ src/*.META
aclocal.m4
autom4te.cache
.merlin
src/ocaml-flags-standard.sexp
# doc
doc/dev-manual/*aux
doc/dev-manual/*.html
Expand Down
26 changes: 23 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ endif
all: opam-lib opam opam-installer
@

ifeq ($(JBUILDER),)
JBUILDER_DEP=src_ext/jbuilder/_build/install/default/bin/jbuilder$(EXE)
ifeq ($(shell command -v cygpath 2>/dev/null),)
JBUILDER:=$(JBUILDER_DEP)
else
JBUILDER:=$(shell echo "$(JBUILDER_DEP)" | cygpath -f - -a)
endif
else
JBUILDER_DEP=
endif

src_ext/jbuilder/_build/install/default/bin/jbuilder$(EXE): src_ext/jbuilder.stamp
cd src_ext/jbuilder && ocaml bootstrap.ml && ./boot.exe

src_ext/jbuilder.stamp:
make -C src_ext jbuilder.stamp

jbuilder: $(JBUILDER_DEP)
@$(JBUILDER) build @install

ALWAYS:
@

Expand Down Expand Up @@ -40,16 +60,16 @@ download-ext:
clean-ext:
$(MAKE) -C src_ext distclean

clean:
clean: fastclean
$(MAKE) -C src $@
$(MAKE) -C doc $@
rm -f *.install *.env *.err *.info *.out
rm -rf _obuild
rm -rf _obuild _build

distclean: clean clean-ext
rm -rf autom4te.cache bootstrap
rm -f .merlin Makefile.config config.log config.status src/core/opamVersion.ml src/core/opamCoreConfig.ml aclocal.m4
rm -f src/*.META
rm -f src/*.META src/*/.merlin src/ocaml-flags-standard.sexp

OPAMINSTALLER_FLAGS = --prefix "$(DESTDIR)$(prefix)"
OPAMINSTALLER_FLAGS += --mandir "$(DESTDIR)$(mandir)"
Expand Down
3 changes: 2 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -4927,7 +4927,7 @@ if test "x$prefix" = "xNONE"; then
prefix=$ac_default_prefix
fi
ac_config_files="$ac_config_files Makefile.config src/core/opamVersion.ml src/core/opamCoreConfig.ml src/core.META src/format.META src/repository.META src/solver.META src/state.META src/client.META src/admin.META"
ac_config_files="$ac_config_files Makefile.config src/core/opamVersion.ml src/core/opamCoreConfig.ml src/core.META src/format.META src/repository.META src/solver.META src/state.META src/client.META src/admin.META src/ocaml-flags-standard.sexp"
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
Expand Down Expand Up @@ -5645,6 +5645,7 @@ do
"src/state.META") CONFIG_FILES="$CONFIG_FILES src/state.META" ;;
"src/client.META") CONFIG_FILES="$CONFIG_FILES src/client.META" ;;
"src/admin.META") CONFIG_FILES="$CONFIG_FILES src/admin.META" ;;
"src/ocaml-flags-standard.sexp") CONFIG_FILES="$CONFIG_FILES src/ocaml-flags-standard.sexp" ;;
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
esac
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ AC_CONFIG_FILES(
src/state.META
src/client.META
src/admin.META
src/ocaml-flags-standard.sexp
)
AC_OUTPUT

Expand Down
4 changes: 2 additions & 2 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ endif
SRCEXTDIR = ../src_ext/lib

ifneq ($(wildcard $(SRCEXTDIR)),)
OCAMLDOC = ocamldoc $(patsubst %,-I %,$(SRCDIR) $(SRCEXTDIR))
OCAMLDOC = ocamldoc $(patsubst %,-I %,$(SRCDIR) $(SRCEXTDIR) +compiler-libs)
else
OCAMLDOC = ocamlfind ocamldoc $(patsubst %,-package %,$(PACKS)) $(patsubst %,-I %,$(SRCDIR))
OCAMLDOC = ocamlfind ocamldoc $(patsubst %,-package %,$(PACKS) compiler-libs.toplevel) $(patsubst %,-I %,$(SRCDIR))
endif

.PHONY: man html dev-manual pages
Expand Down
2 changes: 1 addition & 1 deletion jbuild-ignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
bootstrap
src_ext/jbuilder
tests
tests/packages
Empty file added jbuild-workspace.dev
Empty file.
Empty file added opam-admin.opam
Empty file.
Empty file added opam.opam
Empty file.
22 changes: 22 additions & 0 deletions shell/context_flags.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#directory "+compiler-libs";;
#load "ocamlcommon.cma";;

let p = String.index Sys.ocaml_version '.' in
let ocaml_major = String.sub Sys.ocaml_version 0 p |> int_of_string in
let p = succ p in
let ocaml_minor = String.sub Sys.ocaml_version p (String.index_from Sys.ocaml_version p '.' - p) |> int_of_string in
match Sys.argv.(1) with
| "flags" ->
if ocaml_major > 4 || ocaml_major = 4 && ocaml_minor >= 2 then
Printf.printf "(-safe-string)"
| "compat" ->
if ocaml_major < 4 || ocaml_major = 4 && ocaml_minor < 1 then begin
Printf.eprintf "Unsupported version of OCaml: %d.%02d\n" ocaml_major ocaml_minor;
exit 1
end else if ocaml_major = 4 && ocaml_minor < 3 then
Printf.printf "4.0%d" ocaml_minor
else
Printf.printf "4.03"
| _ ->
Printf.eprintf "Unrecognised context instruction: %s\n" Sys.argv.(1);
exit 1
70 changes: 70 additions & 0 deletions shell/subst_var.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
let name = Printf.sprintf "@%s@" Sys.argv.(1) in
let value =
let file, magic =
let root =
let rec process acc dir =
let dir' = Filename.dirname dir in
let base = Filename.basename dir in
if dir' = dir then
failwith "Invalid invocation - couldn't locate build root"
else
let acc = Filename.concat acc Filename.parent_dir_name in
if base = "_build" then
acc
else
process acc dir'
in
process "" (Sys.getcwd ())
in
let file = Filename.concat root "config.status" in
if Sys.file_exists file then
file, Printf.sprintf "S[\"%s\"]=\"" Sys.argv.(1)
else if Sys.argv.(1) = "PACKAGE_VERSION" then
Filename.concat root "configure.ac", "AC_INIT(opam,"
else
"", ""
in
if file <> "" then
let c = open_in file in
let magic_l = String.length magic in
(* End_of_file is permitted to leak as the failure of this build step *)
let rec process () =
let line = input_line c in
let line_l = String.length line in
if line_l > magic_l then
if String.sub line 0 magic_l = magic then begin
close_in c;
String.sub line magic_l (line_l - magic_l - 1)
end else
process ()
else
process ()
in
process ()
else
Sys.argv.(2)
in
let cin = open_in Sys.argv.(3) in
let name_l = String.length name in
let rec process () =
match input_line cin with
| exception End_of_file ->
close_in cin
| line ->
begin
try
let idx = String.index line '@' in
let line_l = String.length line in
if line_l > idx + name_l - 1 && String.sub line idx name_l = name then begin
if idx > 0 then
print_string (String.sub line 0 idx);
print_string value;
print_endline (String.sub line (idx + name_l) (line_l - idx - name_l));
end else
print_endline line
with Not_found ->
print_endline line
end;
process ()
in
process ()
56 changes: 56 additions & 0 deletions src/client/jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
(* -*- tuareg -*- *)

module J = Jbuild_plugin.V1

let (sha, version) =
let remove () =
try
Sys.remove "current-git-sha"
with _ ->
()
in
try
let _ = Sys.command "git rev-parse HEAD > current-git-sha" in
let c = open_in "current-git-sha" in
let sha =
try
input_line c
with _ ->
""
in
close_in c;
remove ();
if sha = "" then
raise Exit
else
(sha, Printf.sprintf "let version = Some \\\"%s\\\"" sha)
with _ ->
remove ();
("", "let version = None")

let () = Printf.ksprintf J.send {|
(jbuild_version 1)

(library
((name opam_client)
(public_name opam-client)
(synopsis "OCaml Package Manager client and CLI library")
(modules (:standard \ opamMain))
(libraries (opam-state opam-solver re.glob cmdliner))
(flags (:standard (:include ../ocaml-flags-standard.sexp) (:include ../ocaml-context-flags.sexp)))
(wrapped false)))

(executable
((name opamMain)
(public_name opam)
(package opam)
(modules opamMain)
(flags (:standard (:include ../ocaml-flags-standard.sexp) (:include ../ocaml-context-flags.sexp)))
(libraries (opam-client))))

(rule
(with-stdout-to opamGitVersion.ml (echo ${read-lines:git-sha-%s})))

(rule
(with-stdout-to git-sha-%s (echo "%s")))
|} sha sha version
34 changes: 34 additions & 0 deletions src/core/jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(jbuild_version 1)

(library
((name opam_core)
(public_name opam-core)
(synopsis "OCaml Package Manager core internal stdlib")
(libraries (re ocamlgraph unix bigarray))
(flags (:standard (:include ../ocaml-flags-standard.sexp) (:include ../ocaml-context-flags.sexp)))
(wrapped false)))

(rule
((targets (ocaml-compat.sexp))
(deps (../../shell/context_flags.ml))
(action (with-stdout-to ${@} (run ocaml ../../shell/context_flags.ml compat)))))

(rule
((targets (opamCompat.ml))
(deps (opamCompat.ml.4.01 opamCompat.ml.4.02 opamCompat.ml.4.03))
(action (copy ${@}.${read:ocaml-compat.sexp} ${@}))))

(rule
((targets (opamCompat.mli))
(deps (opamCompat.mli.4.01 opamCompat.mli.4.02 opamCompat.mli.4.03))
(action (copy ${@}.${read:ocaml-compat.sexp} ${@}))))

(rule
((targets (opamVersion.ml))
(deps (opamVersion.ml.in ../../shell/subst_var.ml))
(action (with-stdout-to ${@} (run ocaml ../../shell/subst_var.ml PACKAGE_VERSION "<error>" ${!^})))))

(rule
((targets (opamCoreConfig.ml))
(deps (opamCoreConfig.ml.in ../../shell/subst_var.ml))
(action (with-stdout-to ${@} (run ocaml ../../shell/subst_var.ml DEVELOPER false ${!^})))))
18 changes: 18 additions & 0 deletions src/format/jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(jbuild_version 1)

(library
((name opam_format)
(public_name opam-format)
(synopsis "OCaml Package Manager file format handling library")
(libraries (opam-core opam-file-format re.pcre re.posix))
(flags (:standard (:include ../ocaml-flags-standard.sexp) (:include ../ocaml-context-flags.sexp)))
(wrapped false)))

(ocamllex (opamLineLexer))

(rule
(with-stdout-to opamTypes.ml
(progn
(echo "module rec OpamTypes : sig\n")
(cat opamTypes.mli)
(echo "\nend = OpamTypes\ninclude OpamTypes\n"))))
11 changes: 11 additions & 0 deletions src/jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(jbuild_version 1)

(rule
((targets (ocaml-flags-standard.sexp))
(deps (ocaml-flags-standard.sexp.in ../shell/subst_var.ml))
(action (with-stdout-to ${@} (run ocaml ../shell/subst_var.ml CONF_OCAMLFLAGS "" ${!^})))))

(rule
((targets (ocaml-context-flags.sexp))
(deps (../shell/context_flags.ml))
(action (with-stdout-to ${@} (run ocaml ../shell/context_flags.ml flags)))))
1 change: 1 addition & 0 deletions src/ocaml-flags-standard.sexp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(-w +a-4-44-48 -short-paths @CONF_OCAMLFLAGS@)
9 changes: 9 additions & 0 deletions src/repository/jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(jbuild_version 1)

(library
((name opam_repository)
(public_name opam-repository)
(synopsis "OCaml Package Manager remote repository handling library")
(libraries (opam-format))
(flags (:standard (:include ../ocaml-flags-standard.sexp) (:include ../ocaml-context-flags.sexp)))
(wrapped false)))
9 changes: 9 additions & 0 deletions src/solver/jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(jbuild_version 1)

(library
((name opam_solver)
(public_name opam-solver)
(synopsis "OCaml Package Manager solver interaction library")
(libraries (opam-format cudf dose3.algo))
(flags (:standard (:include ../ocaml-flags-standard.sexp) (:include ../ocaml-context-flags.sexp)))
(wrapped false)))
21 changes: 21 additions & 0 deletions src/state/jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(jbuild_version 1)

(library
((name opam_state)
(public_name opam-state)
(libraries (opam-repository))
(synopsis "OCaml Package Manager instance management library")
(flags (:standard (:include ../ocaml-flags-standard.sexp) (:include ../ocaml-context-flags.sexp)))
(wrapped false)))

(rule
((targets (opamScript.ml))
(deps (../../shell/crunch.ml complete.sh complete.zsh prompt.sh))
(action (with-stdout-to ${@} (run ocaml ${!^})))))

(rule
(with-stdout-to opamStateTypes.ml
(progn
(echo "[@@@warning \"-a\"]\nmodule rec OpamStateTypes : sig\n")
(cat opamStateTypes.mli)
(echo "\nend = OpamStateTypes\ninclude OpamStateTypes\n"))))
26 changes: 26 additions & 0 deletions src/tools/jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(jbuild_version 1)

(executable
((name opam_admin_topstart)
(modules (opam_admin_top opam_admin_topstart))
(ocamlc_flags (:standard (:include ../ocaml-flags-standard.sexp) (:include ../ocaml-context-flags.sexp) -linkall))
(libraries (opam-client opam-file-format compiler-libs.toplevel re.glob))))

(install
((section bin)
(package opam-admin)
(files ((opam_admin_topstart.bc as opam-admin.top)))))

(executable
((name opam_check)
(modules (opam_check))
(flags (:standard (:include ../ocaml-flags-standard.sexp) (:include ../ocaml-context-flags.sexp)))
(libraries (opam-client))))

(executable
((name opam_installer)
(package opam)
(public_name opam-installer)
(modules (opam_installer))
(libraries (opam-state cmdliner))
(flags (:standard (:include ../ocaml-flags-standard.sexp) (:include ../ocaml-context-flags.sexp)))))
Loading

0 comments on commit 7c9955b

Please sign in to comment.