Better perl module organization; keep utility modules in Moz. Also read list of modules to checkout from a file. NOT PART OF THE BUILD

This commit is contained in:
sfraser%netscape.com 2000-10-25 21:43:23 +00:00
Родитель 8a83c1e7af
Коммит a7ab870ab7
6 изменённых файлов: 727 добавлений и 56 удалений

Просмотреть файл

@ -51,6 +51,14 @@ my(%options);
my(%filepaths);
my(%optiondefines);
# hash of input files for this build
# eventually, there will be input files for manifests,
# and projects too.
my(%inputfiles) = (
"buildflags", "MozillaBuildFlags.txt",
"checkoutdata", "MozillaCheckoutList.txt"
);
#-------------------------------------------------------------
# configuration variables that globally affect what is built
#-------------------------------------------------------------
@ -83,7 +91,7 @@ $UNIVERSAL_INTERFACES_VERSION = 0x0320;
# configuration variables that are preferences for the build,
# style and do not affect what is built.
#-------------------------------------------------------------
$CodeWarriorLib::CLOSE_PROJECTS_FIRST
$Moz::CodeWarriorLib::CLOSE_PROJECTS_FIRST
= 1;
# 1 = close then make (for development),
# 0 = make then close (for tinderbox).
@ -100,4 +108,4 @@ $MOZ_SRC = cwd();
my($do_checkout) = 0;
my($do_build) = 1;
RunBuild($do_checkout, $do_build, "MozillaBuildFlags.txt", "Mozilla opt build prefs");
RunBuild($do_checkout, $do_build, \%inputfiles, "Mozilla opt build prefs");

Просмотреть файл

@ -26,7 +26,7 @@
#
use Cwd;
use MozillaBuildCore;
use Moz::BuildCore;
#-------------------------------------------------------------
# Where have the build options gone?
@ -51,6 +51,14 @@ my(%options);
my(%filepaths);
my(%optiondefines);
# hash of input files for this build
# eventually, there will be input files for manifests,
# and projects too.
my(%inputfiles) = (
"buildflags", "MozillaBuildFlags.txt",
"checkoutdata", "MozillaCheckoutList.txt"
);
#-------------------------------------------------------------
# configuration variables that globally affect what is built
#-------------------------------------------------------------
@ -83,7 +91,7 @@ $UNIVERSAL_INTERFACES_VERSION = 0x0320;
# configuration variables that are preferences for the build,
# style and do not affect what is built.
#-------------------------------------------------------------
$CodeWarriorLib::CLOSE_PROJECTS_FIRST
$Moz::CodeWarriorLib::CLOSE_PROJECTS_FIRST
= 1;
# 1 = close then make (for development),
# 0 = make then close (for tinderbox).
@ -102,4 +110,4 @@ $MOZ_SRC = cwd();
my($do_checkout) = 0;
my($do_build) = 1;
RunBuild($do_checkout, $do_build, "MozillaBuildFlags.txt", "Mozilla debug build prefs");
RunBuild($do_checkout, $do_build, \%inputfiles, "Mozilla debug build prefs");

Просмотреть файл

@ -0,0 +1,334 @@
#!perl -w
package Moz::BuildCore;
require 5.004;
require Exporter;
use strict;
use vars qw( @ISA @EXPORT );
# perl includes
use Cwd;
use File::Basename;
# homegrown
use Moz::Moz;
use Moz::Jar;
use Moz::BuildFlags;
use Moz::BuildUtils;
use Moz::CodeWarriorLib;
use MozillaBuildList; # eventually, this should go away, and be replaced by data input
@ISA = qw(Exporter);
@EXPORT = qw(RunBuild);
#//--------------------------------------------------------------------------------------------------
#// DoPrebuildCheck
#//
#// Check the build tools etc before running the build.
#//--------------------------------------------------------------------------------------------------
sub DoPrebuildCheck()
{
SanityCheckJarOptions();
# launch codewarrior and persist its location. Have to call this before first
# call to getCodeWarriorPath().
my($ide_path_file) = $main::filepaths{"idepath"};
$ide_path_file = full_path_to($ide_path_file);
LaunchCodeWarrior($ide_path_file);
}
#//--------------------------------------------------------------------------------------------------
#// Configure Build System
#//--------------------------------------------------------------------------------------------------
sub GenBuildSystemInfo()
{
# always rebuild the configuration program.
BuildProjectClean(":mozilla:build:mac:tools:BuildSystemInfo:BuildSystemInfo.mcp", "BuildSystemInfo");
# delete the configuration file.
unlink(":mozilla:build:mac:BuildSystemInfo.pm");
# run the program.
system(":mozilla:build:mac:BuildSystemInfo");
# wait for the file to be created.
while (!(-e ":mozilla:build:mac:BuildSystemInfo.pm")) { WaitNextEvent(); }
# wait for BuildSystemInfo to finish, so that we see correct results.
while (IsProcessRunning("BuildSystemInfo")) { WaitNextEvent(); }
# now, evaluate the contents of the file.
open(F, ":mozilla:build:mac:BuildSystemInfo.pm");
while (<F>) { eval; }
close(F);
}
#//--------------------------------------------------------------------------------------------------
#// Make library aliases
#//--------------------------------------------------------------------------------------------------
sub MakeLibAliases()
{
my($dist_dir) = GetBinDirectory();
#// ProfilerLib
if ($main::PROFILE)
{
my($profilerlibpath) = Moz::CodeWarriorLib::getCodeWarriorPath("MacOS Support:Profiler:Profiler Common:ProfilerLib");
MakeAlias("$profilerlibpath", "$dist_dir"."Essential Files:");
}
}
#//--------------------------------------------------------------------------------------------------
#// Regenerate DefinesOptions.h if necessary
#//
#//--------------------------------------------------------------------------------------------------
sub UpdateConfigHeader($)
{
my($config_path) = @_;
my($config, $oldconfig) = ("", "");
my($define, $definevalue, $defines);
my($k, $l,);
foreach $k (keys(%main::options))
{
if ($main::options{$k})
{
foreach $l (keys(%{$main::optiondefines{$k}}))
{
$my::defines{$l} = $main::optiondefines{$k}{$l};
print "Setting up my::defines{$l}\n";
}
}
}
my $config_headerfile = current_directory().$config_path;
if (-e $config_headerfile)
{
open(CONFIG_HEADER, "< $config_headerfile") || die "$config_headerfile: $!\n";
my($line);
while ($line = <CONFIG_HEADER>)
{
$oldconfig .= $line;
if ($line =~ m/#define (.*) (.*)\n/)
{
$define = $1;
$definevalue = $2;
if (exists ($my::defines{$define}) and ($my::defines{$define} == $definevalue))
{
delete $my::defines{$define};
$config .= $line;
}
}
}
close(CONFIG_HEADER);
}
if (%my::defines)
{
foreach $k (keys(%my::defines))
{
$config .= "#define " . $k . " " . $my::defines{$k} . "\n";
}
}
if (($config ne $oldconfig) || (!-e $config_headerfile))
{
printf("Writing new DefinesOptions.h\n");
open(CONFIG_HEADER, "> $config_headerfile") || die "$config_headerfile: $!\n";
MacPerl::SetFileInfo("CWIE", "TEXT", $config_headerfile);
print CONFIG_HEADER ($config);
close(CONFIG_HEADER);
}
}
#//--------------------------------------------------------------------------------------------------
#// ConfigureBuildSystem
#//
#// defines some build-system configuration variables.
#//--------------------------------------------------------------------------------------------------
sub ConfigureBuildSystem()
{
#// In the future, we may want to do configurations based on the actual build system itself.
#// GenBuildSystemInfo();
#// For now, if we discover a newer header file than existed in Universal Interfaces 3.2,
#// we'll assume that 3.3 or later is in use.
my($universal_interfaces) = Moz::CodeWarriorLib::getCodeWarriorPath("MacOS Support:Universal:Interfaces:CIncludes:");
if (-e ($universal_interfaces . "ControlDefinitions.h")) {
$main::UNIVERSAL_INTERFACES_VERSION = 0x0330;
}
#// Rename IC SDK folder in the Mac OS Support folder
my($ic_sdk_folder) = Moz::CodeWarriorLib::getCodeWarriorPath("MacOS Support:ICProgKit2.0.2");
if( -e $ic_sdk_folder)
{
my($new_ic_folder_name) = Moz::CodeWarriorLib::getCodeWarriorPath("MacOS Support:(ICProgKit2.0.2)");
rename ($ic_sdk_folder, $new_ic_folder_name);
# note that CodeWarrior doesn't descnet into folders with () the name
print "Mozilla no longer needs the Internet Config SDK to build:\n Renaming the 'ICProgKit2.0.2' folder to '(ICProgKit2.0.2)'\n";
}
printf("UNIVERSAL_INTERFACES_VERSION = 0x%04X\n", $main::UNIVERSAL_INTERFACES_VERSION);
UpdateConfigHeader(":mozilla:config:mac:DefinesOptions.h");
# alias required CodeWarrior libs into the Essential Files folder (only the Profiler lib now)
MakeLibAliases();
}
#//--------------------------------------------------------------------------------------------------
#// CheckOutModule. Takes variable number of args; first two are required
#//--------------------------------------------------------------------------------------------------
sub CheckOutModule($$$$)
{
my($session, $module, $revision, $date) = @_;
my($result) = $session->checkout($module, $revision, $date);
# result of 1 is success
if ($result) { return; }
my($checkout_err) = $session->getLastError();
if ($checkout_err == 708) {
die "Checkout was cancelled";
} elsif ($checkout_err == 711) {
print "Checkout of '$module' failed\n";
}
}
#//--------------------------------------------------------------------------------------------------
#// getScriptFolder
#//--------------------------------------------------------------------------------------------------
sub getScriptFolder()
{
return dirname($0);
}
#//--------------------------------------------------------------------------------------------------
#// Checkout
#//--------------------------------------------------------------------------------------------------
sub Checkout($)
{
my($checkout_list) = @_;
unless ( $main::pull{all} ) { return; }
# assertRightDirectory();
my($cvsfile) = AskAndPersistFile($main::filepaths{"sessionpath"});
my($session) = Moz::MacCVS->new( $cvsfile );
unless (defined($session)) { die "Error: Checkout aborted. Cannot create session file: $session" }
# activate MacCVS
ActivateApplication('Mcvs');
my($checkout_file) = getScriptFolder().":".$checkout_list;
local(*CHECKOUT_FILE);
open(CHECKOUT_FILE, "< $checkout_file") || die "Error: failed to open checkout list $checkout_file\n";
while (<CHECKOUT_FILE>)
{
my($line) = $_;
chomp($line);
# ignore comments and empty lines
if ($line =~ /^\#/ || $line =~ /^\s*$/) {
next;
}
my($module) = "";
my($revision) = "";
my($date) = "";
if ($line =~ /\s*([^\s]+)\s*\,\s*([^\s]+)\s*\,\s*(.+)\s*/)
{
$module = $1;
$revision = $2;
$date = $3;
}
elsif ($line =~ /\s*([\/\w]+)\s*\,\s*(\w+)\s*/)
{
$module = $1;
$revision = $2;
}
elsif ($line =~ /\s*([^\s]+)\s*\,\s*,\s*(.+)\s*/)
{
$module = $1;
$date = $2;
}
elsif ($line =~ /\s*([\/\w]+)/)
{
$module = $1;
}
# print "Checking out '$module', '$revision', '$date'\n";
CheckOutModule($session, $module, $revision, $date);
}
close(CHECKOUT_FILE);
}
#//--------------------------------------------------------------------------------------------------
#// RunBuild
#//--------------------------------------------------------------------------------------------------
sub RunBuild($$$$)
{
my($do_pull, $do_build, $input_files, $build_prefs) = @_;
# if we are pulling, we probably want to do a full build, so clear the build progress
if ($do_pull) {
ClearBuildProgress();
}
# read local prefs, and the build progress file, and set flags to say what to build
SetupBuildParams(\%main::pull,
\%main::build,
\%main::options,
\%main::optiondefines,
\%main::filepaths,
$input_files->{"buildflags"},
$build_prefs);
# setup the build log
SetupBuildLog($main::filepaths{"buildlogfilepath"}, $main::USE_TIMESTAMPED_LOGS);
StopForErrors();
if ($main::LOG_TO_FILE) {
RedirectOutputToFile($main::filepaths{"scriptlogfilepath"});
}
# run a pre-build check to see that the tools etc are in order
DoPrebuildCheck();
if ($do_pull) {
Checkout($input_files->{"checkoutdata"});
}
unless ($do_build) { return; }
# create generated headers
ConfigureBuildSystem();
UpdateBuildNumberFiles();
chdir($main::MOZ_SRC);
BuildDist();
chdir($main::MOZ_SRC);
BuildProjects();
# the build finished, so clear the build progress state
ClearBuildProgress();
print "Build complete\n";
}
1;

Просмотреть файл

@ -0,0 +1,360 @@
package Moz::BuildFlags;
require 5.004;
require Exporter;
# Package that attempts to read a file from the Preferences folder,
# and get build settings out of it
use strict;
use Exporter;
use Cwd;
use Moz::Prefs;
use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(SetupBuildParams
WriteBuildProgress
ClearBuildProgress
ReadBuildProgress);
my($script_dir) = cwd();
my(@pull_flags);
my(@build_flags);
my(@options_flags);
my(@filepath_flags);
my(%arrays_list) = (
"pull_flags", \@pull_flags,
"build_flags", \@build_flags,
"options_flags", \@options_flags,
"filepath_flags", \@filepath_flags
);
#-------------------------------------------------------------------------------
# appendArrayFlag
#
# Set a flag in the array
#-------------------------------------------------------------------------------
sub appendArrayFlag($$$)
{
my($array_name, $setting, $value) = @_;
my(@this_flag) = [$setting, $value];
my($flags_array) = $arrays_list{$array_name};
if ($flags_array)
{
push(@{$flags_array}, @this_flag);
}
else
{
die "Error: unknown build flags array $array_name\n";
}
}
#-------------------------------------------------------------------------------
# readFlagsFile
#
# Read the file of build flags from disk. File path is relative to the
# script directory.
#-------------------------------------------------------------------------------
sub readFlagsFile($)
{
my($flags_file) = @_;
my($file_path) = $0;
$file_path =~ s/[^:]+$/$flags_file/;
print "Reading build flags from '$file_path'\n";
local(*FLAGS_FILE);
open(FLAGS_FILE, "< $file_path") || die "Error: failed to open flags file $file_path\n";
my($cur_array) = "";
while(<FLAGS_FILE>)
{
my($line) = $_;
chomp($line);
# ignore comments and empty lines
if ($line =~ /^\#/ || $line =~ /^\s*$/) {
next;
}
# 1-word line, probably array name
if ($line =~ /^(\w+)\s*$/)
{
$cur_array = $1;
next;
}
elsif ($line =~ /^(\w+)\s+\"(.+)\"\s*$/) # quoted option
{
my($flag) = $1;
my($setting) = $2;
appendArrayFlag($cur_array, $flag, $setting);
}
elsif ($line =~ /^(\w+)\s+([^\s]+)\s*$/)
{
my($flag) = $1;
my($setting) = $2;
appendArrayFlag($cur_array, $flag, $setting);
}
else
{
die "Error: unknown build flag at '$line'\n";
}
}
close(FLAGS_FILE);
}
#-------------------------------------------------------------------------------
# flagsArrayToHash
#
# Utility routine to migrate flag from a 2D array to a hash, where
# item[n][0] is the hash entry name, and item[n][1] is the hash entry value.
#-------------------------------------------------------------------------------
sub flagsArrayToHash($$)
{
my($src_array, $dest_hash) = @_;
my($item);
foreach $item (@$src_array)
{
$dest_hash->{$item->[0]} = $item->[1];
}
}
#-----------------------------------------------
# printHash
#
# Utility routine to print a hash
#-----------------------------------------------
sub printHash($)
{
my($hash_ref) = @_;
print "Printing hash:\n";
my($key, $value);
while (($key, $value) = each (%$hash_ref))
{
print " $key $value\n";
}
}
#-------------------------------------------------------------------------------
# SetPullFlags
#-------------------------------------------------------------------------------
sub SetPullFlags($)
{
my($pull) = @_;
flagsArrayToHash(\@pull_flags, $pull);
}
#-------------------------------------------------------------------------------
# SetBuildFlags
#-------------------------------------------------------------------------------
sub SetBuildFlags($)
{
my($build) = @_;
flagsArrayToHash(\@build_flags, $build);
}
#-------------------------------------------------------------------------------
# SetBuildOptions
#-------------------------------------------------------------------------------
sub SetBuildOptions($)
{
my($options) = @_;
flagsArrayToHash(\@options_flags, $options);
}
#-------------------------------------------------------------------------------
# SetFilepathFlags
#-------------------------------------------------------------------------------
sub SetFilepathFlags($)
{
my($filepath) = @_;
flagsArrayToHash(\@filepath_flags, $filepath);
}
#-------------------------------------------------------------------------------
# SetOptionDefines
#-------------------------------------------------------------------------------
sub SetOptionDefines($)
{
my($optiondefines) = @_;
# These should remain unchanged
$optiondefines->{"mathml"}{"MOZ_MATHML"} = 1;
$optiondefines->{"svg"}{"MOZ_SVG"} = 1;
}
#-------------------------------------------------------------------------------
# PropagateAllFlags
#-------------------------------------------------------------------------------
sub PropagateAllFlags($)
{
my($build_array) = @_;
# if "all" is set, set all the flags to 1
unless ($build_array->[0][0] eq "all") { die "Error: 'all' must come first in the build array\n"; }
if ($build_array->[0][1] == 1)
{
my($index);
foreach $index (@$build_array)
{
$index->[1] = 1;
}
}
}
#//--------------------------------------------------------------------------------------------------
#// _getBuildProgressFile
#//--------------------------------------------------------------------------------------------------
sub _getBuildProgressFile()
{
my($progress_file);
if ($main::DEBUG) {
$progress_file = $script_dir.":¥Debug build Progress";
} else {
$progress_file = $script_dir.":¥Opt build Progress";
}
return $progress_file;
}
#//--------------------------------------------------------------------------------------------------
#// setBuildProgressStart
#//--------------------------------------------------------------------------------------------------
sub setBuildProgressStart($$)
{
my($build_array, $name) = @_;
my($setting) = 0;
my($index);
foreach $index (@$build_array)
{
$index->[1] = $setting;
if ($index->[0] eq $name) {
$setting = 1;
}
}
if ($setting == 1) {
print "Building from module after $name, as specified by build progress\n";
} else {
printf "Failed to find buildfrom setting '$name'\n";
}
}
#//--------------------------------------------------------------------------------------------------
#// WriteBuildProgress
#//--------------------------------------------------------------------------------------------------
sub WriteBuildProgress($)
{
my($module_built) = @_;
my($progress_file) = _getBuildProgressFile();
open(PROGRESS_FILE, ">>$progress_file") || die "Failed to open $progress_file\n";
print(PROGRESS_FILE "$module_built\n");
close(PROGRESS_FILE);
}
#//--------------------------------------------------------------------------------------------------
#// ClearBuildProgress
#//--------------------------------------------------------------------------------------------------
sub ClearBuildProgress()
{
my($progress_file) = _getBuildProgressFile();
unlink $progress_file;
}
#//--------------------------------------------------------------------------------------------------
#// ReadBuildProgress
#//--------------------------------------------------------------------------------------------------
sub ReadBuildProgress($)
{
my($build_array) = @_;
my($progress_file) = _getBuildProgressFile();
my($last_module);
if (open(PROGRESS_FILE, "< $progress_file"))
{
print "Getting build progress from $progress_file\n";
while (<PROGRESS_FILE>)
{
my($line) = $_;
chomp($line);
$last_module = $line;
}
close(PROGRESS_FILE);
}
if ($last_module)
{
setBuildProgressStart($build_array, $last_module);
}
}
#-------------------------------------------------------------------------------
# SetupBuildParams
#-------------------------------------------------------------------------------
sub SetupBuildParams($$$$$$$)
{
my($pull, $build, $options, $optiondefines, $filepaths, $flags_file, $prefs_file) = @_;
readFlagsFile($flags_file);
# read the user pref file, that can change values in the array
ReadMozUserPrefs($prefs_file, \@pull_flags, \@build_flags, \@options_flags, \@filepath_flags);
ReadBuildProgress(\@build_flags);
PropagateAllFlags(\@build_flags);
PropagateAllFlags(\@pull_flags);
SetPullFlags($pull);
SetBuildFlags($build);
SetBuildOptions($options);
SetOptionDefines($optiondefines);
SetFilepathFlags($filepaths);
# printHash($build);
}
1;

Просмотреть файл

@ -17,15 +17,14 @@ use File::Path;
use File::Copy;
# homegrown
use Moz;
use MozBuildUtils;
use MozJar;
use MacCVS;
use Moz::Moz;
use Moz::BuildUtils;
use Moz::Jar;
use Moz::MacCVS;
@ISA = qw(Exporter);
@EXPORT = qw(
UpdateBuildNumberFiles
Checkout
BuildDist
BuildProjects
);
@ -1712,50 +1711,5 @@ sub BuildProjects()
BuildResources();
}
#//--------------------------------------------------------------------------------------------------
#// Check out everything
#//--------------------------------------------------------------------------------------------------
sub Checkout()
{
unless ( $main::pull{all} ) { return; }
assertRightDirectory();
my($cvsfile) = AskAndPersistFile($main::filepaths{"sessionpath"});
my($session) = MacCVS->new( $cvsfile );
unless (defined($session)) { die "Error: Checkout aborted. Cannot create session file: $session" }
# activate MacCVS
ActivateApplication('Mcvs');
my($nsprpub_tag) = "NSPRPUB_CLIENT_BRANCH";
my($nss_tab) = "NSS_30_BRANCH";
my($psm_tag) = "SECURITY_MAC_BRANCH";
my($ldapsdk_tag) = "LDAPCSDK_40_BRANCH";
#//
#// Checkout commands
#//
if ($main::RUNTIME)
{
CheckOutModule($session, "mozilla/build/mac");
CheckOutModule($session, "mozilla/lib/mac/InterfaceLib");
CheckOutModule($session, "mozilla/config/mac");
CheckOutModule($session, "mozilla/gc");
CheckOutModule($session, "mozilla/lib/mac/NSStartup");
CheckOutModule($session, "mozilla/lib/mac/NSStdLib");
CheckOutModule($session, "mozilla/lib/mac/NSRuntime");
CheckOutModule($session, "mozilla/lib/mac/MoreFiles");
CheckOutModule($session, "mozilla/lib/mac/MacMemoryAllocator");
CheckOutModule($session, "mozilla/nsprpub", $nsprpub_tag);
}
else
{
CheckOutModule($session, "mozilla/nsprpub", $nsprpub_tag);
CheckOutModule($session, "mozilla/security/nss", $nss_tab);
CheckOutModule($session, "mozilla/security/psm", $psm_tag);
CheckOutModule($session, "DirectorySDKSourceC", $ldapsdk_tag);
CheckOutModule($session, "SeaMonkeyAll");
}
}
1;

Просмотреть файл

@ -37,6 +37,13 @@ my(%options);
my(%filepaths);
my(%optiondefines);
# hash of input files for this build
# eventually, there will be input files for manifests,
# and projects too.
my(%inputfiles) = (
"buildflags", "MozillaBuildFlags.txt",
"checkoutdata", "MozillaCheckoutList.txt"
);
my($cur_dir) = cwd();
$cur_dir =~ s/:mozilla:build:mac:build_scripts$//;
@ -46,4 +53,4 @@ $MOZ_SRC = cwd();
my($do_checkout) = 1;
my($do_build) = 0;
RunBuild($do_checkout, $do_build, "MozillaBuildFlags.txt", "Mozilla Pull prefs");
RunBuild($do_checkout, $do_build, \%inputfiles, "Mozilla Pull prefs");