1 % (c) 2009-2024 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,
9 format_prob_version/1
10 ]).
11
12 :- set_prolog_flag(double_quotes, codes).
13
14 :- use_module(module_information,[module_info/2]).
15
16 :- module_info(group,infrastructure).
17 :- module_info(description,'This module contains the current version number of ProB together with automatically updated version control infos.').
18
19
20 version(1,13,1,'nightly',3). % next beta will be beta3
21 % SemanticBuildCounter is increasing for nightly/beta releases
22
23 version(Major,Minor,Service,Qualifier) :-
24 version(Major,Minor,Service,Qualifier,_SemanticBuildCounter).
25
26
27 % example call: compare_against_current_version([1,7],Res).
28 compare_against_current_version(NrList,Result) :- version(A,B,C,_,D),
29 compare_aux(NrList,[A,B,C,D],Result).
30
31 compare_aux([],_,current_matches).
32 compare_aux([Requested|RT],[Cur|CT],Res) :- Requested = Cur,!, compare_aux(RT,CT,Res).
33 compare_aux([Requested|_],[Cur|_],Res) :- is_newer(Requested,Cur),!, Res = current_older.
34 compare_aux(_,_,current_newer).
35
36 is_newer(final,Cur) :- Cur \= final.
37 % beta and final use same Counter scheme and are semantic-version wise identical
38 is_newer(Requested,Cur) :- number(Requested), number(Cur), Requested > Cur.
39
40 :- use_module(library(lists),[append/2]).
41 version_str(Str) :- version(V1,V2,V3,Suffix,_Counter),
42 number_codes(V1,C1),
43 number_codes(V2,C2),
44 number_codes(V3,C3),
45 atom_codes(Suffix,S),
46 append([C1,[0'.],C2,[0'.],C3,[0'-],S],C),
47 atom_codes(Str,C).
48
49 % version string with build counter
50 full_version_str(Str) :- version(V1,V2,V3,Suffix,Counter),
51 number_codes(V1,C1),
52 number_codes(V2,C2),
53 number_codes(V3,C3),
54 number_codes(Counter,C4),
55 atom_codes(Suffix,S),
56 append([C1,".",C2,".",C3,"-",S, "(",C4,")"],C),
57 atom_codes(Str,C).
58
59 semantic_build_counter(B) :- version(_,_,_,_,B).
60
61 format_prob_version(Stream) :-
62 version_str(VS), revision(Rev), semantic_build_counter(B), lastchangeddate(DD),
63 format(Stream,'ProB ~w~n Revision: ~w~n Build Counter: ~w~nDate: ~w',[VS,Rev,B,DD]).
64
65
66 % this file needs to be touched and committed for information below to be updated!
67
68 get_revision(R) :- catch(read_revision(R),_,R='no revision found').
69 get_lastchanged(R) :- catch(read_lastchanged(R),_,R='no lastchanged found').
70
71
72 % Tries to read the revision file generated by make.
73 % If it does not come from svn, the fallback revision number is used.
74 read_revision(A) :-
75 open('revision', read, ID),
76 read_line(ID,R), close(ID),
77 atom_codes(A,R).
78
79 read_lastchanged(A) :-
80 open('lastchanged', read, ID),
81 read_line(ID,R), close(ID),
82 atom_codes(A,R).
83
84 :- dynamic revision/1, lastchangeddate/1.
85 :- get_revision(X), assertz(revision(X)).
86 :- get_lastchanged(X), assertz(lastchangeddate(X)).