source: devel/pb/lib/common.pm @ 5

Last change on this file since 5 was 5, checked in by bruno, 12 years ago

Lots of modifs to find the right way. Probably still not good

  • Property svn:executable set to *
File size: 1.7 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(set_env);
10
11use lib qw (lib);
12use strict;
13use File::Basename;
14use ExtUtils::Command;
15use File::Temp qw /tempdir/;
16use vars qw (%defpkgdir %extpkgdir %version &pb_init);
17
18$ENV{'PBCONF'} = "/etc/pb";
19
20sub set_env {
21
22my $proj=shift;
23my $ver;
24my $tag;
25
26# Check project name
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));
32
33# Use project configuration file
34require "$ENV{'PBCONF'}/$proj.pb";
35pb_init();
36
37# Check content
38die "PBROOT doesn't exist in $ENV{'PBCONF'}/$proj.pb" if (not (defined $ENV{'PBROOT'}));
39die "defpkgdir doesn't exist in $ENV{'PBCONF'}/$proj.pb" if (not (defined %defpkgdir));
40
41# Set temp directory
42if (undef $ENV{'TMPDIR'}) {
43    $ENV{'TMPDIR'}="/tmp";
44}
45$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
46
47# Get global VERSION
48open(VER, "$ENV{'PBROOT'}/VERSION") || die "Unable to open $ENV{'PBROOT'}/VERSION: $?";
49$ver = <VER>;
50chomp($ver);
51die "Invalid version name $ver in $ENV{'PBROOT'}/VERSION" if ($ver !~ /[0-9.]+/) || (defined $version{$ver});
52$ENV{'PBVER'}=$ver;
53close(VER);
54
55#Get global TAG
56open(TAG, "$ENV{'PBROOT'}/TAG") || die "Unable to open $ENV{'PBROOT'}/TAG: $?";
57$tag = <TAG>;
58chomp($tag);
59die "Invalid version tag $tag in $ENV{'PBROOT'}/TAG" if ($tag !~ /[0-9]+/);
60$ENV{'PBTAG'}=$tag;
61close(TAG);
62
63# Adapt to your needs
64# Set delivery directory
65$ENV{'PBTOPDIR'}="$ENV{'PBROOT'}/../delivery";
66$ENV{'PBDESTDIR'}=$ENV{'TOPDIR'}."/".$ENV{'PBVER'}."-".$ENV{'PBTAG'};
67mkpath $ENV{'PBDESTDIR'};
68
69umask 0022
70}
711;
Note: See TracBrowser for help on using the repository browser.