Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Valued Contributor III
1,346 Views

access environmental variables in _hw.tcl files

Hello all, 

 

When I try to print an environmental variables in the Quartus TCL Console (e.g. puts $::env(PATH) ) it works, but whenever I try to access it within a _hw.tcl component script it doesn't and I get the following error during elaboration: 

 

Can't read "::env(PATH)": no such element in array 

 

Could anyone shed some light on this? 

 

Thank you.
0 Kudos
6 Replies
Highlighted
Valued Contributor III

Re: access environmental variables in _hw.tcl files

I found the same issue, but never had time to look into it much further. 

 

The following command might be useful to you to use as a work around (if all you want is the path to the _hw.tcl file): 

 

set path_to_script ]]  

 

where 'info script' gives you the _hw.tcl file, 'file normalize' gives you the full path to that script, and 'file dirname' strips off the _hw.tcl name. 

 

At that point, you can use names relative to the _hw.tcl location. 

 

Cheers, 

Dave
0 Kudos
Highlighted
Valued Contributor III

Re: access environmental variables in _hw.tcl files

Dear Dave, 

 

Thank you for your reply. However, I want to reference the path of a separate file (not the TCL script) in order to add it with the add_fileset_file command. Using a path relative to the location of the TCL script would work, but would not be elegant at all since the file to be added is several layers of hierarchy away. 

 

I will probably submit a service request with Altera.
0 Kudos
Highlighted
Valued Contributor III

Re: access environmental variables in _hw.tcl files

 

--- Quote Start ---  

 

I want to reference the path of a separate file (not the TCL script) in order to add it with the add_fileset_file command. Using a path relative to the location of the TCL script would work, but would not be elegant at all since the file to be added is several layers of hierarchy away. 

 

--- Quote End ---  

 

 

That was the situation I was also faced with. It would be nicer if the Tcl interpreter preserved the environment variables, but it doesn't. 

 

 

--- Quote Start ---  

 

I will probably submit a service request with Altera. 

--- Quote End ---  

 

 

Please post their response here.  

 

I'd like to see a more elegant solution too :) 

 

Cheers, 

Dave
0 Kudos
Highlighted
Valued Contributor III

Re: access environmental variables in _hw.tcl files

This is fixed in Quartus 13.0 as far as I can see.

0 Kudos
Highlighted
Valued Contributor III

Re: access environmental variables in _hw.tcl files

 

--- Quote Start ---  

This is fixed in Quartus 13.0 as far as I can see. 

--- Quote End ---  

 

Awesome, thanks for posting :) 

 

Cheers, 

Dave
0 Kudos
Highlighted
Valued Contributor III

Re: access environmental variables in _hw.tcl files

After some further testing I concluded that this was already fixed from Quartus/Qsys 12.1 onwards. 

 

The solution is that you need to use the correct package command that forces the component to be interpreted by the latest version of Qsys (and not SOPC Builder, for which reading environment variables doesn't work). 

 

For example, change the package command in your TCL file from e.g.: 

 

package require -exact sopc 11.0 

 

to either: 

 

package require -exact qsys 12.1 

 

or 

 

package require -exact qsys 13.0 

 

depending on the Quartus version you are using.
0 Kudos