diff --git a/bootstrap b/bootstrap index e67b7c9..a53c005 100755 --- a/bootstrap +++ b/bootstrap @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh libs="unix.cma" @@ -6,21 +6,6 @@ OCAMLC="ocamlc -g -I +unix" OCAMLVER=$($OCAMLC -version) echo "$OCAMLVER" -rm -f lib/base/compat.ml -if [[ $OCAMLVER < "4.02.0" ]] ; then - echo "Using compat401.ml" - cp -f compat401.ml lib/base/compat.ml -else - if [[ $OCAMLVER < "4.03.0" ]] ; then - echo "Using compat402.ml" - cp -f compat402.ml lib/base/compat.ml - else - echo "Using compat403.ml" - cp -f compat403.ml lib/base/compat.ml - fi -fi - - extmodules="compat fugue filepath filesystem" coremodules="types gconf filetype dag libname pp expr utils modname taskdep helper dagutils process findlibConf scheduler prog dependencies generators hier meta metacache target dist project analyze configure prepare_types ppx_resolver prepare buildprogs build exception" commandmodules="sdist doc init help install" @@ -93,13 +78,13 @@ let project_version = "0.0.0" EOF cd src -FILES=() +FILES="" for mod in $mainmodules do echo "COMPILING $mod" [ -f "${mod}.mli" ] && $OCAMLC -I ../ -c "${mod}.mli" $OCAMLC -I ../ -c "${mod}.ml" - FILES+=("${mod}.cmo") + FILES="${FILES} ${mod}.cmo" done echo "LINKING obuild.bootstrap" # Link with all individual .cmo files for bootstrap @@ -107,7 +92,9 @@ ALLCMO="" for mod in $extmodules; do ALLCMO="$ALLCMO ${mod}.cmo"; done for mod in $coremodules; do ALLCMO="$ALLCMO ${mod}.cmo"; done for mod in $commandmodules; do ALLCMO="$ALLCMO ${mod}.cmo"; done -$OCAMLC -o ../obuild.bootstrap -I ../ ${libs} $ALLCMO "${FILES[@]}" + +$OCAMLC -o ../obuild.bootstrap -I ../ $libs $ALLCMO $FILES + cd .. rm -f lib/*.cmi lib/*.cmo lib/*.o diff --git a/compat401.ml b/compat401.ml deleted file mode 100644 index ec926e7..0000000 --- a/compat401.ml +++ /dev/null @@ -1,166 +0,0 @@ -let bytes_of_string = String.copy -let bytes_to_string = String.copy -let bytes_make = String.make -let bytes_create = String.create -let bytes_get = String.get -let bytes_set = String.set -let bytes_length = String.length -let bytes_index_from = String.index_from - -let buffer_add_subbytes = Buffer.add_substring - -(* Result type backport - introduced in OCaml 4.03 *) -type ('a, 'b) result = - | Ok of 'a - | Error of 'b - -module Result = struct - type ('a, 'b) t = ('a, 'b) result - - let ok x = Ok x - let error e = Error e - - let is_ok = function Ok _ -> true | Error _ -> false - let is_error = function Ok _ -> false | Error _ -> true - - let map f = function - | Ok x -> Ok (f x) - | Error e -> Error e - - let map_error f = function - | Ok x -> Ok x - | Error e -> Error (f e) - - let bind r f = match r with - | Ok x -> f x - | Error e -> Error e - - let value r ~default = match r with - | Ok x -> x - | Error _ -> default - - let get_ok = function - | Ok x -> x - | Error _ -> invalid_arg "Result.get_ok" - - let get_error = function - | Ok _ -> invalid_arg "Result.get_error" - | Error e -> e -end - -(* Option helpers *) -module Option = struct - let map f = function - | Some x -> Some (f x) - | None -> None - - let bind o f = match o with - | Some x -> f x - | None -> None - - let value o ~default = match o with - | Some x -> x - | None -> default - - let get = function - | Some x -> x - | None -> invalid_arg "Option.get" - - let is_some = function - | Some _ -> true - | None -> false - - let is_none = function - | Some _ -> false - | None -> true -end - -(* SafeList - List module with exception-safe operations *) -module SafeList = struct - include List - - let find_opt pred lst = - try Some (List.find pred lst) - with Not_found -> None - - let assoc_opt key lst = - try Some (List.assoc key lst) - with Not_found -> None - - let nth_opt lst n = - try Some (List.nth lst n) - with Failure _ | Invalid_argument _ -> None - - let filter_map f lst = - let rec aux acc = function - | [] -> List.rev acc - | x :: xs -> - match f x with - | Some y -> aux (y :: acc) xs - | None -> aux acc xs - in - aux [] lst - - let find_map f lst = - let rec aux = function - | [] -> None - | x :: xs -> - match f x with - | Some _ as result -> result - | None -> aux xs - in - aux lst -end - -(* SafeHashtbl - Hashtbl module with exception-safe operations *) -module SafeHashtbl = struct - include Hashtbl - - let find_opt tbl key = - try Some (Hashtbl.find tbl key) - with Not_found -> None - - let update tbl key f = - match find_opt tbl key with - | Some v -> Hashtbl.replace tbl key (f (Some v)) - | None -> Hashtbl.replace tbl key (f None) - - let find_default tbl key default = - try Hashtbl.find tbl key - with Not_found -> default - - let add_or_update tbl key ~default ~update = - match find_opt tbl key with - | Some v -> Hashtbl.replace tbl key (update v) - | None -> Hashtbl.add tbl key default -end - -(* SafeString - String module with exception-safe operations *) -module SafeString = struct - include String - - let index_opt str ch = - try Some (String.index str ch) - with Not_found -> None - - let rindex_opt str ch = - try Some (String.rindex str ch) - with Not_found -> None - - let index_from_opt str pos ch = - try Some (String.index_from str pos ch) - with Not_found | Invalid_argument _ -> None - - let rindex_from_opt str pos ch = - try Some (String.rindex_from str pos ch) - with Not_found | Invalid_argument _ -> None - - let sub_safe str start len = - try Some (String.sub str start len) - with Invalid_argument _ -> None - - let get_opt str idx = - try Some (String.get str idx) - with Invalid_argument _ -> None -end - diff --git a/compat402.ml b/compat402.ml deleted file mode 100644 index 2fbb582..0000000 --- a/compat402.ml +++ /dev/null @@ -1,171 +0,0 @@ -let bytes_of_string = Bytes.of_string -let bytes_to_string = Bytes.to_string -let bytes_make = Bytes.make -let bytes_create = Bytes.create -let bytes_get = Bytes.get -let bytes_set = Bytes.set -let bytes_length = Bytes.length -let bytes_index_from = Bytes.index_from - -let buffer_add_subbytes = Buffer.add_subbytes - -let string_uncapitalize = String.uncapitalize -let string_capitalize = String.capitalize -let string_lowercase = String.lowercase -let string_uppercase = String.uppercase -let char_uppercase = Char.uppercase - -(* Result type backport - introduced in OCaml 4.03 *) -type ('a, 'b) result = - | Ok of 'a - | Error of 'b - -module Result = struct - type ('a, 'b) t = ('a, 'b) result - - let ok x = Ok x - let error e = Error e - - let is_ok = function Ok _ -> true | Error _ -> false - let is_error = function Ok _ -> false | Error _ -> true - - let map f = function - | Ok x -> Ok (f x) - | Error e -> Error e - - let map_error f = function - | Ok x -> Ok x - | Error e -> Error (f e) - - let bind r f = match r with - | Ok x -> f x - | Error e -> Error e - - let value r ~default = match r with - | Ok x -> x - | Error _ -> default - - let get_ok = function - | Ok x -> x - | Error _ -> invalid_arg "Result.get_ok" - - let get_error = function - | Ok _ -> invalid_arg "Result.get_error" - | Error e -> e -end - -(* Option helpers *) -module Option = struct - let map f = function - | Some x -> Some (f x) - | None -> None - - let bind o f = match o with - | Some x -> f x - | None -> None - - let value o ~default = match o with - | Some x -> x - | None -> default - - let get = function - | Some x -> x - | None -> invalid_arg "Option.get" - - let is_some = function - | Some _ -> true - | None -> false - - let is_none = function - | Some _ -> false - | None -> true -end - -(* SafeList - List module with exception-safe operations *) -module SafeList = struct - include List - - let find_opt pred lst = - try Some (List.find pred lst) - with Not_found -> None - - let assoc_opt key lst = - try Some (List.assoc key lst) - with Not_found -> None - - let nth_opt lst n = - try Some (List.nth lst n) - with Failure _ | Invalid_argument _ -> None - - let filter_map f lst = - let rec aux acc = function - | [] -> List.rev acc - | x :: xs -> - match f x with - | Some y -> aux (y :: acc) xs - | None -> aux acc xs - in - aux [] lst - - let find_map f lst = - let rec aux = function - | [] -> None - | x :: xs -> - match f x with - | Some _ as result -> result - | None -> aux xs - in - aux lst -end - -(* SafeHashtbl - Hashtbl module with exception-safe operations *) -module SafeHashtbl = struct - include Hashtbl - - let find_opt tbl key = - try Some (Hashtbl.find tbl key) - with Not_found -> None - - let update tbl key f = - match find_opt tbl key with - | Some v -> Hashtbl.replace tbl key (f (Some v)) - | None -> Hashtbl.replace tbl key (f None) - - let find_default tbl key default = - try Hashtbl.find tbl key - with Not_found -> default - - let add_or_update tbl key ~default ~update = - match find_opt tbl key with - | Some v -> Hashtbl.replace tbl key (update v) - | None -> Hashtbl.add tbl key default -end - -(* SafeString - String module with exception-safe operations *) -module SafeString = struct - include String - - let index_opt str ch = - try Some (String.index str ch) - with Not_found -> None - - let rindex_opt str ch = - try Some (String.rindex str ch) - with Not_found -> None - - let index_from_opt str pos ch = - try Some (String.index_from str pos ch) - with Not_found | Invalid_argument _ -> None - - let rindex_from_opt str pos ch = - try Some (String.rindex_from str pos ch) - with Not_found | Invalid_argument _ -> None - - let sub_safe str start len = - try Some (String.sub str start len) - with Invalid_argument _ -> None - - let get_opt str idx = - try Some (String.get str idx) - with Invalid_argument _ -> None -end diff --git a/compat403.ml b/compat403.ml deleted file mode 100644 index cad7789..0000000 --- a/compat403.ml +++ /dev/null @@ -1,169 +0,0 @@ -let bytes_of_string = Bytes.of_string -let bytes_to_string = Bytes.to_string -let bytes_make = Bytes.make -let bytes_create = Bytes.create -let bytes_get = Bytes.get -let bytes_set = Bytes.set -let bytes_length = Bytes.length -let bytes_index_from = Bytes.index_from - -let buffer_add_subbytes = Buffer.add_subbytes - -let string_uncapitalize = String.uncapitalize_ascii -let string_capitalize = String.capitalize_ascii -let string_lowercase = String.lowercase_ascii -let string_uppercase = String.uppercase_ascii -let char_uppercase = Char.uppercase_ascii - -(* Result type - already available in OCaml 4.03+ but we redefine for compatibility *) -type ('a, 'b) result = Ok of 'a | Error of 'b - -module Result = struct - type ('a, 'b) t = ('a, 'b) result - - let ok x = Ok x - let error e = Error e - - let is_ok = function Ok _ -> true | Error _ -> false - let is_error = function Ok _ -> false | Error _ -> true - - let map f = function - | Ok x -> Ok (f x) - | Error e -> Error e - - let map_error f = function - | Ok x -> Ok x - | Error e -> Error (f e) - - let bind r f = match r with - | Ok x -> f x - | Error e -> Error e - - let value r ~default = match r with - | Ok x -> x - | Error _ -> default - - let get_ok = function - | Ok x -> x - | Error _ -> invalid_arg "Result.get_ok" - - let get_error = function - | Ok _ -> invalid_arg "Result.get_error" - | Error e -> e -end - -(* Option helpers *) -module Option = struct - let map f = function - | Some x -> Some (f x) - | None -> None - - let bind o f = match o with - | Some x -> f x - | None -> None - - let value o ~default = match o with - | Some x -> x - | None -> default - - let get = function - | Some x -> x - | None -> invalid_arg "Option.get" - - let is_some = function - | Some _ -> true - | None -> false - - let is_none = function - | Some _ -> false - | None -> true -end - -(* SafeList - List module with exception-safe operations *) -module SafeList = struct - include List - - let find_opt pred lst = - try Some (List.find pred lst) - with Not_found -> None - - let assoc_opt key lst = - try Some (List.assoc key lst) - with Not_found -> None - - let nth_opt lst n = - try Some (List.nth lst n) - with Failure _ | Invalid_argument _ -> None - - let filter_map f lst = - let rec aux acc = function - | [] -> List.rev acc - | x :: xs -> - match f x with - | Some y -> aux (y :: acc) xs - | None -> aux acc xs - in - aux [] lst - - let find_map f lst = - let rec aux = function - | [] -> None - | x :: xs -> - match f x with - | Some _ as result -> result - | None -> aux xs - in - aux lst -end - -(* SafeHashtbl - Hashtbl module with exception-safe operations *) -module SafeHashtbl = struct - include Hashtbl - - let find_opt tbl key = - try Some (Hashtbl.find tbl key) - with Not_found -> None - - let update tbl key f = - match find_opt tbl key with - | Some v -> Hashtbl.replace tbl key (f (Some v)) - | None -> Hashtbl.replace tbl key (f None) - - let find_default tbl key default = - try Hashtbl.find tbl key - with Not_found -> default - - let add_or_update tbl key ~default ~update = - match find_opt tbl key with - | Some v -> Hashtbl.replace tbl key (update v) - | None -> Hashtbl.add tbl key default -end - -(* SafeString - String module with exception-safe operations *) -module SafeString = struct - include String - - let index_opt str ch = - try Some (String.index str ch) - with Not_found -> None - - let rindex_opt str ch = - try Some (String.rindex str ch) - with Not_found -> None - - let index_from_opt str pos ch = - try Some (String.index_from str pos ch) - with Not_found | Invalid_argument _ -> None - - let rindex_from_opt str pos ch = - try Some (String.rindex_from str pos ch) - with Not_found | Invalid_argument _ -> None - - let sub_safe str start len = - try Some (String.sub str start len) - with Invalid_argument _ -> None - - let get_opt str idx = - try Some (String.get str idx) - with Invalid_argument _ -> None -end diff --git a/configure.ml b/configure.ml index f9c8bf7..9f91c77 100644 --- a/configure.ml +++ b/configure.ml @@ -1,8 +1 @@ -let version = Sys.ocaml_version in -ignore (Sys.command "rm -f lib/base/compat.ml"); -if version < "4.02.0" then - Sys.command "cp -f compat401.ml lib/base/compat.ml" -else if version < "4.03.0" then - Sys.command "cp -f compat402.ml lib/base/compat.ml" -else - Sys.command "cp -f compat403.ml lib/base/compat.ml" +let version = Sys.ocaml_version