Commits

doob committed f4a62bc

Refactored the build module. Enhanced the verbose output.

Comments (0)

Files changed (2)

dake/build/build.rb

 		
 		def build
 			verbose "building \"#{target.name}\"..."			
-
-			if one_at_a_time
-				modules = modules_to_compile
-				@linking = false if modules.empty?
-				
-				modules.each do |mod, path|
-					cmd = build_command(path)
-					verbose "files to compile:"
-					verbose cmd
-					execute(cmd)
-					rename_object_mod(mod)
-				end
-			else
-				files_to_compile, files_to_rename = build_files()
-				
-				if files_to_rename.length > 0
-					cmd = Config.compile.command.sub(Settings.config_d_file, files_to_compile) + flags
-				
-					verbose "files to compile:"
-					verbose cmd
-					execute(cmd)
-					verbose "renaming:"
-					
-					files_to_rename.each do |file|
-						rename_object(file.src, file.dest)
-						verbose ""
-					end
-				else
-					@linking = false
-				end				
+			build_one_at_a_time() if one_at_a_time
+			build_all_at_once() unless one_at_a_time
+		end
+		
+		def build_one_at_a_time
+			modules = modules_to_compile
+			@linking = false if modules.empty?
+			
+			modules.each do |mod, path|
+				cmd = build_command(path)
+				verbose "files to compile:"
+				verbose cmd
+				execute(cmd)
+				rename_object_mod(mod)
 			end
 		end
 		
+		def build_all_at_once
+			files_to_compile, files_to_rename = build_files()
+			
+			if files_to_rename.length > 0
+				cmd = build_command(files_to_compile)			
+				verbose_files_to_compile(files_to_rename)
+				execute_with_message(cmd, "compile:")				
+				rename_object_files(files_to_rename)
+			else
+				@linking = false
+			end
+		end
+		
+		def rename_object_files (files_to_rename)
+			verbose "\nrenaming:"
+			
+			files_to_rename.each do |file|
+				rename_object(file.src, file.dest)
+				verbose ""
+			end
+		end
+		
+		def verbose_files_to_compile (files_to_compile)
+			verbose "\nfiles to compile:" do
+				str = StringIO.new
+				
+				files_to_compile.each do |file|
+					str << "#{file.src}\n"
+				end
+				
+				verbose "#{str.string}\n"
+			end
+		end
+
 		def build_files
 			files_to_compile = StringIO.new
 			files_to_rename = []
 		def build_rename_command (mod)
 			{ :src => Settings.full_objects_path/object_name(mod) + "." + Config.object_extension,
 			  :dest => Settings.full_objects_path/mod + "." + Config.object_extension }
-		end		
+		end
 		
 		def rename_object (src, dest)			
 			verbose "\tsource: #{src}"

dake/util/util.rb

 
 import "dake.config.*"
 
-def verbose (*args)	
+def verbose (*args, &block)	
 	args.each do |arg|
 		puts arg if arg.is_a? String
 		p arg unless arg.is_a? String
 	end if Options.verbose
+	
+	block.call if Options.verbose && block_given?
 end
 
 module Dake
 
 		#raise "#{Config.compiler} returned #{$?.to_int/256} exit status\nline was: #{compiler_line}" if $?.to_i != 0
 	end
+	
+	def execute_with_message (cmd, message)
+		verbose message
+		execute cmd
+	end	
 end