From 0cbb993d7c1c92b43306925aeba9f8dc900701b7 Mon Sep 17 00:00:00 2001
From: Eric Edgar <rocket@gentoo.org>
Date: Thu, 7 Apr 2005 23:02:20 +0000
Subject: [PATCH] fix case bug in livecdfs-update.sh; fix bug in initial
 command line arguement parsing; add cflags spec file support which is only
 allowed to override in stage1

git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/catalyst/trunk@591 d1e1f19c-881f-0410-ab34-b69fee027534
---
 ChangeLog                          |  9 ++++-
 catalyst                           | 10 ++++-
 modules/catalyst_support.py        | 37 +++++++++++++++++-
 modules/generic_stage_target.py    | 63 ++++++++++++++++++++----------
 modules/stage1_target.py           | 20 +++++++++-
 targets/support/livecdfs-update.sh |  4 +-
 6 files changed, 115 insertions(+), 28 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d1f223b2..33c24d50 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,13 @@
 # ChangeLog for gentoo/src/catalyst 
 # Copyright 2002-2005 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.211 2005/04/07 12:24:16 rocket Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.212 2005/04/07 23:02:20 rocket Exp $
+
+  07 Apr 2005; Eric Edgar <rocket@gentoo.org> catalyst,
+  modules/catalyst_support.py, modules/generic_stage_target.py,
+  modules/stage1_target.py, targets/support/livecdfs-update.sh:
+  fix case bug in livecdfs-update.sh; fix bug in initial command line
+  arguement parsing; add cflags spec file support which is only allowed to
+  override in stage1
 
   07 Apr 2005; Eric Edgar <rocket@gentoo.org>
   targets/stage3/stage3-chroot.sh:
diff --git a/catalyst b/catalyst
index 5e5908ae..1ad4924f 100755
--- a/catalyst
+++ b/catalyst
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 # Copyright 1999-2004 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/catalyst,v 1.71 2005/04/05 21:52:51 rocket Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/catalyst,v 1.72 2005/04/07 23:02:20 rocket Exp $
 
 # Maintained in full by:
 # Eric Edgar <rocket@gentoo.org>
@@ -219,7 +219,7 @@ if __name__ == "__main__":
 		print "!!! catalyst: please specify one of either -f or -C\n"
 		usage()
 		sys.exit(2)
-	
+	run=0	
 	for o, a in opts:
 		if o in ("-h", "--help"):
 			usage()
@@ -246,12 +246,14 @@ if __name__ == "__main__":
 				myconfig=a
 
 		if o in ("-C", "--cli"):
+			run=1	
 			x=sys.argv.index(o)+1
 			while x < len(sys.argv):
 				mycmdline.append(sys.argv[x])
 				x=x+1
 			
 		if o in ("-f", "--file"):
+			run=1	
 			myspecfile=a
 
 		if o in ("-F", "--fetchonly"):
@@ -280,6 +282,10 @@ if __name__ == "__main__":
 				mycmdline.append("version_stamp="+a)
 		if o in ("--purge"):
 				conf_values["PURGE"]="1"
+	if run != 1:
+		print "!!! catalyst: please specify one of either -f or -C\n"
+		usage()
+		sys.exit(2)
 
 	# import configuration file and import our main module using those settings
 	parse_config(myconfig)
diff --git a/modules/catalyst_support.py b/modules/catalyst_support.py
index 555ab173..84c39c96 100644
--- a/modules/catalyst_support.py
+++ b/modules/catalyst_support.py
@@ -1,6 +1,6 @@
 # Copyright 1999-2004 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/modules/catalyst_support.py,v 1.36 2005/04/07 00:08:51 rocket Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/modules/catalyst_support.py,v 1.37 2005/04/07 23:02:20 rocket Exp $
 
 import sys,string,os,types,re,traceback,md5
 
@@ -241,6 +241,28 @@ def parse_spec(mylines):
 				myspec[myline[0]]=accum
 	return myspec
 
+def parse_makeconf(mylines):
+	mymakeconf={}
+	pos=0
+	pat=re.compile("([a-zA-Z_]*)=(.*)")
+	while pos<len(mylines):
+		if len(mylines[pos])<=1:
+			#skip blanks
+			pos += 1
+			continue
+		if mylines[pos][0] in ["#"," ","\t"]:
+			#skip indented lines, comments
+			pos += 1
+			continue
+		else:
+			myline=mylines[pos]
+			mobj=pat.match(myline)
+			pos += 1
+			if mobj.group(2):
+			    clean_string = re.sub(r"\"",r"",mobj.group(2))
+			    mymakeconf[mobj.group(1)]=clean_string
+	return mymakeconf
+
 def read_spec(myspecfile):
 	try:
 		myf=open(myspecfile,"r")
@@ -249,6 +271,19 @@ def read_spec(myspecfile):
 	mylines=myf.readlines()
 	myf.close()
 	return parse_spec(mylines)
+
+def read_makeconf(mymakeconffile):
+	if os.path.exists(mymakeconffile):
+	    try:
+		    myf=open(mymakeconffile,"r")
+		    mylines=myf.readlines()
+		    myf.close()
+		    return parse_makeconf(mylines)
+	    except:
+		    raise CatalystError, "Could not open make.conf file "+myspecfile
+	else:
+	    makeconf={}
+	    return makeconf
 	
 def msg(mymsg,verblevel=1):
 	if verbosity>=verblevel:
diff --git a/modules/generic_stage_target.py b/modules/generic_stage_target.py
index 42425019..9ed379e9 100644
--- a/modules/generic_stage_target.py
+++ b/modules/generic_stage_target.py
@@ -1,6 +1,6 @@
 # Copyright 1999-2004 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/modules/generic_stage_target.py,v 1.26 2005/04/07 00:08:51 rocket Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/modules/generic_stage_target.py,v 1.27 2005/04/07 23:02:20 rocket Exp $
 
 """
 This class does all of the chroot setup, copying of files, etc. It is
@@ -97,19 +97,6 @@ class generic_stage_target(generic_target):
 			print "Building on",self.settings["hostarch"],"for alternate machine type",\
 				self.settings["mainarch"]
 		
-		# grab build settings from the environment
-		for envvar in "CHOST", "CFLAGS", "CXXFLAGS":
-			if os.environ.has_key(envvar):
-				self.settings[envvar] = os.environ[envvar]
-		if self.settings.has_key("chost"):
-		    self.settings["CHOST"]=list_to_string(self.settings["chost"])
-		if self.settings.has_key("cflags"):
-		    self.settings["CFLAGS"]=list_to_string(self.settings["cflags"])
-		if self.settings.has_key("cxxflags"):
-		    self.settings["CXXFLAGS"]=list_to_string(self.settings["cxxflags"])
-		if self.settings.has_key("hostuse"):
-		    self.settings["hostuse"]=list_to_string(self.settings["hostuse"])
-
 		# define all of our core variables
 		self.set_target_profile()
 		self.set_target_subpath()
@@ -163,6 +150,33 @@ class generic_stage_target(generic_target):
 			# for the chroot:
 			os.environ["CCACHE_DIR"]="/var/tmp/ccache"	
 		
+	def override_chost(self):
+		if os.environ.has_key("CHOST"):
+		    self.settings["CHOST"] = os.environ["CHOST"]
+		if self.settings.has_key("chost"):
+		    self.settings["CHOST"]=list_to_string(self.settings["chost"])
+		if self.makeconf.has_key("CHOST"):
+		    print "Using CHOST setting from seed stage"
+		    self.settings["CHOST"]=self.makeconf["CHOST"]
+	
+	def override_cflags(self):
+		if os.environ.has_key("CFLAGS"):
+		    self.settings["CFLAGS"] = os.environ["CFLAGS"]
+		if self.settings.has_key("cflags"):
+		    self.settings["CFLAGS"]=list_to_string(self.settings["cflags"])
+		if self.makeconf.has_key("CFLAGS"):
+		    print "Using CFLAGS setting from seed stage"
+		    self.settings["CFLAGS"]=self.makeconf["CFLAGS"]
+
+	def override_cxxflags(self):	
+		if os.environ.has_key("CXXFLAGS"):
+		    self.settings["CXXFLAGS"] = os.environ["CXXFLAGS"]
+		if self.settings.has_key("cxxflags"):
+		    self.settings["CXXFLAGS"]=list_to_string(self.settings["cxxflags"])
+		if self.makeconf.has_key("CXXFLAGS"):
+		    print "Using CXXFLAGS setting from seed stage"
+		    self.settings["CXXFLAGS"]=self.makeconf["CXXFLAGS"]
+
 	def set_spec_prefix(self):
 		self.settings["spec_prefix"]=self.settings["target"]
 
@@ -411,6 +425,9 @@ class generic_stage_target(generic_target):
 
 	def chroot_setup(self):
 		    print "Setting up chroot..."
+		    
+		    self.makeconf=read_makeconf(self.settings["chroot_path"]+"/etc/make.conf")
+		    
 		    cmd("cp /etc/resolv.conf "+self.settings["chroot_path"]+"/etc",\
 			    "Could not copy resolv.conf into place.")
 		
@@ -426,7 +443,9 @@ class generic_stage_target(generic_target):
 			    cmd("mv "+self.settings["chroot_path"]+"/etc/hosts "+self.settings["chroot_path"]+\
 				    "/etc/hosts.bck", "Could not backup /etc/hosts")
 			    cmd("cp /etc/hosts "+self.settings["chroot_path"]+"/etc/hosts", "Could not copy /etc/hosts")
-		
+		    self.override_chost()	
+		    self.override_cflags()
+		    self.override_cxxflags()	
 		    # modify and write out make.conf (for the chroot)
 		    cmd("rm -f "+self.settings["chroot_path"]+"/etc/make.conf")
 		    myf=open(self.settings["chroot_path"]+"/etc/make.conf","w")
@@ -434,6 +453,12 @@ class generic_stage_target(generic_target):
 		    myf.write("# Please consult /etc/make.conf.example for a more detailed example\n")
 		    myf.write('CFLAGS="'+self.settings["CFLAGS"]+'"\n')
 		    myf.write('CHOST="'+self.settings["CHOST"]+'"\n')
+		    
+		    if self.settings.has_key("CXXFLAGS"):
+			    myf.write('CXXFLAGS="'+self.settings["CXXFLAGS"]+'"\n')
+		    else:
+			    myf.write('CXXFLAGS="${CFLAGS}"\n')
+		    
 		    # figure out what our USE vars are for building
 		    myusevars=[]
 		    if self.settings.has_key("HOSTUSE"):
@@ -442,12 +467,8 @@ class generic_stage_target(generic_target):
 		    if self.settings.has_key("use"):
 			    myusevars.extend(self.settings["use"])
 			    myf.write('USE="'+string.join(myusevars)+'"\n')
-		
-		    if self.settings.has_key("CXXFLAGS"):
-			    myf.write('CXXFLAGS="'+self.settings["CXXFLAGS"]+'"\n')
-		    else:
-			    myf.write('CXXFLAGS="${CFLAGS}"\n')
-			    
+
+		    # setup the portage overlay	
 		    if self.settings.has_key("portage_overlay"):
 				if type(self.settings["portage_overlay"])==types.StringType:
 					self.settings[self.settings["portage_overlay"]]=[self.settings["portage_overlay"]]
diff --git a/modules/stage1_target.py b/modules/stage1_target.py
index 93f8278c..95e36815 100644
--- a/modules/stage1_target.py
+++ b/modules/stage1_target.py
@@ -1,6 +1,6 @@
 # Copyright 1999-2004 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/modules/stage1_target.py,v 1.7 2005/04/04 17:48:33 rocket Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/modules/stage1_target.py,v 1.8 2005/04/07 23:02:20 rocket Exp $
 
 """
 Builder class for a stage1 installation tarball build.
@@ -28,6 +28,24 @@ class stage1_target(generic_stage_target):
 		generic_stage_target.set_cleanables(self)
 		self.settings["cleanables"].extend(["/usr/share/gettext","/usr/lib/python2.2/test", "/usr/lib/python2.2/encodings","/usr/lib/python2.2/email", "/usr/lib/python2.2/lib-tk","/usr/share/zoneinfo"])
 
+	def override_chost(self):
+	    if os.environ.has_key("CHOST"):
+		self.settings["CHOST"] = os.environ["CHOST"]
+	    if self.settings.has_key("chost"):
+		self.settings["CHOST"]=list_to_string(self.settings["chost"])
+
+	def override_cflags(self):
+	    if os.environ.has_key("CFLAGS"):
+		self.settings["CFLAGS"] = os.environ["CFLAGS"]
+	    if self.settings.has_key("cflags"):
+		self.settings["CFLAGS"]=list_to_string(self.settings["cflags"])
+
+	def override_cxxflags(self):
+	    if os.environ.has_key("CXXFLAGS"):
+		self.settings["CXXFLAGS"] = os.environ["CXXFLAGS"]
+	    if self.settings.has_key("cxxflags"):
+		self.settings["CXXFLAGS"]=list_to_string(self.settings["cxxflags"])
+
 def register(foo):
 	foo.update({"stage1":stage1_target})
 	return foo
diff --git a/targets/support/livecdfs-update.sh b/targets/support/livecdfs-update.sh
index 3f067825..ac2b558e 100755
--- a/targets/support/livecdfs-update.sh
+++ b/targets/support/livecdfs-update.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 # Copyright 1999-2004 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/targets/support/livecdfs-update.sh,v 1.4 2005/04/06 23:23:57 rocket Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/targets/support/livecdfs-update.sh,v 1.5 2005/04/07 23:02:20 rocket Exp $
 
 /usr/sbin/env-update
 source /etc/profile
@@ -186,7 +186,7 @@ case ${clst_livecd_type} in
 	* )
 		cat /etc/generic.motd.txt /etc/minimal.motd.txt > /etc/motd
 		sed -i 's:^##GREETING:Welcome to the Gentoo Linux LiveCD!:' /etc/motd
-case
+esac
 
 rm -f /etc/generic.motd.txt /etc/universal.motd.txt /etc/minimal.motd.txt /etc/environmental.motd.txt /etc/gamecd.motd.txt
 
-- 
2.26.2