source: ProjectBuilder/devel/pb/lib/ProjectBuilder/common.pm@ 50

Last change on this file since 50 was 50, checked in by Bruno Cornec, 17 years ago

Try to better organize the tree to be perl compliant

  • Property svn:executable set to *
File size: 3.4 KB
RevLine 
[2]1#!/usr/bin/perl -w
2#
3# Creates common environment
4#
5# $Id$
6#
7
[18]8use strict;
[5]9use lib qw (lib);
[6]10use pb qw (pb_init);
[2]11use File::Basename;
[9]12use File::Path;
[2]13use File::Temp qw /tempdir/;
[8]14use Data::Dumper;
[2]15
[49]16$ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
[5]17
[9]18sub env_init {
[2]19
[5]20my $proj=shift;
21my $ver;
22my $tag;
[2]23
[8]24#
[5]25# Check project name
[49]26# Could be with env var PBPROJ
27# or option -p
28# if not define take the first in conf file
[8]29#
[5]30if ((defined $ENV{'PBPROJ'}) &&
31 (not (defined $proj))) {
32 $proj = $ENV{'PBPROJ'};
33}
[49]34#
35# Use project configuration file
36#
37pb_init("$ENV{'PBETC'}");
38
39if (not defined $proj) {
40 # Take the first as the default project
41 $proj = (keys %pbroot)[0];
42 print $LOG "Using $proj as default project as none has been specified\n" if (($debug >= 0) and (defined $proj));
43}
[5]44die "No project defined - use env var PBPROJ or -p proj" if (not (defined $proj));
[2]45
[49]46$ENV{'PBROOT'} = $pbroot{$proj};
47
[8]48#
[49]49# Check pb conf compliance
[8]50#
[49]51$ENV{'PBCONF'} = "$ENV{'PBROOT'}/pbconf";
52die "Project $proj not Project-Builder compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
[2]53
[49]54if (-f "$ENV{'PBCONF'}/$proj.pb") {
55 pb_conf_init("$ENV{'PBCONF'}/$proj.pb");
[38]56} else {
[49]57 die "Unable to open $ENV{'PBCONF'}/$proj.pb";
[38]58}
59
[8]60#
[5]61# Check content
[8]62#
[18]63if (defined $confparam{"cvsroot"}) {
64 $ENV{'CVSROOT'} = $confparam{"cvsroot"};
[17]65}
66
[13]67die "defpkgdir doesn't exist in $ENV{'PBETC'}/$proj.pb" if (not (defined %defpkgdir));
[5]68
[8]69#
[5]70# Set temp directory
[8]71#
[7]72if (not defined $ENV{'TMPDIR'}) {
[2]73 $ENV{'TMPDIR'}="/tmp";
74}
[5]75$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
[2]76
[8]77#
[5]78# Get global VERSION
[8]79#
[11]80open(VER, "$ENV{'PBCONF'}/VERSION") || die "Unable to open $ENV{'PBCONF'}/VERSION: $?";
[5]81$ver = <VER>;
82chomp($ver);
[8]83#print Dumper(%version);
84die "Invalid version name $ver in $ENV{'PBROOT'}/VERSION" if ($ver !~ /[0-9.]+/) && (not exists $version{$ver});
[5]85$ENV{'PBVER'}=$ver;
86close(VER);
87
[8]88#
[5]89#Get global TAG
[8]90#
[11]91open(TAG, "$ENV{'PBCONF'}/TAG") || die "Unable to open $ENV{'PBCONF'}/TAG: $?";
[5]92$tag = <TAG>;
93chomp($tag);
[8]94die "Invalid tag name $tag in $ENV{'PBROOT'}/TAG" if ($tag !~ /[0-9]+/);
[5]95$ENV{'PBTAG'}=$tag;
96close(TAG);
97
[8]98#
[5]99# Adapt to your needs
100# Set delivery directory
[8]101#
[25]102chdir "$ENV{'PBROOT'}/..";
103my $path = `pwd`;
104chomp($path);
105$ENV{'PBTOPDIR'}=$path."/delivery";
[9]106$ENV{'PBDESTDIR'}="$ENV{'PBTOPDIR'}/$ENV{'PBVER'}-$ENV{'PBTAG'}";
[25]107if (-d $ENV{'PBDESTDIR'}) {
108 opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
109 foreach my $d (readdir(DIR)) {
110 next if ($d =~ /^\./);
111 pbrm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
112 }
113 closedir(DIR);
114}
115if (! -d "$ENV{'PBDESTDIR'}") {
116 pbmkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
117}
[5]118
[25]119#
120# Set build directory
121#
122$ENV{'PBBUILDDIR'}=$path."/build";
123pbrm_rf($ENV{'PBBUILDDIR'}) if (-d "$ENV{'PBBUILDDIR'}");
124pbmkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
125
[8]126umask 0022;
127return($proj);
[2]128}
[9]129
130sub pbmkdir_p {
[29]131my @dir = @_;
132my $ret = mkpath(@dir, 0, 0755);
133return($ret);
[9]134}
135
136sub pbrm_rf {
[29]137my @dir = @_;
138my $ret = rmtree(@dir, 0, 0);
139return($ret);
[9]140}
141
[29]142sub pbsystem {
143
144my $cmd=shift;
[30]145my $cmt=shift || $cmd;
[29]146
[30]147print $LOG "$cmt... ";
[29]148system("$cmd");
149if ($? == -1) {
150 print $LOG "failed to execute: $!\n" if ($debug >= 0);
151} elsif ($? & 127) {
152 printf $LOG "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' if ($debug >= 0);
153} else {
[30]154 print $LOG "OK\n" if ($debug >= 0);
[29]155}
[30]156}
[2]1571;
Note: See TracBrowser for help on using the repository browser.