| 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 | ]). | |
| 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,15,1,'nightly',0). % third arg is nightly, beta or final. The last beta was 1.13.1-beta2 | |
| 21 | % SemanticBuildCounter is last argument which 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 | (Suffix=final -> SemanticCounter = [] ; SemanticCounter = [ "(",C4,")"]), | |
| 56 | atom_codes(Suffix,S), | |
| 57 | append([C1,".",C2,".",C3,"-",S | SemanticCounter],C), | |
| 58 | atom_codes(Str,C). | |
| 59 | ||
| 60 | semantic_build_counter(B) :- version(_,_,_,_,B). | |
| 61 | ||
| 62 | format_prob_version(Stream) :- | |
| 63 | version_str(VS), revision(Rev), semantic_build_counter(B), lastchangeddate(DD), | |
| 64 | format(Stream,'ProB ~w~n Revision: ~w~n Build Counter: ~w~nDate: ~w',[VS,Rev,B,DD]). | |
| 65 | ||
| 66 | ||
| 67 | % this file needs to be touched and committed for information below to be updated! | |
| 68 | ||
| 69 | get_revision(R) :- catch(read_revision(R),_,R='no revision found'). | |
| 70 | get_lastchanged(R) :- catch(read_lastchanged(R),_,R='no lastchanged found'). | |
| 71 | ||
| 72 | ||
| 73 | % Tries to read the revision file generated by make. | |
| 74 | % If it does not come from svn, the fallback revision number is used. | |
| 75 | read_revision(A) :- | |
| 76 | open('revision', read, ID), | |
| 77 | read_line(ID,R), close(ID), | |
| 78 | atom_codes(A,R). | |
| 79 | ||
| 80 | read_lastchanged(A) :- | |
| 81 | open('lastchanged', read, ID), | |
| 82 | read_line(ID,R), close(ID), | |
| 83 | atom_codes(A,R). | |
| 84 | ||
| 85 | :- dynamic revision/1, lastchangeddate/1. | |
| 86 | :- get_revision(X), assertz(revision(X)). | |
| 87 | :- get_lastchanged(X), assertz(lastchangeddate(X)). |