run script to set environment variables to be used in current icfb session

Discussion in 'Cadence' started by Erik Wanta, Mar 17, 2005.

  1. Erik Wanta

    Erik Wanta Guest

    I want to run a script in the .cdsinit to set some environment
    variables for the current icfb session. Is this possible?

    I can't use the following as the environment variables get set in the
    child shell.
    csh(strcat("source " getShellEnvVar("MGC_AMS_HOME")
    "/com/init_mgc_ams_home"))
     
    Erik Wanta, Mar 17, 2005
    #1
  2. Erik Wanta

    Erik Wanta Guest

    I can put the following in our .cdsinit but this is a horrible kludge
    as it needs to close and restart icfb.

    when(getShellEnvVar("MGC_AMS_HOME") && !getShellEnvVar("anacad")
    csh(strcat("source " getShellEnvVar("MGC_AMS_HOME")
    "/com/init_mgc_ams_home; icfb &"))
    exit()
    ) ; when

    when(getShellEnvVar("anacad")

    printf("MGC CUSTOMIZATION\n")

    geaAnacadInstallDir = getShellEnvVar("anacad")
    geaVersion = getShellEnvVar("artist_linkver")
    geaAMSSetup = nil
    when(!geaVersion && getShellEnvVar("AMS_ENV_PLT")
    ....
     
    Erik Wanta, Mar 17, 2005
    #2
  3. Erik Wanta

    Erik Wanta Guest

    This icfb restart kludge will be a problem if icfb was submitted with
    LSF (bsub -q queuename -I icfb &). Is there a way to get command that
    was used to start icfb in the icfb session?
     
    Erik Wanta, Mar 17, 2005
    #3
  4. Can you use setShellEnvVar() in .cdsinit to set the environment variables
    for the current session directly?
     
    Svenn Are Bjerkem, Mar 17, 2005
    #4
  5. I realy didn't understand what your are
    trying to do here?

    You check if the variable MGC_AMS_HOME is set and the you try to set it
    again and then you exit DFII?!
    For what reason?

    But rather than doing a and answering your initial question
    csh(
    strcat(
    "source "
    getShellEnvVar("MGC_AMS_HOME")
    "/com/init_mgc_ams_home; icfb &"
    )
    )

    and answering your initial question try
    setShellEnvVar( "MGC_AMS_HOME=/com/init_mgc_ams_home" )

    Bernd
     
    Bernd Fischer, Mar 17, 2005
    #5
  6. Erik Wanta

    S. Badel Guest

    I can't use the following as the environment variables get set in the
    the following csh script sources another script given as argument and extracts
    changes in the environment variables, then formats setShellEnvVar statements
    that you can evaluate with evalstring(), so you should be able to do

    p = ipcStartProcess( "envdiff.csh command" )
    ipcWait(p)
    evalstring( ipcReadProcess(p) )

    but i consider this as a workaround - not a really workable solution -
    better would be to set, in some way, the variables before running icfb

    use at your owk risks!

    stéphane


    #!/bin/csh -f
    # envdiff.csh
    # runs a specified script, then prints out the modified environment formatted as setShellEnvVar()
    statements
    #

    set cmd = "$*"
    env > /tmp/envdiff.prev
    source $cmd >& /dev/null && env > /tmp/envdiff.new
    echo `diff /tmp/envdiff.prev /tmp/envdiff.new | grep '^>' | sed 's/>\s*\(.*\)/setShellEnvVar("\1")/'`
    rm /tmp/envdiff.prev /tmp/envdiff.new
     
    S. Badel, Mar 17, 2005
    #6
  7. Erik,

    This is just something that you can't do in UNIX - execute a child process
    which sets the environment of the parent.

    The only possibility is if you run a child process which generates some SKILL
    code which you can then load from the parent DFII process; that SKILL code
    could contain setShellEnvVar() calls.

    Or you could cut out the middle man and just source some SKILL code...

    Or you could have a wrapper around icfb which sources the relevant file before
    it even starts the real icfb in the first place?

    Andrew.
     
    Andrew Beckett, Mar 17, 2005
    #7
  8. Erik Wanta

    Erik Wanta Guest

    Stéphane:
    Thank you for the idea. I get word too long errors however. I next
    tried the following with similar results as I believe the line limit is
    80 characters with ipcReadProcess.

    test:
    #!/bin/csh
    source ${MGC_AMS_HOME}/com/init_mgc_ams_home

    echo $anacad
    echo $AMS_ENV_PLT
    echo $AMS_ENV_VAR1
    echo $AMS_ENV_VAR2
    echo $AMS_ENV_VAR3
    echo $AMS_ENV_VAR4
    echo $AMS_ENV_VAR5

    printf("penv()\n")

    procedure(penv()
    prog(()

    cid=nil
    cid=ipcBeginProcess(strcat(getShellEnvVar("CDS_PROJECT") "/test"))
    ipcWait(cid)
    xx=ipcReadProcess(cid)
    dprint(xx)
    xx=ipcReadProcess(cid)
    dprint(xx)
    xx=ipcReadProcess(cid)
    dprint(xx)
    xx=ipcReadProcess(cid)
    dprint(xx)
    xx=ipcReadProcess(cid)
    dprint(xx)
    xx=ipcReadProcess(cid)
    dprint(xx)
    return(t)

    ) ; prog
    ) ; procedure
     
    Erik Wanta, Mar 19, 2005
    #8
  9. Erik Wanta

    S.Badel Guest

    Thank you for the idea. I get word too long errors however. I next
    there is no mention of such a limit in the documentation, but if the
    line is too long just echo the statements one per line.
    I don't know why i wrapped the fourth line in an echo statement, but
    when removing it each statement in on its own line.

    another option is to redirect the output to a file, then load() or
    loadi() it.

    by the way, i would also suggest to replace the evalstring with
    errsetstring, so that if something goes wrong it does not stop the
    ..cdsinit from executing and screw the whole session.

    stéphane


    #!/bin/csh -f
    # envdiff.csh
    # runs a specified script, then prints out the modified environment
    formatted as setShellEnvVar() statements
    #

    set cmd = "$*"
    env > /tmp/envdiff.prev
    source $cmd >& /dev/null && env > /tmp/envdiff.new
    diff /tmp/envdiff.prev /tmp/envdiff.new | grep '^>' | sed
    's/>\s*\(.*\)/setShellEnvVar("\1")/'
    rm /tmp/envdiff.prev /tmp/envdiff.new
     
    S.Badel, Mar 19, 2005
    #9
  10. Erik Wanta

    Erik Wanta Guest

    Stéphane:
    OK, I am doing the following. Thank you for your help! The Mentor AMS
    artistlink integration is way too convoluted and isn't conducive to
    cross platform job submission.

    if(outPort=outfile("/tmp/mentorvars.csh") then

    fprintf(outPort "#!/bin/csh\n")
    fprintf(outPort "source ${MGC_AMS_HOME}/com/init_mgc_ams_home\n")
    fprintf(outPort "echo \"anacad=\"$anacad > /tmp/mentorvars.out\n")
    fprintf(outPort "echo \"AMS_ENV_PLT=\"$AMS_ENV_PLT >>
    /tmp/mentorvars.out\n")
    fprintf(outPort "echo \"AMS_ENV_VAR1=\"$AMS_ENV_VAR1 >>
    /tmp/mentorvars.out\n")
    fprintf(outPort "echo \"AMS_ENV_VAR2=\"$AMS_ENV_VAR2 >>
    /tmp/mentorvars.out\n")
    fprintf(outPort "echo \"AMS_ENV_VAR3=\"$AMS_ENV_VAR3 >>
    /tmp/mentorvars.out\n")
    fprintf(outPort "echo \"AMS_ENV_VAR4=\"$AMS_ENV_VAR4 >>
    /tmp/mentorvars.out\n")
    fprintf(outPort "echo \"AMS_ENV_VAR5=\"$AMS_ENV_VAR5 >>
    /tmp/mentorvars.out\n")
    fprintf(outPort "echo \"PATH=\"$PATH >> /tmp/mentorvars.out\n")
    fprintf(outPort "echo \"LD_LIBRARY_PATH=\"$LD_LIBRARY_PATH >>
    /tmp/mentorvars.out\n")

    close(outPort)

    else
    error("unable to open")
    ) ; if

    csh("source /tmp/mentorvars.csh")

    if(inPort=infile("/tmp/mentorvars.out") then

    ;go through each line
    while(gets(line inPort)
    ;set Mentor env var
    setShellEnvVar(car(parseString(line "\n")))
    ) ; while

    close(inPort)
    else
    error("unable to open")
    ) ; if
     
    Erik Wanta, Mar 19, 2005
    #10
  11. Erik Wanta

    fogh Guest

    Hi Erik,
    you could do something with a diff.
    - csh("env > env_before")
    - csh("source myenvsettings.cshrc ; env > env_after")
    - MyDiff(before after)

    The MyDiff function would look for lines in "after" with var name that
    does not exist in "before", and pass the line to setShellEnvVar() . The
    implementation is left as an excercise to the reader ;) This can be made
    nicer with unique tempfiles or named pipes for the "before" and "after".

    I myself don t go to such extremes to preserve the usual way of
    starting workbench. I just make a shell wrapper (for instance "ragtime"
    for the Jazz technologies.) I don t remember there was that much env
    work to justify a wrapper last time I installed AMS kits tho.
     
    fogh, Mar 19, 2005
    #11
  12. Erik Wanta

    G Vandevalk Guest

    Sometimes you need to set the initial environment that
    dfII runs in. This is done because sometimes when dfII spawns a
    background task (say diva LVS !!!) and you need to make sure that
    the background task has the same environment as your normal dfII session.


    (but setting something in a sub-task then leaving dfII is clearly wrong!)

    Cadence seems to advise you to setup your native shell/csh environment to
    use the
    stuff you need, but they don't handle the case where one login id uses
    several different
    scripts from several vendors to setup several radically different dfII
    sessions.

    Beware ...

    -- G
     
    G Vandevalk, Mar 20, 2005
    #12
  13. Actually, we do this internally all the time. In the Pittsburgh
    (Neolinear) office, our convention is to have a file called "csh.cshrc"
    in the vendor directory which we source before launching
    icfb/icms/layoutPlus.

    It wasn't practical for us to have a wrapper script (we were constantly
    switching versions and streams), but if you were, say, a CAD admin for
    ExcellentChip, Inc., you could make a script for your users like the
    following:

    ----
    #! /bin/sh
    # Assumes that this script is launched as "xc" + toolname, e.g.,
    # xcicfb, xcicms, xclayoutPlus, etc.

    if [ x"${CDS_Netlisting_Mode}" = "x" ]; then
    CDS_Netlisting_Mode=Analog;
    export CDS_Netlisting_Mode;
    fi;

    # Note: Recent IC versions don't need this; however, this script
    # will use it to determine where to launch DFII, etc., from.
    if [ x"${CDS_INST_DIR}" = "x" ]; then
    CDS_INST_DIR=/opt/IC-5.10.41-USR2;
    export CDS_INST_DIR;
    fi;

    # Make sure IC tools are in the path
    PATH=${CDS_INST_DIR}/tools/bin:${CDS_INST_DIR}/tools/dfII/bin:${PATH}
    export PATH

    # Strip off leading 'xc' from tool name
    TOOLNAME=`basename $0 | sed -e 's/^xc//'`;
    exec ${TOOLNAME} ${1+"$@"}
     
    David Cuthbert, Mar 31, 2005
    #13
  14. Hello,

    This is enough in /bin/sh and saves two processes:)
    TOOLNAME=${0##*/xc}

    Ok, I know this is not comp.shell.sh, but I couldn't resist ...

    Aldric
     
    Aldric L'Hernault, Apr 11, 2005
    #14
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.