2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
24 sub readIncVersions
($);
27 sub incrementNewVersion
($);
28 sub incrementOldVersion
($);
29 sub incrementPolicyVersion
($);
31 "The tool increments the minor version of assemblies and the major version of ".
32 "the respective policy files. This is only done if new uno types have been added since".
33 "the last product upate. This information is obtained from the file which is passed as ".
34 "argument changedTypes. The names in the version file must have a particular form. ".
35 "They must end on one of folling terms: NEW_VERSION, OLD_VERSION, POLICY_VERSION\n".
36 "If no new published types habe been added then no output, argument newVersions, is written".
37 "Usage is: \n increment_version.pl oldVersions incVersions newVersions changedTypes\n\n".
38 "oldVersion: Contains name value pairs, which are used for forming the config files of ".
39 "the policy assemblies, for building the assemblies. \n\n".
40 "incVersions: File containing the names of which the versions are to be incremented. ".
41 "Every line may only contain one name. The names must exactly match those from the ".
42 "oldVersion file.\n\n".
43 "newVersions: Contains all entries from oldVersions, but the values of the names,".
44 "which occur in selection, have been incremented.\n\n".
45 "changedTypes: File that contains the information if new published types have been added ".
46 "since the last product update.\n\n" ;
49 "The names must end on one of these names: NEW_VERSION, OLD_VERSION, POLICY_VERSION\n".
50 "For example, valid names are: \n".
51 "CLI_URETYPES_NEW_VERSION\nCLI_URETYPES_OLD_VERSION\nCLI_URETYPES_POLICY_VERSION\n";
53 if (scalar @ARGV < 4) {
58 -e
"$ARGV[0]" or die "Error: wrong arguments. \n".$usage;
59 -e
"$ARGV[1]" or die "Error: wrong arguments. \n".$usage;
60 -e
"$ARGV[3]" or die "Error: wrong arguments. \n".$usage;
62 #check if new types have been added since last release.
63 #If not, then there is nothing to be done.
64 #read in oldVersions line by line and apply the increment operation
65 open TYPES
, "$ARGV[3]" or die "Cannot open to $ARGV[3] $!";
69 #We look for the line that contains the number of new types
72 if (/New and published types/i)
77 print "\n###$ARGV[3] contains an invalid entry for 'New and published types'. \n\n";
84 #Check if changeTypes contained the line we are looking for
85 if (! defined $newTypes)
87 print "\n###$ARGV[3] does not contain entry about the new types ".
88 "or we are looking for the wrong string! \n\n";
94 print "\nNo new UNO types since las product update.\n";
99 print "\nNew UNO types were addes since last release. The version will be increased.\n\n";
102 #read in incVersions in a list
103 my @incVersions = readIncVersions
($ARGV[1]);
104 #print "@incVersions";
106 #read in oldVersions line by line and apply the increment operation
107 open OLDVERSION
, "$ARGV[0]" or die "Cannot open to $ARGV[0] $!";
109 #open file we want to write to
110 open NEWVERSION
, "> $ARGV[2]" or die "Cannot write to $ARGV[2] $!";
112 print NEWVERSION processLine
($_, @incVersions) while(<OLDVERSION
>);
124 return $line if (length($trimmed = trim
($line)) == 0);
125 #Skip comment symbol: #
126 return $line if ($trimmed =~ /^#/);
128 #Get the left part of '='
129 my $i = index($line, "=");
132 print "Error: No '=' found in line:,: \n $line \n";
135 my $name = substr($line, 0, $i);
137 #We do not check the names here because the file can contain
138 #other names, e.g. CLI_URETYPES_POLICY_ASSEMBLY
139 if (length($name) == 0) {
140 print "Wrong line in $ARGV[0]\n", $sNameForm;
143 my $value = substr($line, $i + 1);
144 $value = trim
($value);
146 #Check if the entry shall be incremented, this information is in the second
155 if ( ! defined($found)) {
159 #Check if the name represents a version we need to change
160 if ($name =~ /NEW_VERSION$/)
162 $value = incrementNewVersion
($value);
164 elsif ($name =~ /OLD_VERSION$/)
166 $value = incrementOldVersion
($value);
168 elsif ($name =~ /POLICY_VERSION$/)
170 $value = incrementPolicyVersion
($value);
174 #other name which we ignore
177 return "${name}=${value}\n";
180 #The value of a new version has the form x.x.x.x
181 #We increment the third position from the left.
182 #Te argument must already be trimmed.
183 sub incrementNewVersion
($)
185 my @parts = split /\./,$_[0];
186 if (scalar @parts != 4)
188 print "Error, no valid version given in $ARGV[0]\n. A 'new version' has four parts.";
192 #build the version string and return
193 return "$parts[0].$parts[1].$parts[2].$parts[3]";
196 #The value of a new version has the form x.x.x.x-x.x.x.x
197 #We increment the third position of the second part.
198 #Te argument must already be trimmed.
199 sub incrementOldVersion
($)
201 my @parts = split /[\.-]/,$_[0];
202 if (scalar @parts != 8)
204 print "Error, no valid version given in $ARGV[0]\n. A 'old version' has the form
209 return "$parts[0].$parts[1].$parts[2].$parts[3]-$parts[4].$parts[5].$parts[6].$parts[7]";
213 sub incrementPolicyVersion
($)
215 my @parts = split /\./,$_[0];
216 if (scalar @parts != 4)
218 print "Error, no valid version given in $ARGV[0]\n. A 'policy version' has four parts.";
222 #build the version string and return
223 return "$parts[0].$parts[1].$parts[2].$parts[3]";
227 sub readIncVersions
($)
229 open INC
, $_[0] or die "Could not open $_[0] $!";
238 if (length($line = trim
($_)) == 0) {
241 #Skip comment symbol: #
245 if (!checkName
($line)) {
246 print "Wrong entry in file $_[0]\n", $sNameForm;
251 print "No entries found in $arg\n" if(scalar @names == 0);
255 #The argument must already be trimmed
260 if ( $name !~/NEW_VERSION$|OLD_VERSION$|POLICY_VERSION$/) {