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

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

Still in dev. phase - lots of changes - near the end for cms2build

  • Property svn:executable set to *
File size: 2.3 KB
RevLine 
[2]1#!/usr/bin/perl -w
2#
3# Creates common environment
4#
5# $Id$
6#
7require Exporter;
8@ISA = qw(Exporter);
[9]9@EXPORT = qw(env_init);
[2]10
[5]11use lib qw (lib);
[6]12use pb qw (pb_init);
[2]13use strict;
14use File::Basename;
[9]15use File::Path;
[2]16use File::Temp qw /tempdir/;
[17]17use vars qw (%defpkgdir %extpkgdir %version %param);
[8]18use Data::Dumper;
[2]19
[13]20$ENV{'PBETC'} = "/etc/pb";
[5]21
[9]22sub env_init {
[2]23
[5]24my $proj=shift;
25my $ver;
26my $tag;
[2]27
[8]28#
[5]29# Check project name
[8]30#
[5]31if ((defined $ENV{'PBPROJ'}) &&
32 (not (defined $proj))) {
33 $proj = $ENV{'PBPROJ'};
34}
35die "No project defined - use env var PBPROJ or -p proj" if (not (defined $proj));
[2]36
[8]37#
[5]38# Use project configuration file
[8]39#
[13]40pb_init("$ENV{'PBETC'}/$proj.pb");
[2]41
[8]42#
[5]43# Check content
[8]44#
[17]45if (not defined $param{"pbroot"}) {
46 die "param pbroot doesn't exist in $ENV{'PBETC'}/$proj.pb";
47} else {
48 $ENV{'PBROOT'} = $param{"pbroot"};
49}
50if (defined $param{"cvsroot"}) {
51 $ENV{'CVSROOT'} = $param{"cvsroot"};
52}
53
[13]54die "defpkgdir doesn't exist in $ENV{'PBETC'}/$proj.pb" if (not (defined %defpkgdir));
[5]55
[8]56#
[5]57# Set temp directory
[8]58#
[7]59if (not defined $ENV{'TMPDIR'}) {
[2]60 $ENV{'TMPDIR'}="/tmp";
61}
[5]62$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
[2]63
[8]64#
65# Check pb conf compliance
66#
[11]67$ENV{'PBCONF'} = "$ENV{'PBROOT'}/pbconf";
68die "Project $ENV{'PBPROJ'} not ProjectBuild compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
[8]69
70#
[5]71# Get global VERSION
[8]72#
[11]73open(VER, "$ENV{'PBCONF'}/VERSION") || die "Unable to open $ENV{'PBCONF'}/VERSION: $?";
[5]74$ver = <VER>;
75chomp($ver);
[8]76#print Dumper(%version);
77die "Invalid version name $ver in $ENV{'PBROOT'}/VERSION" if ($ver !~ /[0-9.]+/) && (not exists $version{$ver});
[5]78$ENV{'PBVER'}=$ver;
79close(VER);
80
[8]81#
[5]82#Get global TAG
[8]83#
[11]84open(TAG, "$ENV{'PBCONF'}/TAG") || die "Unable to open $ENV{'PBCONF'}/TAG: $?";
[5]85$tag = <TAG>;
86chomp($tag);
[8]87die "Invalid tag name $tag in $ENV{'PBROOT'}/TAG" if ($tag !~ /[0-9]+/);
[5]88$ENV{'PBTAG'}=$tag;
89close(TAG);
90
[8]91#
[5]92# Adapt to your needs
93# Set delivery directory
[8]94#
[5]95$ENV{'PBTOPDIR'}="$ENV{'PBROOT'}/../delivery";
[9]96$ENV{'PBDESTDIR'}="$ENV{'PBTOPDIR'}/$ENV{'PBVER'}-$ENV{'PBTAG'}";
97pbrm_rf($ENV{'PBDESTDIR'}) if (-d "$ENV{'PBDESTDIR'}");
98pbmkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
[5]99
[8]100umask 0022;
101return($proj);
[2]102}
[9]103
104sub pbmkdir_p {
105 my @dir = @_;
106 my $ret = mkpath(@dir, 0, 0755);
107 return($ret);
108}
109
110sub pbrm_rf {
111 my @dir = @_;
112 my $ret = rmtree(@dir, 0, 0);
113 return($ret);
114}
115
[2]1161;
Note: See TracBrowser for help on using the repository browser.