Skip to content

Commit 9038166

Browse files
committed
Added support for detecting release candidate version numbers
1 parent 58b2cb1 commit 9038166

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### 4.5.1 (2019-10-11)
2+
3+
* Fixed warnings in C-stubs
4+
5+
* Support detection of release candidate version numbers
6+
7+
18
### 4.5.0 (2019-06-06)
29

310
* Added support for `put_copy_data`, `put_copy_end`, and `get_copy_data`

src/config/discover.ml

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
open Base
22
open Stdio
33

4+
let find_number ~pos str =
5+
let len = String.length str in
6+
let rec skip_other ~pos =
7+
if pos = len then pos
8+
else
9+
match str.[pos] with
10+
| '0'..'9' -> pos
11+
| _ -> skip_other ~pos:(pos + 1)
12+
in
13+
let pos = skip_other ~pos in
14+
let rec loop ~pos =
15+
if pos = len then [], pos
16+
else match str.[pos] with
17+
| '0'..'9' as c ->
18+
let acc, next = loop ~pos:(pos + 1) in
19+
String.make 1 c :: acc, next
20+
| _ -> [], pos
21+
in
22+
let number_lst, next = loop ~pos in
23+
String.concat number_lst, next
24+
425
let () =
526
let module C = Configurator.V1 in
627
C.main ~name:"postgresql" (fun _c ->
@@ -17,40 +38,24 @@ let () =
1738
let print_fail () =
1839
eprintf "Unable to find versions from line '%s', cmd: '%s'" line cmd
1940
in
41+
let exit_fail () = print_fail (); Caml.exit 1 in
2042
try
2143
let first_space = String.index_exn line ' ' in
22-
let first_dot = String.index_exn line '.' in
23-
let first_part =
24-
let len = first_dot - first_space - 1 in
25-
String.sub line ~pos:(first_space + 1) ~len
26-
in
27-
let second_part =
28-
let len = String.length line - first_dot - 1 in
29-
String.sub line ~pos:(first_dot + 1) ~len
30-
in
31-
let search_version s =
32-
let version = ref "" in
33-
let stop = ref false in
34-
let check_car c =
35-
let ascii = Char.to_int c in
36-
if (ascii >= 48 && ascii <= 57 && not !stop) then
37-
version := !version ^ (String.make 1 c)
38-
else stop := true
39-
in
40-
let () = String.iter ~f:check_car s in
41-
!version
44+
let major, next = find_number ~pos:first_space line in
45+
let minor =
46+
(* Can also handle release candidates *)
47+
let c = line.[next] in
48+
if Char.(c = '.') then fst (find_number ~pos:next line)
49+
else if Char.(c <> 'r' || line.[next + 1] <> 'c') then exit_fail ()
50+
else "0"
4251
in
43-
let major = search_version first_part in
44-
let minor = search_version second_part in
45-
if String.(major <> "" && minor <> "") then
52+
if String.(major = "" || minor = "") then exit_fail ()
53+
else
4654
"-DPG_OCAML_MAJOR_VERSION=" ^ major,
4755
"-DPG_OCAML_MINOR_VERSION=" ^ minor
48-
else begin
49-
print_fail ();
50-
Caml.exit 1
51-
end
5256
with exn -> print_fail (); raise exn
5357
in
58+
eprintf "major: %s, minor: %s" major minor;
5459
let conf = {
5560
C.Pkg_config.
5661
cflags = [pgsql_includedir; major; minor];

0 commit comments

Comments
 (0)