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

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

/etc/pb/proj now contains the strict minimum
rest is under pbconf/proj.pb

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