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

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

Basic function works (conf file read and interpret)

  • Property svn:executable set to *
File size: 1.9 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 pb qw (pb_init);
13use strict;
14use File::Basename;
15use ExtUtils::Command;
16use File::Temp qw /tempdir/;
17use vars qw (%defpkgdir %extpkgdir %version);
18use Data::Dumper;
19
20$ENV{'PBCONF'} = "/etc/pb";
21
22sub set_env {
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{'PBCONF'}/$proj.pb");
41
42#
43# Check content
44#
45die "PBROOT doesn't exist in $ENV{'PBCONF'}/$proj.pb" if (not (defined $ENV{'PBROOT'}));
46die "defpkgdir doesn't exist in $ENV{'PBCONF'}/$proj.pb" if (not (defined %defpkgdir));
47
48#
49# Set temp directory
50#
51if (not defined $ENV{'TMPDIR'}) {
52 $ENV{'TMPDIR'}="/tmp";
53}
54$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
55
56#
57# Check pb conf compliance
58#
59die "Project $ENV{'PBPROJ'} not ProjectBuild compliant. Please populate $ENV{'PBROOT'}/pbconf" if ( not -d "$ENV{'PBROOT'}/pbconf");
60
61#
62# Get global VERSION
63#
64open(VER, "$ENV{'PBROOT'}/pbconf/VERSION") || die "Unable to open $ENV{'PBROOT'}/pbconf/VERSION: $?";
65$ver = <VER>;
66chomp($ver);
67#print Dumper(%version);
68die "Invalid version name $ver in $ENV{'PBROOT'}/VERSION" if ($ver !~ /[0-9.]+/) && (not exists $version{$ver});
69$ENV{'PBVER'}=$ver;
70close(VER);
71
72#
73#Get global TAG
74#
75open(TAG, "$ENV{'PBROOT'}/pbconf/TAG") || die "Unable to open $ENV{'PBROOT'}/pbconf/TAG: $?";
76$tag = <TAG>;
77chomp($tag);
78die "Invalid tag name $tag in $ENV{'PBROOT'}/TAG" if ($tag !~ /[0-9]+/);
79$ENV{'PBTAG'}=$tag;
80close(TAG);
81
82#
83# Adapt to your needs
84# Set delivery directory
85#
86$ENV{'PBTOPDIR'}="$ENV{'PBROOT'}/../delivery";
87$ENV{'PBDESTDIR'}=$ENV{'PBTOPDIR'}."/".$ENV{'PBVER'}."-".$ENV{'PBTAG'};
88mkpath $ENV{'PBDESTDIR'};
89
90umask 0022;
91return($proj);
92}
931;
Note: See TracBrowser for help on using the repository browser.