| 6861 |
dpurdie |
1 |
########################################################################
|
|
|
2 |
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
|
|
|
3 |
#
|
|
|
4 |
# Module name : PackagerUtils.pm
|
|
|
5 |
# Module type : JATS Utility
|
|
|
6 |
# Compiler(s) : Perl
|
|
|
7 |
# Environment(s): jats
|
|
|
8 |
#
|
|
|
9 |
# Description : Some utilities common to:
|
|
|
10 |
# Build-Time
|
|
|
11 |
# Debian Packager
|
|
|
12 |
# RPM Packager
|
|
|
13 |
# Run-Time
|
|
|
14 |
# DebianPackager Runtime
|
|
|
15 |
#
|
|
|
16 |
# Usage : See function headers
|
|
|
17 |
#
|
|
|
18 |
#......................................................................#
|
|
|
19 |
|
|
|
20 |
require 5.008_002;
|
|
|
21 |
use strict;
|
|
|
22 |
use warnings;
|
|
|
23 |
|
|
|
24 |
use JatsError;
|
|
|
25 |
|
|
|
26 |
#-------------------------------------------------------------------------------
|
|
|
27 |
# Function : canonicalName
|
|
|
28 |
#
|
|
|
29 |
# Description : Convert a Jats package name to a name suitable for the current
|
|
|
30 |
# target: RPM or Debian
|
|
|
31 |
#
|
|
|
32 |
# Used to transform names for the Packager 'Depends' list
|
|
|
33 |
#
|
|
|
34 |
#
|
|
|
35 |
# Inputs : $rawName - Current Name
|
|
|
36 |
# $type - Target Type: Debian or RPM
|
|
|
37 |
# $quiet - true: No warnings
|
|
|
38 |
#
|
|
|
39 |
# Returns : $canonicalName
|
|
|
40 |
# May not return
|
|
|
41 |
#
|
|
|
42 |
sub canonicalName
|
|
|
43 |
{
|
|
|
44 |
my ($rawName, $type, $quiet) = @_;
|
|
|
45 |
my $canonicalName = $rawName;
|
|
|
46 |
my $quietFn = $quiet ? \&Verbose : \&Warning;
|
|
|
47 |
|
|
|
48 |
if ($type =~ m~Debian~i) {
|
|
|
49 |
|
|
|
50 |
# Debian has stricter requirements than JATS
|
|
|
51 |
# Name: Lower case letters (a-z), digits (0-9), plus (+) and minus (-) signs, and periods (.).
|
|
|
52 |
# Release Manager does not allow '.'
|
|
|
53 |
# Version: alphanumerics and the characters . + - : (full stop, plus, hyphen, colon) and should start with a digit
|
|
|
54 |
#
|
|
|
55 |
# Allow ( and cleanup )
|
|
|
56 |
# ERGxxxxx -> erg-xxx
|
|
|
57 |
# VIXxxxxx -> vix-xxx
|
|
|
58 |
# Whitespace -> -
|
|
|
59 |
# _ -> -
|
|
|
60 |
# Remove multiple '-' characters
|
|
|
61 |
# Lowercase all text
|
|
|
62 |
|
|
|
63 |
my $cvt = 0;
|
|
|
64 |
$cvt = 1 if ( $canonicalName =~ s/^ERG/erg-/ );
|
|
|
65 |
$cvt = 2 if ( $canonicalName =~ s/^VIX/vix-/ );
|
|
|
66 |
$cvt = 3 if ( $canonicalName =~ s~\s~-~g );
|
|
|
67 |
$cvt = 4 if ( $canonicalName =~ s~_~-~g );
|
|
|
68 |
$cvt = 5 if ( $canonicalName =~ s~--+~-~g );
|
|
|
69 |
if ( $canonicalName =~ m/[A-Z]/ )
|
|
|
70 |
{
|
|
|
71 |
$cvt = 6;
|
|
|
72 |
$canonicalName = lc $canonicalName;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
$quietFn->("Package Name ($rawName) converted to debian form: $canonicalName")
|
|
|
76 |
if ( $cvt );
|
|
|
77 |
|
|
|
78 |
unless ( $canonicalName =~ m/^[a-z][-+a-z0-9]+$/ )
|
|
|
79 |
{
|
|
|
80 |
Error ("Package Name does not conform to Debian Requirements",
|
|
|
81 |
"and cannot be massaged into a conforming name",
|
|
|
82 |
"Must be at least two characters long",
|
|
|
83 |
"Must start with an alphabetic character",
|
|
|
84 |
"Must only contain: (a-z) (0-9) and -",
|
|
|
85 |
"Provided Name: $rawName",
|
|
|
86 |
"Massaged: $canonicalName");
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
} elsif ($type =~ m~Rpm~i) {
|
|
|
90 |
|
|
|
91 |
# Sanity check the package name and version
|
|
|
92 |
# RedHat has stricter requirements than JATS
|
|
|
93 |
# Name: Upper and Lower case letters (a-z), digits (0-9), plus (+) and minus (-) signs, and periods (.).
|
|
|
94 |
# '-' is used as a field seperator, although it is allowed in names
|
|
|
95 |
# Release Manager does not allow '.'
|
|
|
96 |
# Version: alphanumerics and the characters . + - : (full stop, plus, hyphen, colon) and should start with a digit
|
|
|
97 |
#
|
|
|
98 |
# Allow ( and cleanup )
|
|
|
99 |
# Whitespace -> -
|
|
|
100 |
# _ -> -
|
|
|
101 |
# Remove multiple '-' characters
|
|
|
102 |
# Lowercase all text
|
|
|
103 |
#
|
|
|
104 |
my $cvt = 0;
|
|
|
105 |
$cvt = 3 if ( $canonicalName =~ s~\s~_~g );
|
|
|
106 |
$cvt = 4 if ( $canonicalName =~ s~-~_~g );
|
|
|
107 |
$cvt = 5 if ( $canonicalName =~ s~__+~-~g );
|
|
|
108 |
|
|
|
109 |
$quietFn->("Package Name ($rawName) converted to RedHat form: $canonicalName")
|
|
|
110 |
if ( $cvt );
|
|
|
111 |
|
|
|
112 |
unless ( $canonicalName =~ m/^[a-zA-Z][_+a-zA-Z0-9]+$/ )
|
|
|
113 |
{
|
|
|
114 |
Error ("Package Name does not conform to RedHat Requirements",
|
|
|
115 |
"and cannot be massaged into a conforming name",
|
|
|
116 |
"Must be at least two characters long",
|
|
|
117 |
"Must start with an alphabetic character",
|
|
|
118 |
"Must only contain: (a-zA-Z) (0-9) and _",
|
|
|
119 |
"Provided Name: $rawName",
|
|
|
120 |
"Massaged: $canonicalName");
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
} else {
|
|
|
124 |
Error ("canonicalName. Unknown type: $type");
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
return $canonicalName;
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
|