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

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

Use pbsystem everywhere

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