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