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
Line 
1#!/usr/bin/perl -w
2#
3# Creates common environment
4#
5# $Id$
6#
7require Exporter;
8@ISA = qw(Exporter);
9@EXPORT = qw(env_init);
10
11use lib qw (lib);
12use pb qw (pb_init);
13use strict;
14use File::Basename;
15use File::Path;
16use File::Temp qw /tempdir/;
17use vars qw (%defpkgdir %extpkgdir %version %param);
18use Data::Dumper;
19
20$ENV{'PBETC'} = "/etc/pb";
21
22sub env_init {
23
24my $proj=shift;
25my $ver;
26my $tag;
27
28#
29# Check project name
30#
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));
36
37#
38# Use project configuration file
39#
40pb_init("$ENV{'PBETC'}/$proj.pb");
41
42#
43# Check content
44#
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
54die "defpkgdir doesn't exist in $ENV{'PBETC'}/$proj.pb" if (not (defined %defpkgdir));
55
56#
57# Set temp directory
58#
59if (not defined $ENV{'TMPDIR'}) {
60 $ENV{'TMPDIR'}="/tmp";
61}
62$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
63
64#
65# Check pb conf compliance
66#
67$ENV{'PBCONF'} = "$ENV{'PBROOT'}/pbconf";
68die "Project $ENV{'PBPROJ'} not ProjectBuild compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
69
70#
71# Get global VERSION
72#
73open(VER, "$ENV{'PBCONF'}/VERSION") || die "Unable to open $ENV{'PBCONF'}/VERSION: $?";
74$ver = <VER>;
75chomp($ver);
76#print Dumper(%version);
77die "Invalid version name $ver in $ENV{'PBROOT'}/VERSION" if ($ver !~ /[0-9.]+/) && (not exists $version{$ver});
78$ENV{'PBVER'}=$ver;
79close(VER);
80
81#
82#Get global TAG
83#
84open(TAG, "$ENV{'PBCONF'}/TAG") || die "Unable to open $ENV{'PBCONF'}/TAG: $?";
85$tag = <TAG>;
86chomp($tag);
87die "Invalid tag name $tag in $ENV{'PBROOT'}/TAG" if ($tag !~ /[0-9]+/);
88$ENV{'PBTAG'}=$tag;
89close(TAG);
90
91#
92# Adapt to your needs
93# Set delivery directory
94#
95$ENV{'PBTOPDIR'}="$ENV{'PBROOT'}/../delivery";
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'}";
99
100umask 0022;
101return($proj);
102}
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
1161;
Note: See TracBrowser for help on using the repository browser.