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

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

Remove use of PBTOPDIR useless
delivery dir is cleaned of dir in it only now.
One level less generated during delivery (easier)

  • Property svn:executable set to *
File size: 3.6 KB
Line 
1#!/usr/bin/perl -w
2#
3# Creates common environment
4#
5# $Id$
6#
7
8use strict;
9use lib qw (lib);
10use ProjectBuilder::pb qw (pb_init);
11use File::Basename;
12use File::Path;
13use File::Temp qw /tempdir/;
14use Data::Dumper;
15
16$ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
17
18sub env_init {
19
20my $proj=shift;
21my $ver;
22my $tag;
23
24#
25# Check project name
26# Could be with env var PBPROJ
27# or option -p
28# if not define take the first in conf file
29#
30if ((defined $ENV{'PBPROJ'}) &&
31 (not (defined $proj))) {
32 $proj = $ENV{'PBPROJ'};
33}
34#
35# Use project configuration file if needed
36#
37if (not defined $ENV{'PBROOT'}) {
38 pb_init("$ENV{'PBETC'}");
39
40 if (not defined $proj) {
41 # Take the first as the default project
42 $proj = (keys %pbroot)[0];
43 print $LOG "Using $proj as default project as none has been specified\n" if (($debug >= 0) and (defined $proj));
44 }
45 die "No project defined - use env var PBPROJ or -p proj" if (not (defined $proj));
46
47 $ENV{'PBROOT'} = $pbroot{$proj};
48} else {
49 die "No project defined - use env var PBPROJ or -p proj" if (not (defined $proj));
50}
51
52#
53# Check pb conf compliance
54#
55$ENV{'PBCONF'} = "$ENV{'PBROOT'}/pbconf";
56die "Project $proj not Project-Builder compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
57
58if (-f "$ENV{'PBCONF'}/$proj.pb") {
59 pb_conf_init("$ENV{'PBCONF'}/$proj.pb");
60} else {
61 die "Unable to open $ENV{'PBCONF'}/$proj.pb";
62}
63
64#
65# Check content
66#
67if (defined $confparam{"cvsroot"}) {
68 $ENV{'CVSROOT'} = $confparam{"cvsroot"};
69}
70
71die "defpkgdir doesn't exist in $ENV{'PBETC'}/$proj.pb" if (not (defined %defpkgdir));
72
73#
74# Set temp directory
75#
76if (not defined $ENV{'TMPDIR'}) {
77 $ENV{'TMPDIR'}="/tmp";
78}
79$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
80
81#
82# Get global VERSION
83#
84open(VER, "$ENV{'PBCONF'}/VERSION") || die "Unable to open $ENV{'PBCONF'}/VERSION: $?";
85$ver = <VER>;
86chomp($ver);
87#print Dumper(%version);
88die "Invalid version name $ver in $ENV{'PBROOT'}/VERSION" if ($ver !~ /[0-9.]+/) && (not exists $version{$ver});
89$ENV{'PBVER'}=$ver;
90close(VER);
91
92#
93#Get global TAG
94#
95open(TAG, "$ENV{'PBCONF'}/TAG") || die "Unable to open $ENV{'PBCONF'}/TAG: $?";
96$tag = <TAG>;
97chomp($tag);
98die "Invalid tag name $tag in $ENV{'PBROOT'}/TAG" if ($tag !~ /[0-9]+/);
99$ENV{'PBTAG'}=$tag;
100close(TAG);
101
102#
103# Adapt to your needs
104# Set delivery directory
105# Removes all directory existing below as they are temp dir only
106# Files stay and have to be cleaned up manually
107#
108chdir "$ENV{'PBROOT'}/..";
109my $path = `pwd`;
110chomp($path);
111$ENV{'PBDESTDIR'}=$path."/delivery";
112if (-d $ENV{'PBDESTDIR'}) {
113 opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
114 foreach my $d (readdir(DIR)) {
115 next if ($d =~ /^\./);
116 next if (-f "$ENV{'PBDESTDIR'}/$d");
117 pbrm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
118 }
119 closedir(DIR);
120}
121if (! -d "$ENV{'PBDESTDIR'}") {
122 pbmkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
123}
124
125#
126# Set build directory
127#
128$ENV{'PBBUILDDIR'}=$path."/build";
129pbrm_rf($ENV{'PBBUILDDIR'}) if (-d "$ENV{'PBBUILDDIR'}");
130pbmkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
131
132umask 0022;
133return($proj);
134}
135
136sub pbmkdir_p {
137my @dir = @_;
138my $ret = mkpath(@dir, 0, 0755);
139return($ret);
140}
141
142sub pbrm_rf {
143my @dir = @_;
144my $ret = rmtree(@dir, 0, 0);
145return($ret);
146}
147
148sub pbsystem {
149
150my $cmd=shift;
151my $cmt=shift || $cmd;
152
153print $LOG "$cmt... ";
154system("$cmd");
155if ($? == -1) {
156 print $LOG "failed to execute: $!\n" if ($debug >= 0);
157} elsif ($? & 127) {
158 printf $LOG "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' if ($debug >= 0);
159} else {
160 print $LOG "OK\n" if ($debug >= 0);
161}
162}
1631;
Note: See TracBrowser for help on using the repository browser.