| 1 |
# |
| 2 |
# This file is part of the LibreOffice project. |
| 3 |
# |
| 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/. |
| 7 |
# |
| 8 |
# This file incorporates work covered by the following license notice: |
| 9 |
# |
| 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 . |
| 17 |
# |
| 18 |
|
| 19 |
use warnings; |
| 20 |
use strict; |
| 21 |
use diagnostics; |
| 22 |
|
| 23 |
sub trim; |
| 24 |
sub readIncVersions($); |
| 25 |
sub processLine($$); |
| 26 |
sub checkName($); |
| 27 |
sub incrementNewVersion($); |
| 28 |
sub incrementOldVersion($); |
| 29 |
sub incrementPolicyVersion($); |
| 30 |
my $usage = |
| 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 update. 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 following terms: NEW_VERSION, OLD_VERSION, POLICY_VERSION\n". |
| 36 |
"If no new published types have 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" ; |
| 47 |
|
| 48 |
my $sNameForm = |
| 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"; |
| 52 |
|
| 53 |
if (scalar @ARGV < 3) { |
| 54 |
print $usage; |
| 55 |
exit -1; |
| 56 |
} |
| 57 |
|
| 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; |
| 61 |
|
| 62 |
# DISABLED: always increment |
| 63 |
#check if new types have been added since last release. |
| 64 |
#If not, then there is nothing to be done. |
| 65 |
#read in oldVersions line by line and apply the increment operation |
| 66 |
#open TYPES, "$ARGV[3]" or die "Cannot open to $ARGV[3] $!"; |
| 67 |
|
| 68 |
my $newTypes; |
| 69 |
|
| 70 |
#We look for the line that contains the number of new types |
| 71 |
#while(<TYPES>) |
| 72 |
#{ |
| 73 |
# if (/New and published types/i) |
| 74 |
# { |
| 75 |
# $_ =~ /=\s*(\d+)/; |
| 76 |
# if ( ! defined $1) |
| 77 |
# { |
| 78 |
# print "\n###$ARGV[3] contains an invalid entry for 'New and published types'. \n\n"; |
| 79 |
# exit -1; |
| 80 |
# } |
| 81 |
# $newTypes = $1; |
| 82 |
# } |
| 83 |
#} |
| 84 |
|
| 85 |
#Check if changeTypes contained the line we are looking for |
| 86 |
#if (! defined $newTypes) |
| 87 |
#{ |
| 88 |
# print "\n###$ARGV[3] does not contain entry about the new types ". |
| 89 |
# "or we are looking for the wrong string! \n\n"; |
| 90 |
# exit -1; |
| 91 |
#} |
| 92 |
|
| 93 |
#if ( $newTypes == 0) |
| 94 |
#{ |
| 95 |
# print "\nNo new UNO types since las product update.\n"; |
| 96 |
# exit 0; |
| 97 |
#} |
| 98 |
#else |
| 99 |
#{ |
| 100 |
# print "\nNew UNO types were added since last release. The version will be increased.\n\n"; |
| 101 |
#} |
| 102 |
|
| 103 |
#read in incVersions in a list |
| 104 |
my @incVersions = readIncVersions($ARGV[1]); |
| 105 |
#print "@incVersions"; |
| 106 |
|
| 107 |
#read in oldVersions line by line and apply the increment operation |
| 108 |
open OLDVERSION, "$ARGV[0]" or die "Cannot open to $ARGV[0] $!"; |
| 109 |
|
| 110 |
#open file we want to write to |
| 111 |
open NEWVERSION, "> $ARGV[2]" or die "Cannot write to $ARGV[2] $!"; |
| 112 |
|
| 113 |
print NEWVERSION processLine($_, @incVersions) while(<OLDVERSION>); |
| 114 |
|
| 115 |
close NEWVERSION; |
| 116 |
close OLDVERSION; |
| 117 |
|
| 118 |
exit 0; |
| 119 |
|
| 120 |
sub processLine($$) |
| 121 |
{ |
| 122 |
my $line = $_[0]; |
| 123 |
#skip empty lines |
| 124 |
my $trimmed; |
| 125 |
return $line if (length($trimmed = trim($line)) == 0); |
| 126 |
#Skip comment symbol: # |
| 127 |
return $line if ($trimmed =~ /^#/); |
| 128 |
|
| 129 |
#Get the left part of '=' |
| 130 |
my $i = index($line, "="); |
| 131 |
if( $i == -1) |
| 132 |
{ |
| 133 |
print "Error: No '=' found in line:,: \n $line \n"; |
| 134 |
exit -1; |
| 135 |
} |
| 136 |
my $name = substr($line, 0, $i); |
| 137 |
$name = trim($name); |
| 138 |
#We do not check the names here because the file can contain |
| 139 |
#other names, e.g. CLI_URETYPES_POLICY_ASSEMBLY |
| 140 |
if (length($name) == 0) { |
| 141 |
print "Wrong line in $ARGV[0]\n", $sNameForm; |
| 142 |
exit -1; |
| 143 |
} |
| 144 |
my $value = substr($line, $i + 1); |
| 145 |
$value = trim($value); |
| 146 |
|
| 147 |
#Check if the entry shall be incremented, this information is in the second |
| 148 |
#argument |
| 149 |
my $found; |
| 150 |
for(@incVersions) { |
| 151 |
if ($_ eq $name) { |
| 152 |
$found = 1; |
| 153 |
last; |
| 154 |
} |
| 155 |
} |
| 156 |
if ( ! defined($found)) { |
| 157 |
return $line; |
| 158 |
} |
| 159 |
|
| 160 |
#Check if the name represents a version we need to change |
| 161 |
if ($name =~ /NEW_VERSION$/) |
| 162 |
{ |
| 163 |
$value = incrementNewVersion($value); |
| 164 |
} |
| 165 |
elsif ($name =~ /OLD_VERSION$/) |
| 166 |
{ |
| 167 |
$value = incrementOldVersion($value); |
| 168 |
} |
| 169 |
elsif ($name =~ /POLICY_VERSION$/) |
| 170 |
{ |
| 171 |
$value = incrementPolicyVersion($value); |
| 172 |
} |
| 173 |
else |
| 174 |
{ |
| 175 |
#other name which we ignore |
| 176 |
return $line; |
| 177 |
} |
| 178 |
return "${name}=${value}\n"; |
| 179 |
} |
| 180 |
|
| 181 |
#The value of a new version has the form x.x.x.x |
| 182 |
#We increment the third position from the left. |
| 183 |
#Te argument must already be trimmed. |
| 184 |
sub incrementNewVersion($) |
| 185 |
{ |
| 186 |
my @parts = split /\./,$_[0]; |
| 187 |
if (scalar @parts != 4) |
| 188 |
{ |
| 189 |
print "Error, no valid version given in $ARGV[0]\n. A 'new version' has four parts."; |
| 190 |
exit -1; |
| 191 |
} |
| 192 |
$parts[2]++; |
| 193 |
#build the version string and return |
| 194 |
return "$parts[0].$parts[1].$parts[2].$parts[3]"; |
| 195 |
} |
| 196 |
|
| 197 |
#The value of a new version has the form x.x.x.x-x.x.x.x |
| 198 |
#We increment the third position of the second part. |
| 199 |
#Te argument must already be trimmed. |
| 200 |
sub incrementOldVersion($) |
| 201 |
{ |
| 202 |
my @parts = split /[\.-]/,$_[0]; |
| 203 |
if (scalar @parts != 8) |
| 204 |
{ |
| 205 |
print "Error, no valid version given in $ARGV[0]\n. A 'old version' has the form |
| 206 |
x.x.x.x-x.x.x.x\n."; |
| 207 |
exit -1; |
| 208 |
} |
| 209 |
$parts[6]++; |
| 210 |
return "$parts[0].$parts[1].$parts[2].$parts[3]-$parts[4].$parts[5].$parts[6].$parts[7]"; |
| 211 |
return $_[0]; |
| 212 |
} |
| 213 |
|
| 214 |
sub incrementPolicyVersion($) |
| 215 |
{ |
| 216 |
my @parts = split /\./,$_[0]; |
| 217 |
if (scalar @parts != 4) |
| 218 |
{ |
| 219 |
print "Error, no valid version given in $ARGV[0]\n. A 'policy version' has four parts."; |
| 220 |
exit -1; |
| 221 |
} |
| 222 |
$parts[0]++; |
| 223 |
#build the version string and return |
| 224 |
return "$parts[0].$parts[1].$parts[2].$parts[3]"; |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
sub readIncVersions($) |
| 229 |
{ |
| 230 |
open INC, $_[0] or die "Could not open $_[0] $!"; |
| 231 |
my $arg = $_[0]; |
| 232 |
my @names; |
| 233 |
|
| 234 |
while(<INC>) |
| 235 |
{ |
| 236 |
chomp; |
| 237 |
#Skip empty lines |
| 238 |
my $line; |
| 239 |
if (length($line = trim($_)) == 0) { |
| 240 |
next; |
| 241 |
} |
| 242 |
#Skip comment symbol: # |
| 243 |
if ($line =~ /^#/) { |
| 244 |
next; |
| 245 |
} |
| 246 |
if (!checkName($line)) { |
| 247 |
print "Wrong entry in file $_[0]\n", $sNameForm; |
| 248 |
exit -1; |
| 249 |
} |
| 250 |
push @names, $line; |
| 251 |
} |
| 252 |
print "No entries found in $arg\n" if(scalar @names == 0); |
| 253 |
return @names; |
| 254 |
} |
| 255 |
|
| 256 |
#The argument must already be trimmed |
| 257 |
#returns 1 if ok |
| 258 |
sub checkName($) |
| 259 |
{ |
| 260 |
my $name = $_[0]; |
| 261 |
if ( $name !~/NEW_VERSION$|OLD_VERSION$|POLICY_VERSION$/) { |
| 262 |
return 0; |
| 263 |
} |
| 264 |
return 1; |
| 265 |
} |
| 266 |
|
| 267 |
sub trim($) |
| 268 |
{ |
| 269 |
my $string = shift; |
| 270 |
$string =~ s/^\s+//; |
| 271 |
$string =~ s/\s+$//; |
| 272 |
return $string; |
| 273 |
} |