1 % (c) 2009-2026 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
2 % Heinrich Heine Universitaet Duesseldorf
3 % This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
4
5 :- module(version, [ version/4, version/5, version_str/1, full_version_str/1,
6 revision/1, semantic_build_counter/1,
7 lastchangeddate/1,
8 compare_against_current_version/2, compare_against_current_version/6,
9 format_prob_version/1,
10 format_prolog_version/1
11 ]).
12
13 :- set_prolog_flag(double_quotes, codes).
14
15 :- use_module(module_information,[module_info/2]).
16
17 :- module_info(group,infrastructure).
18 :- module_info(description,'This module contains the current version number of ProB together with automatically updated version control infos.').
19
20
21 version(1,16,2,'beta',1). % third arg is nightly, beta or final. The last beta was 1.16.0-beta1
22 % SemanticBuildCounter is last argument which is increasing for nightly/beta releases
23
24 version(Major,Minor,Service,Qualifier) :-
25 version(Major,Minor,Service,Qualifier,_SemanticBuildCounter).
26
27 %compare_against_current_version(Major,Minor,Service,Result) :-
28 % compare_against_current_version([Major,Minor,Service],Result).
29 compare_against_current_version(Major,Minor,Service,Qualifier,SBC,Result) :-
30 compare_against_current_version([Major,Minor,Service,Qualifier,SBC],Result).
31
32 % example call: compare_against_current_version([1,7],Res).
33 compare_against_current_version(NrList,Result) :- version(A,B,C,_,D),
34 compare_aux(NrList,[A,B,C,D],Result).
35
36 compare_aux([],_,current_matches).
37 compare_aux([Requested|RT],[Cur|CT],Res) :- Requested = Cur,!, compare_aux(RT,CT,Res).
38 compare_aux([Requested|_],[Cur|_],Res) :- is_newer(Requested,Cur),!, Res = current_older.
39 compare_aux(_,_,current_newer).
40
41 is_newer(final,Cur) :- Cur \= final.
42 % beta and final use same Counter scheme and are semantic-version wise identical
43 is_newer(Requested,Cur) :- number(Requested), number(Cur), Requested > Cur.
44
45 :- use_module(library(lists),[append/2]).
46 version_str(Str) :- version(V1,V2,V3,Suffix,_Counter),
47 number_codes(V1,C1),
48 number_codes(V2,C2),
49 number_codes(V3,C3),
50 atom_codes(Suffix,S),
51 append([C1,[0'.],C2,[0'.],C3,[0'-],S],C),
52 atom_codes(Str,C).
53
54 % version string with build counter
55 full_version_str(Str) :- version(V1,V2,V3,Suffix,Counter),
56 number_codes(V1,C1),
57 number_codes(V2,C2),
58 number_codes(V3,C3),
59 number_codes(Counter,C4),
60 (Suffix=final -> SemanticCounter = [] ; SemanticCounter = [ "(",C4,")"]),
61 atom_codes(Suffix,S),
62 append([C1,".",C2,".",C3,"-",S | SemanticCounter],C),
63 atom_codes(Str,C).
64
65 semantic_build_counter(B) :- version(_,_,_,_,B).
66
67 format_prob_version(Stream) :-
68 version_str(VS), revision(Rev), semantic_build_counter(B), lastchangeddate(DD),
69 format(Stream,'ProB ~w~n Revision: ~w~n Build Counter: ~w~nDate: ~w',[VS,Rev,B,DD]).
70 format_prolog_version(Stream) :-
71 current_prolog_flag(dialect, Dialect),
72 (Dialect= swi, current_prolog_flag(version_git,PV) -> true
73 ; current_prolog_flag(version,PV) % also works on SWI, but provides longer string
74 ),
75 format(Stream,'Prolog (~w) version: ~p',[Dialect, PV]).
76
77 % this file needs to be touched and committed for information below to be updated!
78
79 get_revision(R) :- catch(read_revision(R),_,R='no revision found').
80 get_lastchanged(R) :- catch(read_lastchanged(R),_,R='no lastchanged found').
81
82
83 % Tries to read the revision file generated by make.
84 % If it does not come from svn, the fallback revision number is used.
85 read_revision(A) :-
86 open('revision', read, ID),
87 read_line(ID,R), close(ID),
88 atom_codes(A,R).
89
90 read_lastchanged(A) :-
91 open('lastchanged', read, ID),
92 read_line(ID,R), close(ID),
93 atom_codes(A,R).
94
95 :- dynamic revision/1, lastchangeddate/1.
96 :- get_revision(X), assertz(revision(X)).
97 :- get_lastchanged(X), assertz(lastchangeddate(X)).