pkg/merge-metadata.pl
author Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
Mon, 23 May 2011 12:14:08 -0700
changeset 1132 d9f96853a754
parent 970 272328fe1b4a
child 1356 73c3eb360de2
permissions -rwxr-xr-x
7047456 X could do better at building & packaging python bits
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
970
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     1
#! /usr/perl5/bin/perl
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     2
#
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     3
# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     4
#
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     5
# Permission is hereby granted, free of charge, to any person obtaining a
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     6
# copy of this software and associated documentation files (the "Software"),
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     7
# to deal in the Software without restriction, including without limitation
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     8
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     9
# and/or sell copies of the Software, and to permit persons to whom the
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    10
# Software is furnished to do so, subject to the following conditions:
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    11
#
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    12
# The above copyright notice and this permission notice (including the next
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    13
# paragraph) shall be included in all copies or substantial portions of the
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    14
# Software.
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    15
#
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    16
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    17
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    18
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    19
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    20
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    21
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    22
# DEALINGS IN THE SOFTWARE.
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    23
#
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    24
#
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    25
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    26
#
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    27
# Merge pkg(5) metadata files to reduce duplicates and combine attribute
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    28
# values for the same attribute name into a single line
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    29
#
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    30
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    31
use strict;
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    32
use warnings;
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    33
use diagnostics;
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    34
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    35
my %attributes = ();
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    36
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    37
while (my $in = <>) {
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    38
  chomp $in;
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    39
  if ($in =~ m{^set name=(\S+) value="(.*)"$}) {
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    40
    my ($name, $value) = ($1, $2);
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    41
    $attributes{$name}->{$value} = 1;
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    42
  } else {
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    43
    # Pass through other lines unchanged
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    44
    print $in, "\n";
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    45
  }
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    46
}
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    47
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    48
foreach my $n (sort keys %attributes) {
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    49
  print qq(set name="$n");
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    50
  foreach my $v (sort keys %{$attributes{$n}}) {
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    51
    print qq( value="$v");
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    52
  }
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    53
  print "\n";
272328fe1b4a 6941932 X should be able to build IPS packages natively
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    54
}