releasing/cbrtools/perl/BuildRel
author jjkang
Fri, 25 Jun 2010 18:37:20 +0800
changeset 602 3145852acc89
permissions -rw-r--r--
add releasing to new structure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
#!perl
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
# Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
# All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     6
# which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     8
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     9
# Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
# Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
# Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
use FindBin;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
use lib "$FindBin::Bin";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
use Getopt::Long;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
use IniData;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
use EnvDb;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
use MrpData;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
use CommandController;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
use Cwd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
# Globals.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
my $verbose = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
my $comp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
my $iniData = IniData->New();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
my $commandController = CommandController->New($iniData, 'BuildRel');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
my $envDb;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
my $buildall;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
my $noclean;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
my $dummyrun;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
# Main.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
ProcessCommandLine();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
BuildRel();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
# Subs.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
sub ProcessCommandLine {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
  Getopt::Long::Configure ("bundling");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
  my $help;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
  my $ignore;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
  my $stdin;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
  GetOptions("h" => \$help, "v+" => \$verbose, "a" => \$buildall, "q" => \$noclean, "d" => \$dummyrun, "f" => \$ignore);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
  if ($help) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
    Usage(0);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
  $comp = shift @ARGV;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
  if (@ARGV) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
    print "Error: too many arguments\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
    Usage(1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
  } elsif ($buildall && $comp) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
    print "Error: can't use -a with a component name\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
    Usage(1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
  } elsif (!$buildall && !$comp) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
    print "Error: Must specify -a or a component name\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
    Usage(1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
  $envDb = EnvDb->Open($iniData, $verbose);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
sub Usage {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
  my $exitCode = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
  Utils::PrintDeathMessage($exitCode, "\nUsage: buildrel [options] -a | <component>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
options:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
-a                    build all pending release components
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
-h                    help
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
-f                    (deprecated)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
-v                    verbose output (-vv very verbose)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
-q                    quick (don't do \"abld reallyclean\")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
-d                    dummy run: just show what would happen\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
sub BuildRel {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
  if ($buildall) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
    BuildEnvironment();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
  } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
    BuildComp($comp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
# Implementation
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
sub BuildComp {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
  my $comp = shift; # could accept a component name or an entry
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
  print "Building \"$comp\"\n" if ($verbose);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
  print "Gathering data from MRP file...\n" if ($verbose>1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
  my $mrpData = $envDb->GetMrpData($comp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
  print "Working out build commands...\n" if ($verbose>1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
  my $cwd = cwd();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
  my $nul = ($verbose > 2)?"":" > NUL";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
  my %commands_by_path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
  foreach my $binset (@{$mrpData->BinSets()}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
    my $path = Utils::PrependSourceRoot($binset->{path});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
    unless ($commands_by_path{$path}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
      $commands_by_path{$path} = [ "bldmake bldfiles" ];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
      push @{$commands_by_path{$path}}, "abld reallyclean" unless $noclean;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
    push @{$commands_by_path{$path}}, "abld $binset->{test} build $binset->{plat} $binset->{var} $binset->{mmp}";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
  print "Running build commands...\n" if ($verbose>1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
  foreach my $path (sort keys %commands_by_path) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
    chdir($path);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
    my $cmds = $commands_by_path{$path};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
    foreach my $cmd (@$cmds) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
      print "Build command: $cmd\n" if ($dummyrun || $verbose > 1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
      next if $dummyrun;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
      open(CMD, "$cmd|") or die "Couldn't start command \"$_\" because $!";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
      my $output = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
      my $failure = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
      while (<CMD>) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
        print $_ if $verbose > 2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
        $failure = 1 if m/fatal error/i;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
        $output .= $_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
      close CMD;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
      die "Error: build failed. Command \"$cmd\" in directory \"$path\" failed with error code $? and output:\n$output\n\n" if ($? || $failure);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
      # ABLD currently doesn't pass through error codes. I have requested
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
      # that it be modified to do so.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
  chdir $cwd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
sub BuildEnvironment {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
  foreach my $comp (keys %{$envDb->{db}}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
    next unless $envDb->Status($comp) == EnvDb::STATUS_PENDING_RELEASE;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
    BuildComp($comp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
__END__
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
BuildRel - Attempt to build a component.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
=head1 SYNOPSIS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
  buildrel [options] -a | <component>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
options:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
  -a                    build all components pending release
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
  -h                    help
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
  -v                    verbose output (-vv  very verbose)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
  -q                    quick (don't do abld reallyclean)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
  -d                    dummy run: just show what would happen
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
Attempts to build a component, using all the platforms listed in the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
MRP file. Using -a will build all the components that are pending
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
release.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
The -d option doesn't do any building. However, in the process of
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
reading the details from the MRP it may be forced to run commands
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
such as C<bldmake bldfiles> and C<abld makefile>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
The commands this script runs are:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
  bldmake bldfiles
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
  abld reallyclean (unless you're using -q)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
  abld build XXX XXX (or abld test build XXX XXX)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   193
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   194
=head1 STATUS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   195
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   196
Supported. If you find a problem, please report it to us.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   197
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   198
=head1 KNOWN BUGS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   199
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   200
None.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   201
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   202
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   203
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   204
 Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   205
 All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   206
 This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   207
 under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   208
 which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   209
 at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   210
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   211
 Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   212
 Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   213
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   214
 Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   215
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   216
 Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   217
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   218
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   219
=cut