Allow variables to come from shell commands
This commit is contained in:
parent
174923cbc8
commit
629d6bf612
2 changed files with 35 additions and 2 deletions
|
|
@ -158,8 +158,10 @@ class DebugSession( object ):
|
||||||
'dollar': '$', # HACK
|
'dollar': '$', # HACK
|
||||||
'workspaceRoot': self._workspace_root
|
'workspaceRoot': self._workspace_root
|
||||||
}
|
}
|
||||||
self._variables.update( adapter.get( 'variables', {} ) )
|
self._variables.update(
|
||||||
self._variables.update( configuration.get( 'variables', {} ) )
|
utils.ParseVariables( adapter.get( 'variables', {} ) ) )
|
||||||
|
self._variables.update(
|
||||||
|
utils.ParseVariables( configuration.get( 'variables', {} ) ) )
|
||||||
self._variables.update( launch_variables )
|
self._variables.update( launch_variables )
|
||||||
|
|
||||||
utils.ExpandReferencesInDict( configuration, self._variables )
|
utils.ExpandReferencesInDict( configuration, self._variables )
|
||||||
|
|
|
||||||
|
|
@ -328,6 +328,37 @@ def ExpandReferencesInDict( obj, mapping, **kwargs ):
|
||||||
obj[ k ] = expand_refs_in_object( obj[ k ] )
|
obj[ k ] = expand_refs_in_object( obj[ k ] )
|
||||||
|
|
||||||
|
|
||||||
|
def ParseVariables( variables ):
|
||||||
|
new_variables = {}
|
||||||
|
for n,v in variables.items():
|
||||||
|
if isinstance( v, dict ):
|
||||||
|
if 'shell' in v:
|
||||||
|
import subprocess
|
||||||
|
import shlex
|
||||||
|
|
||||||
|
new_v = v.copy()
|
||||||
|
# Bit of a hack. Allows environment variables to be used.
|
||||||
|
ExpandReferencesInDict( new_v, {} )
|
||||||
|
|
||||||
|
env = os.environ.copy()
|
||||||
|
env.update( new_v.get( 'env' ) or {} )
|
||||||
|
cmd = new_v[ 'shell' ]
|
||||||
|
if not isinstance( cmd, list ):
|
||||||
|
cmd = shlex.split( cmd )
|
||||||
|
|
||||||
|
new_variables[ n ] = subprocess.check_output(
|
||||||
|
cmd,
|
||||||
|
cwd = new_v.get( 'cwd' ) or os.getcwd(),
|
||||||
|
env = env ).decode( 'utf-8' ).strip()
|
||||||
|
else:
|
||||||
|
raise ValueError(
|
||||||
|
"Unsupported variable defn {}: Missing 'shell'".format( n ) )
|
||||||
|
else:
|
||||||
|
new_variables[ n ] = v
|
||||||
|
|
||||||
|
return new_variables
|
||||||
|
|
||||||
|
|
||||||
def DisplayBaloon( is_term, display ):
|
def DisplayBaloon( is_term, display ):
|
||||||
if not is_term:
|
if not is_term:
|
||||||
display = '\n'.join( display )
|
display = '\n'.join( display )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue