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

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

Deal with rpm build process

  • Property svn:executable set to *
File size: 2.2 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/;
[6]17use vars qw (%defpkgdir %extpkgdir %version);
[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#
[13]45die "PBROOT doesn't exist in $ENV{'PBETC'}/$proj.pb" if (not (defined $ENV{'PBROOT'}));
46die "defpkgdir doesn't exist in $ENV{'PBETC'}/$proj.pb" if (not (defined %defpkgdir));
[5]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#
[11]59$ENV{'PBCONF'} = "$ENV{'PBROOT'}/pbconf";
60die "Project $ENV{'PBPROJ'} not ProjectBuild compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
[8]61
62#
[5]63# Get global VERSION
[8]64#
[11]65open(VER, "$ENV{'PBCONF'}/VERSION") || die "Unable to open $ENV{'PBCONF'}/VERSION: $?";
[5]66$ver = <VER>;
67chomp($ver);
[8]68#print Dumper(%version);
69die "Invalid version name $ver in $ENV{'PBROOT'}/VERSION" if ($ver !~ /[0-9.]+/) && (not exists $version{$ver});
[5]70$ENV{'PBVER'}=$ver;
71close(VER);
72
[8]73#
[5]74#Get global TAG
[8]75#
[11]76open(TAG, "$ENV{'PBCONF'}/TAG") || die "Unable to open $ENV{'PBCONF'}/TAG: $?";
[5]77$tag = <TAG>;
78chomp($tag);
[8]79die "Invalid tag name $tag in $ENV{'PBROOT'}/TAG" if ($tag !~ /[0-9]+/);
[5]80$ENV{'PBTAG'}=$tag;
81close(TAG);
82
[8]83#
[5]84# Adapt to your needs
85# Set delivery directory
[8]86#
[5]87$ENV{'PBTOPDIR'}="$ENV{'PBROOT'}/../delivery";
[9]88$ENV{'PBDESTDIR'}="$ENV{'PBTOPDIR'}/$ENV{'PBVER'}-$ENV{'PBTAG'}";
89pbrm_rf($ENV{'PBDESTDIR'}) if (-d "$ENV{'PBDESTDIR'}");
90pbmkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
[5]91
[8]92umask 0022;
93return($proj);
[2]94}
[9]95
96sub pbmkdir_p {
97 my @dir = @_;
98 my $ret = mkpath(@dir, 0, 0755);
99 return($ret);
100}
101
102sub pbrm_rf {
103 my @dir = @_;
104 my $ret = rmtree(@dir, 0, 0);
105 return($ret);
106}
107
[2]1081;
Note: See TracBrowser for help on using the repository browser.