ProjectBuilder

 view release on metacpan or  search on metacpan

lib/ProjectBuilder/Env.pm  view on Meta::CPAN

		pb_log(1,"WARNING: using $proj as default project as none has been specified\n");
		pb_log(1,"         Please either create a pbconfurl reference for project $proj in $ENV{'PBETC'}\n");
		pb_log(1,"         or call pb with the -p project option or use the env var PBPROJ\n");
		pb_log(1,"         if you want to use another project\n");
	}
}
die "No project defined - use env var PBPROJ or -p proj or a pbconfurl entry in $ENV{'PBETC'}" if (not (defined $proj));

# That's always the environment variable that will be used
$ENV{'PBPROJ'} = $proj;
pb_log(2,"PBPROJ: $ENV{'PBPROJ'}\n");

if (not defined ($pbconf{$ENV{'PBPROJ'}})) {
	die "Please create a pbconfurl reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n";
}

# Adds a potential conf file now as it's less 
# important than the project conf file
my ($vmpath,$vepath,$rmpath) = pb_conf_get_if("vmpath","vepath","rmpath");
foreach my $p ($vmpath,$vepath,$rmpath) {
	if ((defined $p) && (defined $p->{$ENV{'PBPROJ'}})) {
		$p->{$ENV{'PBPROJ'}} = pb_path_expand($p->{$ENV{'PBPROJ'}});
		pb_conf_add("$p->{$ENV{'PBPROJ'}}/.pbrc") if (-f "$p->{$ENV{'PBPROJ'}}/.pbrc");
	}
}

#
# Detect the root dir for hosting all the content generated with pb
#
=pod

 Tree will look like this:

             maint pbdefdir                         PBDEFDIR            dev dir (optional)
                  |                                                        |
            ------------------------                                --------------------
            |                      |                                |                  |
         pbproj1                pbproj2             PBPROJ       pbproj1           pbproj2   PBPROJDIR
            |                                                       |
  ---------------------------------------------                ----------
  *      *        *       |        |          |                *        *
 tag    dev    pbconf    ...    bpbuild  pbdelivery PBCONFDIR dev      tag                  
  |               |                           |     PBDESTDIR           |
  ---          ------                        pbrc   PBBUILDDIR       -------
    |          |    |                                                |     |
   1.1        dev  tag                                              1.0   1.1                PBDIR
                    |
                 -------
                 |     |
                1.0   1.1                           PBROOTDIR
                       |
               ----------------------------------
               |          |           |         |
             pkg1      pbproj1.pb   pbfilter   pbcl
               |
        -----------------
        |      |        |
       rpm    deb    pbfilter


 (*) By default, if no relocation in .pbrc, dev dir is taken in the maint pbdefdir (when appropriate)
 Names under a pbproj and the corresponding pbconf should be similar

=back 

=cut

my ($pbdefdir) = pb_conf_get_if("pbdefdir");

if (not defined $ENV{'PBDEFDIR'}) {
	if ((not defined $pbdefdir) || (not defined $pbdefdir->{$ENV{'PBPROJ'}})) {
		pb_log(1,"WARNING: no pbdefdir defined, using /var/cache\n");
		pb_log(1,"         Please create a pbdefdir reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n");
		pb_log(1,"         if you want to use another directory\n");
		$ENV{'PBDEFDIR'} = "/var/cache";
	} else {
		# That's always the environment variable that will be used
		$ENV{'PBDEFDIR'} = $pbdefdir->{$ENV{'PBPROJ'}};
	}
}
# Expand potential env variable in it
$ENV{PBDEFDIR} = pb_path_expand($ENV{PBDEFDIR});
pb_log(2,"PBDEFDIR: $ENV{'PBDEFDIR'}\n");

# Need to do that earlier as it's used potentialy in pb_vcs_add
pb_temp_init($pbkeep);
pb_log(2,"PBTMP: $ENV{'PBTMP'}\n");

# Put under CMS the PBPROJ dir
if ($action =~ /^newproj$/) {
	if (! -d "$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}") {
		# TODO: There is also the need to do 
		# svn import "$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}" svn://repo
		# in case it doesn't exist there
		pb_mkdir_p("$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}");
	}
	pb_vcs_add($pbconf{$ENV{'PBPROJ'}},"$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}");
}

#
# Set delivery directory
#
$ENV{'PBDESTDIR'}="$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}/pbdelivery";

pb_log(2,"PBDESTDIR: $ENV{'PBDESTDIR'}\n");
#
# Removes all directory existing below the delivery dir 
# as they are temp dir only except when called from pbinit
# Files stay and have to be cleaned up manually if needed
# those files serves as communication channels between pb phases
# Removing them prevents a following phase to detect what has been done before
#
if ((-d $ENV{'PBDESTDIR'}) && ($action !~ /pbinit/)) {
	opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
	foreach my $d (readdir(DIR)) {
		next if ($d =~ /^\./);
		next if (-f "$ENV{'PBDESTDIR'}/$d");
		pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
	}
	closedir(DIR);
}



( run in 0.437 second using v1.01-cache-2.11-cpan-71847e10f99 )