changed tcl procs abs_sym_path and rel_sym_path, now the real symbol filename is obtained by prepending one of the XSCHEM_LIBRARY_PATH paths until the symbol is found. This allows more than one directory levels in symbol references.

This commit is contained in:
schippes 2020-08-13 02:19:08 +02:00
parent c5f412bdb7
commit ea4513f9c5
5 changed files with 33 additions and 53 deletions

View File

@ -113,11 +113,6 @@ the schematic file `counter.sch' will be loaded.
After exiting XSCHEM you can load directly this schematic with the following commands, they are After exiting XSCHEM you can load directly this schematic with the following commands, they are
all equivalent. all equivalent.
<pre class="code"> <pre class="code">
# xschem defaults its search to the
# XSCHEM_LIBRARY_PATH root path
# .sch may be omitted, it is added by default ...
xschem test
# or ...
xschem /home/schippes/x/test.sch xschem /home/schippes/x/test.sch
# or ... # or ...
xschem ${HOME}/schippes/x/test xschem ${HOME}/schippes/x/test

View File

@ -28,13 +28,13 @@ p{padding: 15px 30px 10px;}
</li> </li>
<li> <li>
second approach: define a <kbd>XSCHEM_LIBRARY_PATH</kbd> that is a list of paths second approach: define a <kbd>XSCHEM_LIBRARY_PATH</kbd> that is a list of paths
one level above the directories containing .sym/.sch files one or more levels above the directories containing .sym/.sch files
</li> </li>
</ul> </ul>
<p> <p>
In the first approach a '<kbd>npn.sym</kbd>' symbol placed in a schematic will be In the first approach a '<kbd>npn.sym</kbd>' symbol placed in a schematic will be
saved as '<kbd>npn.sym</kbd>' in the .sch file, when loading back the parent saved as '<kbd>npn.sym</kbd>' in the .sch file, when loading back the parent
schematic xschem will go through the <kbd>XSCHEM_LIBRARY_PATH</kbd> and look for schematic xschem will go through the elements of <kbd>XSCHEM_LIBRARY_PATH</kbd> and look for
a directory containing <kbd>npn.sym</kbd>. a directory containing <kbd>npn.sym</kbd>.
</p> </p>
@ -50,10 +50,19 @@ p{padding: 15px 30px 10px;}
<p> <p>
The first approach is preferred by pcb hobbysts, people working on The first approach is preferred by pcb hobbysts, people working on
small designs. small designs.
the second approach is preferred for big designs where a one level the second approach is preferred for big designs where a one or more directory level
indirection is desired for symbols, so any symbol in xschem is given indirection is desired for symbols, so any symbol in xschem is given
as '<kbd>libname/symname.sym</kbd>' instead of just '<kbd>symname.sym</kbd>'<br> as '<kbd>libname/symname.sym</kbd>' (one level directory specification in symbol references)
or '<kbd>libgroup/libname/symname.sym</kbd>' (2 level directory specification in symbol references)
instead of just '<kbd>symname.sym</kbd>'<br>
</p>
<p>
In any case the real path of the symbol reference is obtained by prepending
the XSCHEM_LIBRARY_PATH paths to the symbol reference until the resulting file is found in
the machine filesystem.
</p>
<p>
For VLSI / big designs I <b>strongly</b> suggest using the second approach, For VLSI / big designs I <b>strongly</b> suggest using the second approach,
just as an example i have the following dirs: just as an example i have the following dirs:
</p> </p>

View File

@ -977,7 +977,7 @@ proc myload_set_home {dir} {
proc setglob {dir} { proc setglob {dir} {
global globfilter myload_files2 global globfilter myload_files2
set myload_files2 [lsort [glob -nocomplain -directory $dir -tails -type d \{.*,*\}]] set myload_files2 [lsort [glob -nocomplain -directory $dir -tails -type d \{.*,*\}]]
set myload_files2 ${myload_files2}\ [lsort [glob -nocomplain -directory $dir -tails -type {f l} \{.*,$globfilter\}]] set myload_files2 ${myload_files2}\ [lsort [glob -nocomplain -directory $dir -tails -type {f} \{.*,$globfilter\}]]
} }
proc load_file_dialog {{msg {}} {ext {}} {global_initdir {INITIALINSTDIR}}} { proc load_file_dialog {{msg {}} {ext {}} {global_initdir {INITIALINSTDIR}}} {
@ -2411,28 +2411,16 @@ proc viewdata {data {ro {}}} {
proc rel_sym_path {symbol} { proc rel_sym_path {symbol} {
global pathlist current_dirname global pathlist current_dirname
set lib_cell [get_cell $symbol]
set cell [file tail $symbol]
set name {} set name {}
if {[regexp {^/} $symbol]} {set symbol [file normalize $symbol]}
foreach path_elem $pathlist { foreach path_elem $pathlist {
if { ![string compare $path_elem .] && [info exist current_dirname]} { if { ![string compare $path_elem .] && [info exist current_dirname]} {
set path_elem $current_dirname set path_elem $current_dirname
} }
# libname/symname[.ext] and libname in $path_elem set pl [string length $path_elem]
# --> libname/symname if { [string equal -length $pl $path_elem $symbol] } {
if { [file exists [file dirname "${path_elem}/${lib_cell}"]] && set name [string range $symbol [expr $pl+1] end]
(![string compare $symbol $lib_cell ]) } {
set name ${lib_cell} ;# was lib_cell
# /.../path/.../libname/cellname[.ext] and libname in $path_elem
# --> libname/cellname
} elseif { (![string compare $symbol "${path_elem}/${lib_cell}" ])
&& [file exists [file dirname "${path_elem}/${lib_cell}"]] } {
set name ${lib_cell} ;# was lib_cell
} elseif { (![string compare $symbol "${path_elem}/${cell}" ])
&& [file exists "${path_elem}/${cell}"] } {
set name ${cell}
} }
if {$name ne {} } { break}
} }
if { ![string compare $name {} ] } { if { ![string compare $name {} ] } {
# no known lib, so return full path # no known lib, so return full path
@ -2445,6 +2433,8 @@ proc rel_sym_path {symbol} {
# given a library/symbol return its absolute path # given a library/symbol return its absolute path
proc abs_sym_path {fname {ext {} } } { proc abs_sym_path {fname {ext {} } } {
global pathlist current_dirname global pathlist current_dirname
if {$fname eq {} } return {}
if {$::OS == "Windows"} { if {$::OS == "Windows"} {
if { [regexp {^[A-Za-z]\:/$} $fname ] } { if { [regexp {^[A-Za-z]\:/$} $fname ] } {
return $fname; return $fname;
@ -2458,47 +2448,33 @@ proc abs_sym_path {fname {ext {} } } {
if { $ext ne {} } { if { $ext ne {} } {
set fname [file rootname $fname]$ext set fname [file rootname $fname]$ext
} }
# transform ./file_or_path to file_or_path # transform ./file_or_path to file_or_path, resolve (normalize) ../file_or_path
if { [regexp {^\.\./} $fname ] } { if { [regexp {^\.\./} $fname ] } {
set fname [file normalize $fname] set fname [file normalize $fname]
} elseif {[regexp {^\./} $fname ] } { } elseif {[regexp {^\./} $fname ] } {
regsub {^\./} $fname {} fname regsub {^\./} $fname {} fname
} }
set lib_cell [get_cell $fname] set lib_cell [get_cell $fname]
if {$fname eq {} } return {}
set name {} set name {}
# fname is of type libname/cellname[.ext] but not ./cellname[.ext] or if { ![regexp {^/} $fname] } {
# ../cellname[.ext] and has a slash, so no cellname[.ext]
# no ./cell.sym
if {![string compare $fname $lib_cell ]} {
foreach path_elem $pathlist { foreach path_elem $pathlist {
if { ![string compare $path_elem .] && [info exist current_dirname]} { if { ![string compare $path_elem .] && [info exist current_dirname]} {
set path_elem $current_dirname set path_elem $current_dirname
} }
# libname/cellname and libname is in pathlist set fullpath "$path_elem/$fname"
# --> $pathlist/libname/cellname if { [file exists $fullpath] } {
# cellname and $pathlist/cellname exists set name $fullpath
# --> $pathlist/cellname
if { [regexp {/} $fname] && [file exists "${path_elem}/${fname}"] } {
set name "$path_elem/$lib_cell"
break
}
if { [file exists "${path_elem}/${fname}"] &&
![regexp {/} $fname]
} {
set name "$path_elem/$lib_cell"
break break
} }
} }
# if no abs path, no existing items elsewhere, }
# set name relative to $current_dirname
if { ![string compare $name {}] } { if { ![string compare $name {}] } {
if { [regexp {^/} $fname] } {
set name $fname
} else {
set name "$current_dirname/$fname" set name "$current_dirname/$fname"
} }
} }
if { ![string compare $name {}] } {
set name $fname
}
regsub {/\.$} $name {} name regsub {/\.$} $name {} name
return $name return $name
} }

View File

@ -1,4 +1,4 @@
v {xschem version=2.9.5_RC5 file_version=1.1} v {xschem version=2.9.7 file_version=1.2}
G {type=label G {type=label
format="*.alias @lab" format="*.alias @lab"
template="name=l1 sig_type=std_logic lab=xxx"} template="name=l1 sig_type=std_logic lab=xxx"}

View File

@ -1,4 +1,4 @@
v {xschem version=2.9.5_RC6 file_version=1.1} v {xschem version=2.9.7 file_version=1.2}
G {} G {}
V {} V {}
S {} S {}