| 1 |
#!/usr/bin/env perl |
| 2 |
# Copyright (c) MediaTek USA Inc., 2022-2023 |
| 3 |
# |
| 4 |
# This program is free software; you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation; either version 2 of the License, or (at |
| 7 |
# your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, but |
| 10 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
# General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program; if not, see |
| 16 |
# <http://www.gnu.org/licenses/>. |
| 17 |
# |
| 18 |
# |
| 19 |
# gitversion [--p4] [--md5] [--prefix path] pathname OR |
| 20 |
# gitversion [--p4] [--md5] [--prefix path] --compare old_version new_version pathname |
| 21 |
# |
| 22 |
# If the '--p4' flag is used: |
| 23 |
# we assume that the GIT repo is cloned from Perforce - and look for |
| 24 |
# the line in the generated commit log message which tells us the perforce |
| 25 |
# changelist ID that we actually want. |
| 26 |
# If specified, 'path' is prependied to 'pathname' (as 'path/pathname') |
| 27 |
# before processing. |
| 28 |
|
| 29 |
# This is a sample script which uses git commands to determine |
| 30 |
# the version of the filename parameter. |
| 31 |
# Version information (if present) is used during ".info" file merging |
| 32 |
# to verify that the data the user is attempting to merge is for the same |
| 33 |
# source code/same version. |
| 34 |
# If the version is not the same - then line numbers, etc. may be different |
| 35 |
# and some very strange errors may occur. |
| 36 |
|
| 37 |
use strict; |
| 38 |
use Getopt::Long; |
| 39 |
use FindBin; |
| 40 |
use lib "$FindBin::RealBin"; |
| 41 |
use gitversion qw(new usage); |
| 42 |
|
| 43 |
my $class = gitversion->new($0, @ARGV); |
| 44 |
# need to check if this is a --compare call or not |
| 45 |
my ($compare, $mapp4, $use_md5, $prefix, $allow_missing, $help); |
| 46 |
if (!GetOptions("--compare" => \$compare, |
| 47 |
"--md5" => \$use_md5, |
| 48 |
"--p4" => \$mapp4, |
| 49 |
'--prefix:s' => \$prefix, |
| 50 |
'--allow-missing' => \$allow_missing, |
| 51 |
'--help' => \$help) || |
| 52 |
$help || |
| 53 |
$compare && scalar(@ARGV) != 3 |
| 54 |
) { |
| 55 |
gitversion::usage($help); |
| 56 |
exit $help ? 0 : 1; |
| 57 |
} |
| 58 |
|
| 59 |
if ($compare) { |
| 60 |
exit $class->compare_version(@ARGV); |
| 61 |
} else { |
| 62 |
print $class->extract_version(@ARGV) . "\n"; |
| 63 |
} |
| 64 |
exit 0; |