mbeckerle opened a new issue, #652:
URL: https://github.com/apache/daffodil-vscode/issues/652

   I was unable to get the daffodil vscode 1.3.0-RC2 to work when installed.
   
   This is because the vscode extension is sensitive to the default 
environment. It currently picks up many things from the users default shell 
environment.
   
   The vscode extension needs to be isolated from the user's shell environment.
   
   One example is that the vscode extension requires Java 11. 
   
   Starting the vscode extension needs to guarantee Java 11 is what is being 
used. It should not use what is configured via the JAVA_HOME environment 
variable by the user. (Mine is defaulting to Java 17 these days.)
   
   To get vscode to work I have this script I use to launch vscode in a 
minimal/empty environment with just the few things it needs. This technique is 
also useful to determine if you are depending on the environment in any way:
   
   ```
   #! /bin/bash
   if [ "$1" = "emptyEnv" ] # is it the special first arg
   then
     shift # discard special first arg, and continue with the rest of the script
   else
     # execute this same script again in an empty environment
     CMD=$0
     exec -c $CMD "emptyEnv" $* # exec with an empty environment and special 
first arg
   fi
   # the environment is empty when we get here
   # just add env vars we need to get vscode to work
   export LANG=en_US.UTF-8
   export HOME=/home/mbeckerle
   export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 # java 11 required
   export PATH=$JAVA_HOME/bin:$PATH
   export DISPLAY=:0
   export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus # vscode spits 
lots of errors without this
   exec /usr/bin/code
   # end
   ```
   
   Then, within ~/.config/Code/User/settings.json, I had to create these 
settings for terminal:
   
   ```
       "terminal.integrated.inheritEnv": false,
       "terminal.integrated.profiles.linux": {
           "Custom Init": {
             "path": "/bin/bash",
             "args": [
                "--norc"
             ]
           }
         },
         "terminal.integrated.defaultProfile.linux": "Custom Init"
   ```
   
   That instructs vscode not to create a login shell for the terminal. The 
--norc option means it does not run the .bashrc file so that the java version 
specified in the launch script sticks. 
   
   I am not sure the inheritEnv setting actually does anything. That alone 
sounds like the right thing, but that alone didn't solve the problem.
   You still have everything in the login shell environment where vscode was 
launched. Hence the need for the environment-emptying launch script.
   
   With those two techniques combined, a terminal created by vscode does not 
inherit everything my typical shell has. For example there is no daffodil on 
the path, no DAFFODIL_CLASSPATH env var, etc. Rather it has only a small 
environment of just what vscode needs.
   
   Given the above if I just create a terminal with Terminal > new Terminal: 
The environment is relatively simple:
   
   ```
   bash-5.0$ env
   COLORTERM=truecolor
   TERM_PROGRAM_VERSION=1.78.2
   JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
   NO_AT_BRIDGE=1
   PWD=/home/mbeckerle/dataiti/opensource/DFDLSchemas/PCAP
   VSCODE_GIT_ASKPASS_NODE=/usr/share/code/code
   HOME=/home/mbeckerle
   LANG=en_US.UTF-8
   GIT_ASKPASS=/usr/share/code/resources/app/extensions/git/dist/askpass.sh
   CHROME_DESKTOP=code-url-handler.desktop
   VSCODE_GIT_ASKPASS_EXTRA_ARGS=--ms-enable-electron-run-as-node
   TERM=xterm-256color
   VSCODE_GIT_IPC_HANDLE=/tmp/vscode-git-56a269c0f5.sock
   DISPLAY=:0
   SHLVL=1
   
VSCODE_GIT_ASKPASS_MAIN=/usr/share/code/resources/app/extensions/git/dist/askpass-main.js
   GDK_BACKEND=x11
   
PATH=/usr/lib/jvm/java-11-openjdk-amd64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
   ORIGINAL_XDG_CURRENT_DESKTOP=undefined
   DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
   TERM_PROGRAM=vscode
   _=/usr/bin/env
   ```
   
   If I run daffodil debugging, then c-C in the terminal it creates, then the 
environment has this added environment variable only. 
   
   ```
   
DAFFODIL_DEBUG_CLASSPATH=/home/mbeckerle/dataiti/opensource/DFDLSchemas/PCAP/../ethernetIP/src/main/resources:/home/mbeckerle/dataiti/opensource/DFDLSchemas/PCAP/lib_managed/jars/com.owlcyberdefense/dfdl-ethernetip/dfdl-ethernetip-1.2.0.jar
   ```
   
   This works.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to