| 1 | % (c) 2009-2025 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 | 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,15,1,'nightly',0). % third arg is nightly, beta or final. The last beta was 1.13.1-beta2 | |
| 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 | ||
| 28 | % example call: compare_against_current_version([1,7],Res). | |
| 29 | compare_against_current_version(NrList,Result) :- version(A,B,C,_,D), | |
| 30 | compare_aux(NrList,[A,B,C,D],Result). | |
| 31 | ||
| 32 | compare_aux([],_,current_matches). | |
| 33 | compare_aux([Requested|RT],[Cur|CT],Res) :- Requested = Cur,!, compare_aux(RT,CT,Res). | |
| 34 | compare_aux([Requested|_],[Cur|_],Res) :- is_newer(Requested,Cur),!, Res = current_older. | |
| 35 | compare_aux(_,_,current_newer). | |
| 36 | ||
| 37 | is_newer(final,Cur) :- Cur \= final. | |
| 38 | % beta and final use same Counter scheme and are semantic-version wise identical | |
| 39 | is_newer(Requested,Cur) :- number(Requested), number(Cur), Requested > Cur. | |
| 40 | ||
| 41 | :- use_module(library(lists),[append/2]). | |
| 42 | version_str(Str) :- version(V1,V2,V3,Suffix,_Counter), | |
| 43 | number_codes(V1,C1), | |
| 44 | number_codes(V2,C2), | |
| 45 | number_codes(V3,C3), | |
| 46 | atom_codes(Suffix,S), | |
| 47 | append([C1,[0'.],C2,[0'.],C3,[0'-],S],C), | |
| 48 | atom_codes(Str,C). | |
| 49 | ||
| 50 | % version string with build counter | |
| 51 | full_version_str(Str) :- version(V1,V2,V3,Suffix,Counter), | |
| 52 | number_codes(V1,C1), | |
| 53 | number_codes(V2,C2), | |
| 54 | number_codes(V3,C3), | |
| 55 | number_codes(Counter,C4), | |
| 56 | (Suffix=final -> SemanticCounter = [] ; SemanticCounter = [ "(",C4,")"]), | |
| 57 | atom_codes(Suffix,S), | |
| 58 | append([C1,".",C2,".",C3,"-",S | SemanticCounter],C), | |
| 59 | atom_codes(Str,C). | |
| 60 | ||
| 61 | semantic_build_counter(B) :- version(_,_,_,_,B). | |
| 62 | ||
| 63 | format_prob_version(Stream) :- | |
| 64 | version_str(VS), revision(Rev), semantic_build_counter(B), lastchangeddate(DD), | |
| 65 | format(Stream,'ProB ~w~n Revision: ~w~n Build Counter: ~w~nDate: ~w',[VS,Rev,B,DD]). | |
| 66 | format_prolog_version(Stream) :- | |
| 67 | current_prolog_flag(dialect, Dialect), | |
| 68 | (Dialect= swi, current_prolog_flag(version_git,PV) -> true | |
| 69 | ; current_prolog_flag(version,PV) % also works on SWI, but provides longer string | |
| 70 | ), | |
| 71 | format(Stream,'Prolog (~w) version: ~p',[Dialect, PV]). | |
| 72 | ||
| 73 | % this file needs to be touched and committed for information below to be updated! | |
| 74 | ||
| 75 | get_revision(R) :- catch(read_revision(R),_,R='no revision found'). | |
| 76 | get_lastchanged(R) :- catch(read_lastchanged(R),_,R='no lastchanged found'). | |
| 77 | ||
| 78 | ||
| 79 | % Tries to read the revision file generated by make. | |
| 80 | % If it does not come from svn, the fallback revision number is used. | |
| 81 | read_revision(A) :- | |
| 82 | open('revision', read, ID), | |
| 83 | read_line(ID,R), close(ID), | |
| 84 | atom_codes(A,R). | |
| 85 | ||
| 86 | read_lastchanged(A) :- | |
| 87 | open('lastchanged', read, ID), | |
| 88 | read_line(ID,R), close(ID), | |
| 89 | atom_codes(A,R). | |
| 90 | ||
| 91 | :- dynamic revision/1, lastchangeddate/1. | |
| 92 | :- get_revision(X), assertz(revision(X)). | |
| 93 | :- get_lastchanged(X), assertz(lastchangeddate(X)). |