Author Topic: Common sourcing script for cross compiler  (Read 737 times)

jmbraben

  • Junior Community Member
  • Posts: 6
  • Hero Points: 0
Common sourcing script for cross compiler
« on: June 01, 2018, 07:39:05 pm »
In the yocto generated toolchains, there is always an environment configuration script that must be run to ensure that the compiler will actually run and refer to proper includes.
I don't see any way I can run this script based on the selected COMPILER within the project. Doing this within the project makes no sense as this is a compiler environment. If I were to set it within "pre-build commands, it would have to be done for every project and would have to change any time I switch compiler versions.
How do I source an environment coupled to the toolchain? Am I missing this?

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4485
  • Hero Points: 344
Re: Common sourcing script for cross compiler
« Reply #1 on: June 01, 2018, 09:28:49 pm »
Too many unknowns here. What platform are you on?

When you created your workspace/project, which project type did you choose?

jmbraben

  • Junior Community Member
  • Posts: 6
  • Hero Points: 0
Re: Common sourcing script for cross compiler
« Reply #2 on: June 04, 2018, 04:15:57 pm »
GNU C/C++, user maintained makefile (but could change type if that would help).
Again, the point is to ensure the compiler is running in the correct environment, and this should be done based on the compiler, not the project. So what is correct way to do this?

SlickEdit Pro 2017 (v22.0.2.1 64-bit)
Build Date: March 23, 2018
Emulation: CUA
OS: Linux
OS Version: Ubuntu 16.04.4 LTS
Kernel Level: 4.13.0-43-generic
Build Version: #48~16.04.1-Ubuntu SMP Thu May 17 12:56:46 UTC 2018
Processor Architecture: x86_64

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4485
  • Hero Points: 344
Re: Common sourcing script for cross compiler
« Reply #3 on: June 04, 2018, 04:36:26 pm »
We like to setup our environment per workspace since our workspaces have tons of projects. However, you would have to do this via Project>Workspace Properties>Environment... You couldn't use a script.

Another way is to create your own indirection script. For example, instead of running make, you could run <the-make-for-this-workspace> which sets up the environment and then runs the make. Using a pre-build command only works for very simple scripts since SlickEdit uses it's own shell and doesn't support any fancy conditional logic. This had to be done because "bash" doesn't support simple piping.

jmbraben

  • Junior Community Member
  • Posts: 6
  • Hero Points: 0
Re: Common sourcing script for cross compiler
« Reply #4 on: June 07, 2018, 07:09:50 pm »
This is definitely a big limitation...especially with regards to cross compiling with yocto toolchains.
If I source an environment prior to starting the editor, does it pass through to any shells?
If so, why can't you allow me to run a script in a bash shell to establish my environment and then launch your shell from there?
Again, this is a real problem, and I'd like to think there is a clean solution. It seems ridiculous that I can't (globally) configure an environment for a particular toolchain.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4485
  • Hero Points: 344
Re: Common sourcing script for cross compiler
« Reply #5 on: June 07, 2018, 08:17:03 pm »
You can set the environment in a terminal and start SlickEdit from there. That will work.

"source whatever" in the slickedit build shell (secsh) likely won't work. However, like I said, you can write a script to do "source whatever" AND also do the build. Then use that as your build command.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4485
  • Hero Points: 344
Re: Common sourcing script for cross compiler
« Reply #6 on: June 07, 2018, 09:13:02 pm »
Here's an interesting idea. You can write a script which sets the environment AND runs another copy of secsh (just invoke another instance). SlickEdit will still be able to exit it even though secsh has been invoked twice. This would allow your "source whatever" to work and for you to have a working build shell. Then you wouldn't have to create a special terminal with the environment already set (although that seems like a decent way to work also).

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4485
  • Hero Points: 344
Re: Common sourcing script for cross compiler
« Reply #7 on: June 08, 2018, 01:14:57 am »
bash does not support interactive commands (bash -i) when run via a pipe which is what slickedit uses for its' build shell. bash -i needs to detect when it's being run via a pipe but it doesn't.
« Last Edit: June 08, 2018, 01:59:30 am by Clark »

rowbearto

  • Senior Community Member
  • Posts: 1167
  • Hero Points: 73
Re: Common sourcing script for cross compiler
« Reply #8 on: June 08, 2018, 02:37:53 pm »
I'm able to get "bash -i" to run in the SE shell by using the "script" utility to wrap it into a pty:

script -eqfc "bash -i" /dev/null

Now you can run bash in the SE shell :)

If you look at the process tree for this you will see:

Code: [Select]
$ pstree -s -p $$
systemd(1)---sh(21055)---vs_exe(21061)---secsh(5261)---script(10610)---script(10612)---bash(10613)---pstree(10899)
« Last Edit: June 08, 2018, 02:42:51 pm by rowbearto »

rowbearto

  • Senior Community Member
  • Posts: 1167
  • Hero Points: 73
Re: Common sourcing script for cross compiler
« Reply #9 on: June 08, 2018, 02:39:12 pm »
Pertaining to the original topic of this conversation, in order to set my environment I don't call "make" directly from SE, rather I invoke a shell script that sources/sets my environment and then invokes "make". I even take it much further than this and my shell script will ssh into another machine, run another script from ssh to source the environment there, then it calls "make"

jmbraben

  • Junior Community Member
  • Posts: 6
  • Hero Points: 0
Re: Common sourcing script for cross compiler
« Reply #10 on: June 08, 2018, 03:59:13 pm »
I'll play around and see if I can find a reasonable solution (However, I feel I should not have to).
The issue I have is many projects that need to be compiled with multiple toolchains (that each need their own environments)...so I really want an environment that is tied to the compilers (not the projects, nor their makefiles, nor should I have to shim all of my project builds...and yes, I'm being whiny  ;D).

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4485
  • Hero Points: 344
Re: Common sourcing script for cross compiler
« Reply #11 on: June 08, 2018, 04:20:29 pm »
I'm able to get "bash -i" to run in the SE shell by using the "script" utility to wrap it into a pty:

script -eqfc "bash -i" /dev/null
[/code]

For me, my prompt becomes weird when I try this.
Code: [Select]
<ESC>0;cmaurer@ubuntu14-clark: ~/f/projects/gnucpp2/cmaurer@ubuntu14-clark:~/f/projects/gnucpp2/$

rowbearto

  • Senior Community Member
  • Posts: 1167
  • Hero Points: 73
Re: Common sourcing script for cross compiler
« Reply #12 on: June 08, 2018, 05:00:23 pm »
@Clark: If you have color or other control characters in your prompt, then they come out that way. It is also common in prompts to have some control chars that set the title of the window. Its actually a feature request that I've made before for the process buffer, as well as editor windows showing build logs, to show the colors from these control chars :)  :  https://community.slickedit.com/index.php?topic=15761.0

In my scripts that set the prompt, I specifically check if I'm running under slickedit, if so I take out all color coding and window title setting in my prompt. But would be nice if we could get the colors in the process buffer not just for a colored prompt, but also to see compiler errors that are shown in color. SE could also ignore any control chars that are used to set the title of the terminal window that are common in prompts.

Here is how I change my prompt based on whether in SE or not:

Code: [Select]
if ((${#SLICKEDITCONFIG[@]}))
then
  export SLICKTERM="true"
else
  export SLICKTERM="false"
fi
if [[ "${PROMPT_PATH_COLOR:-}" == "" ]]
then
  PROMPT_PATH_COLOR="32;1"
fi
if  [[ ( "$TERM" != "sun-cmd" ) && ( "$SLICKTERM" != "true" ) && ( -t 1 ) ]]
then
    # Color codes below can be obtained from:
    # https://misc.flogisoft.com/bash/tip_colors_and_formatting
    export PS1=']0;${CURRENT_VIEW}${MYHOST}:${PWD}''${CURRENT_VIEW_COLORED}'$'\033[${PROMPT_PATH_COLOR}'m'${MYHOST}:$PWD'$'\033[0m'"
\$ "

# set proper 'vi' mode for 'ksh' so that command recall works
# set -o viraw
else
    export PS1=$'${CURRENT_VIEW_SC}'$'${MYHOST}:$PWD'"
\$ "
    if [[ "$TERM" = sun-cmd ]]
    then
        cdsun . # put up the first display
        alias cd=cdsun
    fi
fi
fi

See:
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/c327.html
https://misc.flogisoft.com/bash/tip_colors_and_formatting
« Last Edit: June 08, 2018, 05:22:24 pm by rowbearto »

rowbearto

  • Senior Community Member
  • Posts: 1167
  • Hero Points: 73
Re: Common sourcing script for cross compiler
« Reply #13 on: June 08, 2018, 05:02:17 pm »
@jmbraben, I actually prefer to do all my environment settings in scripts and minimize that in SE. Most of my colleagues do not use SE - so in order for them to get the same environment settings as me, having a common script is the way to go.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4485
  • Hero Points: 344
Re: Common sourcing script for cross compiler
« Reply #14 on: June 08, 2018, 06:24:35 pm »
Thanks for the help. Support for this popular color output would be nice.