2002-02-28 11:11:51 +03:00
#!/usr/bin/perl -w
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# First attempt at using module-graph.pl to generate
# a cvs checkout list, and building the resulting tree.
#
2002-04-03 04:48:03 +04:00
# bootstrap.pl starts with an "all.dot" requires map file
# and nothing else, and does the following:
# * Figures out the module dependencies for the module
# you want to build, via module-graph.pl.
# * Creates a list of directories from the modules via
# modules2dir.pl.
# * Checks out core config files, nspr, and module directories.
# * Based on this resulting tree, allmakefiles.sh is generated
# on the fly with a module name "bootstrap".
# * A build is attemped with this configure option:
# --enable-standalone-modules=bootstrap
#
# Bug: currently, the build descends into the nspr configure
# and never comes back, bailing with the error
# "configure: warning: Recreating autoconf.mk with updated nspr-config output"
#
2002-02-28 11:11:51 +03:00
2002-03-30 07:29:40 +03:00
use strict ;
2002-04-03 03:13:35 +04:00
use File::Find ( ) ;
2002-03-30 07:29:40 +03:00
# For --option1, --option2, ...
use Getopt::Long ;
Getopt::Long:: Configure ( "bundling_override" ) ;
Getopt::Long:: Configure ( "auto_abbrev" ) ;
2002-02-28 11:11:51 +03:00
use Cwd ;
2002-03-30 07:29:40 +03:00
my $ debug = 1 ;
2002-03-02 03:04:47 +03:00
sub PrintUsage {
die << END_USAGE
2002-04-03 03:13:35 +04:00
usage: $ 0 - - modules = mod1 , mod2 , .. - - skip - cvs
2002-03-02 03:04:47 +03:00
( Assumes all . dot is in cwd , and you can check out a new cvs tree here )
END_USAGE
2002-02-28 11:11:51 +03:00
}
2002-04-03 03:13:35 +04:00
# Globals.
2002-04-02 03:43:44 +04:00
my $ root_modules = 0 ; # modules we want to build.
2002-04-03 03:13:35 +04:00
my $ skip_cvs = 0 ;
2002-03-30 07:29:40 +03:00
sub parse_args () {
PrintUsage ( ) if $# ARGV < 0 ;
# Stuff arguments into variables.
# Print usage if we get an unknown argument.
2002-04-03 03:13:35 +04:00
PrintUsage ( ) if ! GetOptions ( 'modules=s' = > \ $ root_modules ,
'skip-cvs' = > \ $ skip_cvs ) ;
2002-04-02 03:43:44 +04:00
if ( $ root_modules ) {
print "root_modules = $root_modules\n" ;
# Test for last tree, or remember what tree we're doing.
if ( - e "last_module.txt" ) {
open LAST_MODULE , "last_module.txt" ;
while ( <LAST_MODULE> ) {
# Assume module name is first line
unless ( $ _ eq $ root_modules ) {
print "Error: Last module pulled ($_) doesn't match \"$root_modules\", remove last_module.txt and mozilla tree, then try again.\n" ;
exit 1 ;
} else {
print "Checking out same module...\n" ;
}
}
close LAST_MODULE ;
} else {
# Save off file to remember which tree we're using
open LAST_MODULE , ">last_module.txt" ;
print LAST_MODULE $ root_modules ;
close LAST_MODULE ;
}
}
2002-03-30 07:29:40 +03:00
}
2002-02-28 11:11:51 +03:00
2002-03-02 03:04:47 +03:00
sub get_system_cwd {
my $ a = Cwd:: getcwd ( ) || `pwd` ;
chomp ( $ a ) ;
return $ a ;
}
2002-02-28 11:11:51 +03:00
2002-03-02 03:04:47 +03:00
# Run shell command, return output string.
sub run_shell_command {
2002-03-30 07:29:40 +03:00
my ( $ shell_command , $ echo ) = @ _ ;
2002-03-02 03:04:47 +03:00
local $ _ ;
my $ status = 0 ;
my $ output = "" ;
2002-02-28 11:11:51 +03:00
2002-03-02 03:04:47 +03:00
chomp ( $ shell_command ) ;
2002-03-30 07:29:40 +03:00
2002-03-02 03:04:47 +03:00
print "cmd = $shell_command\n" ;
2002-03-30 07:29:40 +03:00
2002-03-02 03:04:47 +03:00
open CMD , "$shell_command 2>&1|" or die "open: $!" ;
2002-02-28 11:11:51 +03:00
2002-03-02 03:04:47 +03:00
while ( <CMD> ) {
2002-02-28 11:11:51 +03:00
2002-03-30 07:29:40 +03:00
if ( $ echo ) {
2002-03-02 03:04:47 +03:00
print $ _ ;
}
chomp ( $ _ ) ;
$ output . = "$_ " ;
}
2002-02-28 11:11:51 +03:00
2002-03-02 03:04:47 +03:00
close CMD or $ status = 1 ;
2002-02-28 11:11:51 +03:00
2002-03-02 03:04:47 +03:00
if ( $ status ) {
exit 1 ; # bail.
}
2002-02-28 11:11:51 +03:00
2002-03-02 03:04:47 +03:00
return $ output ;
}
2002-02-28 11:11:51 +03:00
2002-04-03 03:13:35 +04:00
# Global and Compare routine for Find()
my @ foundMakefiles ;
sub FindMakefiles
{
# Don't descend into CVS dirs.
/CVS/ and $ File:: Find:: prune = 1 ;
if ( $ _ eq "Makefile.in" ) {
#print "$File::Find::dir $_\n";
#strip off the ".in"
$ _ =~ s/.in// ;
push ( @ foundMakefiles , "$File::Find::dir/$_" ) ;
} else {
#print " $File::Find::dir $_\n";
}
}
2002-02-28 11:11:51 +03:00
2002-03-02 03:04:47 +03:00
# main
{
my $ rv = 0 ; # 0 = success.
2002-03-30 07:29:40 +03:00
# Get options.
parse_args ( ) ;
2002-03-02 03:04:47 +03:00
#
# Assume all.dot is checked in somewhere.
#
unless ( - e "all.dot" ) {
print "No all.dot file found. Get one by running\n tools/module-deps/module-graph.pl . > all.dot\non built tree from the mozilla directory, or find one checked in somewhere.\n\n" ;
PrintUsage ( ) ;
}
# Pull core build stuff.
2002-04-03 03:13:35 +04:00
unless ( $ skip_cvs ) {
print "\n\nPulling core build files...\n" ;
my $ core_build_files = "mozilla/client.mk mozilla/config mozilla/configure mozilla/configure.in mozilla/Makefile.in mozilla/build mozilla/include mozilla/tools/module-deps" ;
$ rv = run_shell_command ( "cvs co $core_build_files" ) ;
}
2002-03-02 03:04:47 +03:00
# Pull nspr
2002-04-03 03:13:35 +04:00
unless ( $ skip_cvs ) {
print "\n\nPulling nspr...\n" ;
my $ nspr_cvs_cmd = "cvs co -rNSPRPUB_PRE_4_2_CLIENT_BRANCH mozilla/nsprpub" ;
$ rv = run_shell_command ( "$nspr_cvs_cmd" ) ;
}
2002-03-02 03:04:47 +03:00
#
# Pull modules.
2002-03-30 07:29:40 +03:00
# Only one root/start module to start.
2002-03-02 03:04:47 +03:00
#
print "\n\nPulling modules...\n" ;
2002-04-03 03:13:35 +04:00
2002-03-02 03:04:47 +03:00
# Figure out the modules list.
my @ modules ;
my $ modules_string = "" ;
my $ num_modules = 0 ;
2002-03-30 07:29:40 +03:00
my $ modules_cmd = "mozilla/tools/module-deps/module-graph\.pl --file all\.dot --start-module $root_modules --list-only" ;
$ modules_string = run_shell_command ( $ modules_cmd , 0 ) ;
2002-03-02 03:04:47 +03:00
@ modules = split ( ' ' , $ modules_string ) ;
$ num_modules = $# modules + 1 ;
print "modules = $num_modules\n" ;
# Map modules list to directories list.
my @ dirs ;
my $ dirs_string = "" ;
my $ dirs_cmd = "echo $modules_string | mozilla/config/module2dir\.pl --list-only" ;
2002-04-03 03:13:35 +04:00
print "\nGenerating directories list...\n" ;
2002-03-30 07:29:40 +03:00
$ dirs_string = run_shell_command ( $ dirs_cmd , 0 ) ;
2002-03-02 03:04:47 +03:00
#print "dirs_string = $dirs_string\n";
2002-04-03 03:13:35 +04:00
@ dirs = split ( ' ' , $ dirs_string ) ; # Create dirs array for find command.
2002-03-02 03:04:47 +03:00
# Checkout directories.
2002-04-03 03:13:35 +04:00
unless ( $ skip_cvs ) {
print "\nChecking out directories...\n" ;
my $ dirs_cvs_cmd = "cvs co $dirs_string" ;
run_shell_command ( $ dirs_cvs_cmd ) ;
}
2002-03-02 03:05:54 +03:00
2002-03-02 03:04:47 +03:00
# Try a build.
my $ base = get_system_cwd ( ) ;
2002-03-30 07:29:40 +03:00
#
2002-04-03 03:13:35 +04:00
# Construct an allmakefiles.sh file
2002-03-30 07:29:40 +03:00
#
2002-04-03 03:13:35 +04:00
# Look for previously generated allmakefiles.sh file.
my $ generated_allmakefiles_file = 0 ;
if ( - e "mozilla/allmakefiles.sh" ) {
open ALLMAKEFILES , "mozilla/allmakefiles.sh" ;
while ( <ALLMAKEFILES> ) {
if ( /# Generated by bootstrap.pl/ ) {
$ generated_allmakefiles_file = 1 ;
}
}
close ALLMAKEFILES ;
if ( $ generated_allmakefiles_file == 0 ) {
print "Error: non-generated mozilla/allmakefiles.sh found.\n" ;
exit 1 ;
}
}
# Stomp on generated file, or open a new one.
open ALLMAKEFILES , ">mozilla/allmakefiles.sh" ;
2002-03-30 07:29:40 +03:00
2002-04-03 03:13:35 +04:00
# Add in stub allmakefiles.sh file.
open STUB , "mozilla/tools/module-deps/allmakefiles.stub" ;
while ( <STUB> ) {
print ALLMAKEFILES $ _ ;
}
close STUB ;
# Add in our hack
print ALLMAKEFILES "MAKEFILES_bootstrap=\"\n" ;
# Recursively decend the tree looking for Makefiles
File::Find:: find ( \ & FindMakefiles , @ dirs ) ;
# Write Makefiles out to allmakefiles.sh.
foreach ( @ foundMakefiles ) {
print ALLMAKEFILES "$_\n" ;
}
2002-03-30 07:29:40 +03:00
2002-04-03 03:13:35 +04:00
print ALLMAKEFILES "\"" ;
close ALLMAKEFILES ;
2002-03-30 07:29:40 +03:00
2002-03-02 03:04:47 +03:00
#print "Configuring nspr ... \n";
#chdir("$base/mozilla/nsprpub");
#my $nspr_configure_cmd = "./configure";
#system("$nspr_configure_cmd");
print "Configuring ... \n" ;
unlink ( "$base/mozilla/config.cache" ) ;
chdir ( "$base/mozilla" ) ;
2002-03-30 07:29:40 +03:00
my $ configure_cmd = "./configure --enable-standalone-modules=$root_modules" ;
2002-03-02 03:04:47 +03:00
$ rv = run_shell_command ( "$configure_cmd" ) ;
2002-03-30 07:29:40 +03:00
unless ( $ rv ) {
print "Building ... \n" ;
$ rv = run_shell_command ( "gmake" ) ;
} else {
print "Error: skipping build.\n" ;
}
2002-02-28 11:11:51 +03:00
}