siemens / kas

Setup tool for bitbake based projects
MIT License
339 stars 145 forks source link

.bashrc in shell command #88

Closed lfdmn closed 1 year ago

lfdmn commented 1 year ago

I'm new to kas and trying things out. Nice work :)

When going to kas shell is there a way to get .bashrc sourced?

My usecase is that I define a bunch of aliases I'd like to be able to use when working on recipes.

I tried -E, --preserve-env argument but it didn't help.

henning-schild commented 1 year ago

kas and its companion container aim at creating a fresh and pretty isolated environment so that host contamination does not happen, that means you will find your build somewhat isolated from the happy env you know and that is by design

Say you use the container, i imagine you could volume mount some shell script into the container and source that manually. It seems the shell is not a login shell so even if you place it in /etc/profile.d/ it will not magically work.

echo "echo HELLO" > /tmp/hack.sh
kas-container --ssh-dir ~/.ssh/ --runtime-args "-v /tmp/hack.sh:/etc/profile.d/hack.sh:ro" shell kas.yml
source /etc/profile.d/hack.sh
jan-kiszka commented 1 year ago

Is there a container in the loop as well, @lfdmn?

--preserve-env is indeed supposed to carry over the env from the calling shell into the kas shell. Possible worth the check based on concrete examples what is lost, and then why.

henning-schild commented 1 year ago

if we are talking about a "bash alias" man 1 bash_builtins i am afraid that has nothing to do with env.

lfdmn commented 1 year ago

Hi,

No there is no container in the loop. I have a LinuxMint 19 distro, pip3 install kass, made a bare minal config which clones poky and builds core-image-minimal.

When going to the shell the ll for ls - la for example isn't defined anymore.

How is the isolation implemented?

henning-schild commented 1 year ago

I personally hate aliases or custom configs, since they manifest habits that will cause trouble when working with many machines, but that is a personal thing.

There is a temporary $HOME directory which includes only some very carefully selected files, main feature is that it will be empty. The env variable HOME is also set to hopefully convince all tools to not find anything in the real HOME.

Just check out env and look at HOME, compare that to your real or to ~.

Your best bet is to remember to source that file from your real home manually whenever you need the shell, or get used to not using ll.

Possible other hacks could be applying a patch from your layer in oe-init-build-env or isar-init-build-env. That is potentially even valid since you will make ll available to everyone using your layer. But a super hacky pattern people hopefully do not abuse to contaminate the build env which is on purpose very clean.

lfdmn commented 1 year ago

OK thanks for the pointers.

I'll keep investigating kas to see how it could fit my workflows.