Ben Elliston wrote:
I'm  testing   installed  GNU   toolchain  using  dejagnu.   I  just
encountered  a  problem that  find_g++  returned  a directory  which
happened  to be  named as  g++ and  located under  $tool_root_dir. I
expected it  would return  [transform g++]. I  can work  around this
problem by  naming that directory  in a name  other than g++.  But I
think  adding a check  on the  return value  of lookfor_file  in all
functions like  find_g++ might  be a better  solution. Is it  a good
idea?  If   possible,  I  can  try   to  work  out   a  patch.

Yes, please.

This is a patch. I add checking for each lookfor_file which is called
with $tool_root_dir as the first argument. I don't do the same thing for the other calls of lookfor_file, since those calls look for file or directory in source directory or installed directory, which might be laid out much more predictably. I think there is less chance of the problem. And I do the same thing for none of [file exists xxx] cases. There are too much cases there. So I don't know if it's good to do that for them. How about this patch?


Jie



2008-05-09  Jie Zhang  <[EMAIL PROTECTED]>

	* baseboards/basic-sid.exp (find_sid): Check if the return
	value of lookfor_file is a directory or a regular file.
	(find_rawsid): Likewise.
	* baseboards/basic-sim.exp (find_sim): Likewise.
	* baseboards/cf.exp: Likewise.
	* baseboards/i960-cyclone.exp: Likewise.
	* baseboards/op50n.exp: Likewise.
	* baseboards/rom68k-idp.exp: Likewsie.
	* config/ddb.exp: Likewise.
	* config/gdb-comm.exp (gdb_comm_start): Likewise.
	* config/gdb_stub.exp (gdb_stub_init): Likewise.
	* lib/libgloss.exp (newlib_link_flags): Likewise.
	(g++_link_flags): Likewise.
	(libstdc++_link_flags): Likewise.
	(find_binutils_prog): Likewsie.
	(find_gcc): Likewise.
	(find_gcj): Likewise.
	(find_g++): Likewise.
	(find_g77): Likewise.
	(find_gnatmake): Likewise.
	(find_nm): Likewise.
	(find_gas): Likewise.
	(find_ld): Likewise.


diff --git a/baseboards/basic-sid.exp b/baseboards/basic-sid.exp
index a7e3658..f994d1d 100644
--- a/baseboards/basic-sid.exp
+++ b/baseboards/basic-sid.exp
@@ -28,9 +28,11 @@ proc find_sid { target_alias } {
     global tool_root_dir
 
     set try [lookfor_file ${tool_root_dir} sid/bsp/${target_alias}-sid]
-    if { $try != "" } {
+    if { $try != "" && ![file isdirectory $try] } {
 	set sid_build [lookfor_file ${tool_root_dir} sid/main/dynamic/sid]
-	if { $sid_build != "" } { set env(SID) $sid_build }
+	if { $sid_build != "" && ![file isdirectory $sid_build] } {
+	    set env(SID) $sid_build
+	}
 	return $try
     }
 
@@ -59,7 +61,7 @@ proc find_rawsid { } {
     global srcdir
 
     set try [lookfor_file ${tool_root_dir} sid/main/dynamic/sid]
-    if { $try == "" } {
+    if { $try == "" || [file isdirectory $try] } {
 	set try "sid"
     } else {
 	# testing build tree
diff --git a/baseboards/basic-sim.exp b/baseboards/basic-sim.exp
index 23e27df..0fde0ed 100644
--- a/baseboards/basic-sim.exp
+++ b/baseboards/basic-sim.exp
@@ -41,10 +41,12 @@ proc find_sim { target_alias sim_dir sim_name } {
     # We have to search because tool_root_dir may actually point to that blasted
     # "target" subdirectory.
     set try [lookfor_file ${tool_root_dir} sim/${sim_dir}/${sim_name}]
-    if { $try != "" } {
+    if { $try == "" || [file isdirectory $try] } {
+	return ${target_alias}-${sim_name}
+    } else {
 	return $try
     }
-    return ${target_alias}-${sim_name}
+
 }
 
 proc setup_sim { subdir_name } {
diff --git a/baseboards/cf.exp b/baseboards/cf.exp
index 2839af3..71674d4 100644
--- a/baseboards/cf.exp
+++ b/baseboards/cf.exp
@@ -55,10 +55,10 @@ unset extra_m68k_ld_flags
 # If no output format is specified, use objcopy.
 if {![board_info $board exists output_format]} {
     set tempfil [lookfor_file $tool_root_dir binutils/objcopy]
-    if { $tempfil != "" } {
-	set_board_info objcopy $tempfil
-    } else {
+    if { $tempfil == "" || [file isdirectory $tempfil] } {
 	set_board_info objcopy [transform objcopy]
+    } else {
+	set_board_info objcopy $tempfil
     }
     unset tempfil
 }
diff --git a/baseboards/i960-cyclone.exp b/baseboards/i960-cyclone.exp
index 3c87af4..2d18f08 100644
--- a/baseboards/i960-cyclone.exp
+++ b/baseboards/i960-cyclone.exp
@@ -30,10 +30,10 @@ process_multilib_options ""
 # We want to strip executables before downloading them via xmodem.
 if {![board_info $board exists strip]} {
     set tempfil [lookfor_file $tool_root_dir binutils/strip]
-    if { $tempfil != "" } {
-	set_board_info strip $tempfil
-    } else {
+    if { $tempfil == "" || [file isdirectory $tempfil] } {
 	set_board_info strip [transform strip]
+    } else {
+	set_board_info strip $tempfil
     }
     unset tempfil
 }
diff --git a/baseboards/op50n.exp b/baseboards/op50n.exp
index 924c354..e7c52bb 100644
--- a/baseboards/op50n.exp
+++ b/baseboards/op50n.exp
@@ -27,10 +27,10 @@ set_board_info gdb_protocol  "op50n"
 
 if {![board_info $board exists output_format]} {
     set tempfil [lookfor_file $tool_root_dir binutils/objcopy]
-    if { $tempfil != "" } {
-	set_board_info objcopy $tempfil
-    } else {
+    if { $tempfil == "" || [file isdirectory $tempfil] } {
 	set_board_info objcopy [transform objcopy]
+    } else {
+	set_board_info objcopy $tempfil
     }
     unset tempfil
 }
diff --git a/baseboards/rom68k-idp.exp b/baseboards/rom68k-idp.exp
index c21ee39..0098060 100644
--- a/baseboards/rom68k-idp.exp
+++ b/baseboards/rom68k-idp.exp
@@ -55,10 +55,10 @@ unset extra_m68k_ld_flags
 # If no output format is specified, use objcopy.
 if {![board_info $board exists output_format]} {
     set tempfil [lookfor_file $tool_root_dir binutils/objcopy]
-    if { $tempfil != "" } {
-	set_board_info objcopy $tempfil
-    } else {
+    if { $tempfil == "" || [file isdirectory $tempfil] } {
 	set_board_info objcopy [transform objcopy]
+    } else {
+	set_board_info objcopy $tempfil
     }
     unset tempfil
 }
diff --git a/config/ddb.exp b/config/ddb.exp
index 4a982e8..a8a027d 100644
--- a/config/ddb.exp
+++ b/config/ddb.exp
@@ -87,10 +87,10 @@ set_board_info dont_wait_for_prompt 1
 # If no output format is specified, use objcopy.
 if {![board_info $board exists output_format]} {
     set tempfil [lookfor_file $tool_root_dir binutils/objcopy]
-    if { $tempfil != "" } {
-	set_board_info objcopy $tempfil
-    } else {
+    if { $tempfil == "" || [file isdirectory $tempfil] } {
 	set_board_info objcopy [transform objcopy]
+    } else {
+	set_board_info objcopy $tempfil
     }
     unset tempfil
 }
diff --git a/config/gdb-comm.exp b/config/gdb-comm.exp
index b7dbfc3..f6be0dd 100644
--- a/config/gdb-comm.exp
+++ b/config/gdb-comm.exp
@@ -166,7 +166,7 @@ proc gdb_comm_start { dest } {
     # provided with one.
     if {![info exists GDB]} then {
 	set GDB "[lookfor_file ${tool_root_dir} gdb/gdb]"
-	if { $GDB == "" } {
+	if { $GDB == "" || [file isdirectory $GDB] } {
 	    set GDB [transform gdb]
 	}
     }
diff --git a/config/gdb_stub.exp b/config/gdb_stub.exp
index 6c33a5f..5bffa04 100644
--- a/config/gdb_stub.exp
+++ b/config/gdb_stub.exp
@@ -30,7 +30,7 @@ proc gdb_stub_init { dest args } {
 
     if {![info exists GDB]} then {
 	set GDB "[lookfor_file ${tool_root_dir} gdb/gdb]"
-	if { $GDB == "" } {
+	if { $GDB == "" || [file isdirectory $GDB] } {
 	    set GDB [transform gdb]
 	}
     }
diff --git a/lib/libgloss.exp b/lib/libgloss.exp
index 1adb2bb..18945f0 100644
--- a/lib/libgloss.exp
+++ b/lib/libgloss.exp
@@ -118,7 +118,7 @@ proc newlib_link_flags { args } {
     }
 
     set ld_script_path [lookfor_file ${tool_root_dir} "ld/ldscripts"]
-    if { $ld_script_path != "" } {
+    if { $ld_script_path != "" && [file isdirectory $ld_script_path] } {
 	set result "-L[file dirname $ld_script_path]"
     } else {
 	set result ""
@@ -291,21 +291,21 @@ proc g++_link_flags { args } {
 	global tool_root_dir
 
 	set libgpp [lookfor_file ${tool_root_dir} libg++]
-	if { $libgpp != "" } {
+	if { $libgpp != "" && [file isdirectory $libgpp] } {
 	    append flags "-L${libgpp} "
 	    append ld_library_path ":${libgpp}"
 	}
 	set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
-	if { $libstdcpp != "" } {
+	if { $libstdcpp != "" && [file isdirectory $libstdcpp] } {
 	    append flags "-L${libstdcpp} "
 	    append ld_library_path ":${libstdcpp}"
 	}
 	set libiberty [lookfor_file ${tool_root_dir} libiberty]
-	if { $libiberty != "" } {
+	if { $libiberty != "" && [file isdirectory $libiberty] } {
 	    append flags "-L${libiberty} "
 	}
 	set librx [lookfor_file ${tool_root_dir} librx]
-	if { $librx != "" } {
+	if { $librx != "" && [file isdirectory $librx] } {
 	    append flags "-L${librx} "
 	}
     }
@@ -368,16 +368,16 @@ proc libstdc++_link_flags { args } {
 	global tool_root_dir
 
 	set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
-	if { $libstdcpp != "" } {
+	if { $libstdcpp != "" && [file isdirectory $libstdcpp] } {
 	    append flags "-L${libstdcpp} "
 	    append ld_library_path ":${libstdcpp}"
 	}
 	set libiberty [lookfor_file ${tool_root_dir} libiberty]
-	if { $libiberty != "" } {
+	if { $libiberty != "" && [file isdirectory $libiberty] } {
 	    append flags "-L${libiberty} "
 	}
 	set librx [lookfor_file ${tool_root_dir} librx]
-	if { $librx != "" } {
+	if { $librx != "" && [file isdirectory $librx] } {
 	    append flags "-L${librx} "
 	}
     }
@@ -606,19 +606,19 @@ proc find_binutils_prog { name } {
     if {![is_remote host]} {
 
 	set file [lookfor_file $tool_root_dir $name]
-	if { $file == "" } {
+	if { $file == "" || [file isdirectory $file] } {
 	    set file [lookfor_file $tool_root_dir ${name}-new]
 	}
-	if { $file == "" } {
+	if { $file == "" || [file isdirectory $file] } {
 	    set file [lookfor_file $tool_root_dir binutils/$name]
 	}
-	if { $file == "" } {
+	if { $file == "" || [file isdirectory $file] } {
 	    set file [lookfor_file $tool_root_dir binutils/${name}-new]
 	}
-	if { $file != "" } {
-	    set NAME "$file"
-	} else {
+	if { $file == "" || [file isdirectory $file] } {
 	    set NAME [transform $name]
+	} else {
+	    set NAME "$file"
 	}
     } else {
 	set NAME [transform $name]
@@ -631,13 +631,13 @@ proc find_gcc {} {
 
     if {![is_remote host]} {
 	set file [lookfor_file $tool_root_dir xgcc]
-	if { $file == "" } {
+	if { $file == "" || [file isdirectory $file] } {
 	    set file [lookfor_file $tool_root_dir gcc/xgcc]
 	}
-	if { $file != "" } {
-	    set CC "$file -B[file dirname $file]/"
-	} else {
+	if { $file == "" || [file isdirectory $file] } {
 	    set CC [transform gcc]
+	} else {
+	    set CC "$file -B[file dirname $file]/"
 	}
     } else {
 	set CC [transform gcc]
@@ -650,13 +650,13 @@ proc find_gcj {} {
 
     if {![is_remote host]} {
 	set file [lookfor_file $tool_root_dir gcj]
-	if { $file == "" } {
+	if { $file == "" || [file isdirectory $file] } {
 	    set file [lookfor_file $tool_root_dir gcc/gcj]
 	}
-	if { $file != "" } {
-	    set CC "$file -B[file dirname $file]/"
-	} else {
+	if { $file == "" || [file isdirectory $file] } {
 	    set CC [transform gcj]
+	} else {
+	    set CC "$file -B[file dirname $file]/"
 	}
     } else {
 	set CC [transform gcj]
@@ -669,13 +669,13 @@ proc find_g++ {} {
 
     if {![is_remote host]} {
 	set file [lookfor_file $tool_root_dir g++]
-	if { $file == "" } {
+	if { $file == "" || [file isdirectory $file] } {
 	    set file [lookfor_file $tool_root_dir gcc/g++]
 	}
-	if { $file != "" } {
-	    set CC "$file -B[file dirname $file]/"
-	} else {
+	if { $file == "" || [file isdirectory $file] } {
 	    set CC [transform g++]
+	} else {
+	    set CC "$file -B[file dirname $file]/"
 	}
     } else {
 	set CC [transform g++]
@@ -688,13 +688,13 @@ proc find_g77 {} {
 
     if {![is_remote host]} {
 	set file [lookfor_file $tool_root_dir g77]
-	if { $file == "" } {
+	if { $file == "" || [file isdirectory $file] } {
 	    set file [lookfor_file $tool_root_dir gcc/g77]
 	}
-	if { $file != "" } {
-	    set CC "$file -B[file dirname $file]/"
-	} else {
+	if { $file == "" || [file isdirectory $file] } {
 	    set CC [transform g77]
+	} else {
+	    set CC "$file -B[file dirname $file]/"
 	}
     } else {
 	set CC [transform g77]
@@ -707,14 +707,14 @@ proc find_gnatmake {} {
 
     if {![is_remote host]} {
 	set file [lookfor_file $tool_root_dir gnatmake]
-	if { $file == "" } {
+	if { $file == "" || [file isdirectory $file] } {
 	    set file [lookfor_file $tool_root_dir gcc/gnatmake]
 	}
-	if { $file != "" } {
+	if { $file == "" || [file isdirectory $file] } {
+	    set CC [transform gnatmake]
+	} else {
 	    set root [file dirname $file]
 	    set CC "$file -I$root/ada/rts --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs --GCC=$root/xgcc -B$root -margs"
-	} else {
-	    set CC [transform gnatmake]
 	}
     } else {
 	set CC [transform gnatmake]
@@ -728,11 +728,11 @@ proc find_nm {} {
     set NM ""
     if {![is_remote host]} {
 	set NM [lookfor_file $tool_root_dir nm-new]
-	if {$NM == ""} {
+	if { $NM == "" || [file isdirectory $NM] } {
  	    set NM [lookfor_file $tool_root_dir binutils/nm-new]
 	}
     }
-    if { $NM == ""} {
+    if { $NM == "" || [file isdirectory $NM] } {
 	set NM [transform nm]
     }
     return $NM
@@ -826,11 +826,11 @@ proc find_gas { } {
 
     if {![is_remote host]} {
 	set AS [lookfor_file $tool_root_dir as-new]
-	if { $AS == "" } {
+	if { $AS == "" || [file isdirectory $GAS] } {
 	    set AS [lookfor_file $tool_root_dir gas/as-new]
 	}
     }
-    if { $AS == "" } {
+    if { $AS == "" || [file isdirectory $GAS] } {
 	set AS [transform as]
     }
     return $AS
@@ -843,11 +843,11 @@ proc find_ld { } {
 
     if {![is_remote host]} {
 	set LD [lookfor_file $tool_root_dir ld-new]
-	if { $LD == "" } {
+	if { $LD == "" || [file isdirectory $LD] } {
 	    set LD [lookfor_file $tool_root_dir ld/ld-new]
 	}
     }
-    if { $LD == "" } {
+    if { $LD == "" || [file isdirectory $LD] } {
 	set LD [transform ld]
     }
     return $LD
_______________________________________________
DejaGnu mailing list
DejaGnu@gnu.org
http://lists.gnu.org/mailman/listinfo/dejagnu

Reply via email to