This blog post provides insight into the underlying mechanisms of Business Application Studio(BAS) and how the curious of us can leverage this understanding to extend the built-in capabilities. While the approach described is general in nature, we will be focusing on attempting to provide a full development experience for python developers.
I’ll be using the version of Business Application Studio found in trial account as of the writing of this blog post. December 10, 2020.
I created my Dev Space with the starting point of a type of SAP Cloud Business Application and additionally also checked the CDS Graphical Modeler.
From here on I’ll refer to Business Application Studio as BAS as a shorthand. SAP has provided development tools based on Eclipse for local based development and in the cloud with WebIDE. Each environment is better suited for certain development tasks and/or developer preferences.
Having a cloud based reference environment that is consistent, provides for a broader range of examples and educational material. However, maintaining two branches of tools takes more time and often leads to feature differences. BAS is the latest evolution and is driven at its core with Eclipse Theia framework. Microsoft’s free Visual Studio Code and SAP’s BAS utilize this common framework so we should see quicker feature releases that target both cloud and local environments.
Once your BAS is up, check which version you’re running.
Under the Help->About menu, you can check your version.
If you haven’t already, click on “Open Workspace” and open the default projects folder. BAS will reload itself and position the Explorer pane in the Projects context.
The files you see will only be the ones located in projects and if you create anther workspace your file Explorer plane will only show those files. It’s important to realize that there are more files in the filesystem that’s provided by the Dev Space than you’re likely seeing.
Go to the menu item Terminal -> New Terminal. This will open up a terminal at the bottom of the window.
You current location will be the projects directory. If you’re used to working with linux based shells, you should be right at home. You’re looking at a standard Bash shell interface. If you’re a windows user, think cmd or power shell. I’m not going to get into details but if you’re a windows user don’t let the direction of the slash confuse you.
You can do all the bash things you might expect. Try commands like pwd, ls, head or run a program like top(you can only see your user’s processes). Notice that your pwd is /home/user/projects. If you go up a folder you should start seeing more things.
Things are getting clearer now. We see our projects folder and a couple of others. I wonder if I can put anything in tmp? Looks like I have my own copy of NodeJS modules, etc. Let’s go up again to the root of the filesystem.
Hmm, this looks like a full linux style filesystem…and it is. I wonder what other assumptions we can make about things?
First you’ll need to understand that as a normal user(called user) you don’t have root privileges. If you do “ls -l” you’ll start seeing that you’re pretty much confined to creating files in the home directory(and /tmp as well) but you can still look around at most things.
Let’s look at the contents of /etc/issue. This file usually contains some info about the particular distribution being used.
Looks the Dev Space is based on Debian Linux 10. That’s good to know because it tells us what binary format is likely to work well in this environment.
The next thing you should be wondering is “I wonder what files will be preserved across Dev Space stops/starts?”. The best way to determine this is by creating some files where you and just try it. I’d suggest doing this to convince yourself that your work won’t get lost the first time your Dev Space gets stopped(which it will if you leave it idle overnight).
I’ll give you a hint and that is that most of the system things are built up during startup but things in your /home/user folder will be preserved. This include hidden files like .bashrc.
What’s missing? :
If you start trying commands you already know you’ll quickly find that some of your favorite linux things may be missing.
The vim and pico editors are there, but tree and jq are not.
Build vs. (apt)Get :
No problem you say. I’ll just get the source code and build it myself.
I see make and ldd, but gcc is missing. That’s going to be a problem…
In fact since we know this is a Debian based system and Debian uses apt-get to install the build toolchain and be off to the races! Best make sure the apt repos are fresh.
Denied!? Oh yeah, I forgot, we’re not root and the apt package utility is trying to put files where I don’t have permissions.
Two Ways :
Well we could set up a Debian 10 system and use apt-get to install things there and then painstakingly transfer them into our Dev Space and put them into the right places. This is in fact what I’ve done in a Docker container on my local system. I won’t go into the details here but leave that to a later blog post.
Even if we do that, we can’t put the binaries and libraries in the standard places /usr/bin etc. since we can’t write files there. However, we can put files under /home/user and change the PATH so that it finds ours first! This is the trick that enables the following approach.
I’m NotRoot :
After thinking on this issue for a while and considering things like chroot environments to get around the issue, I found the following script and forked the project for my needs. Credit to the original author Gregwar Grégoire Passault.
Start by cloning my fork of the project.
cd /home/user git clone https://github.com/andrewlunde/notroot.git cd notroot
Follow the README.md file on the repo for any changes in the instructions.
cd /home/user/notroot cat add2bashrc.txt >> ~/.bashrc
This will modify your .bashrc file which is read upon every shell startup. Exit and restart a new terminal.
What this script is doing is allowing you to use the apt package manager tools to search for and install apt packages into your user space and alters the environment so that your versions are found first. Continue to grab the latest repos.
cd /home/user/notroot ./prepapt
OK, a lot just happened. First it did an apt-get update to fetch the latest package definitions.
Then it installed a few things that allow for installation of packages and all their dependencies.
Finally it installed the jq tool as a test. You should see the following at the end of all that output.
We see that it actually ended up installing 3 things, libonig5, libjq1, and jq itself.
Now we can run jq just like anything else that’s installed.
Instead of using “apt-get install”, you use “notroot install”. Go ahead and install some other things.
notroot install tree notroot install htop
Now we can use htop to see how our resources are being used.
Hit the “q” key to quit and return to the terminal.
You can use the “notroot search” command to effectively do an “apt-cache search”. It tends to return a lot of matches so it’s handy to grep the results. An example would be to find the build tools meta-package.
notroot search build | grep essential
Doing this plus whatever -dev packages is usually enough to get to a point where you can build most things from source. You’ll have to google around to find the names of the packages for your needs. Just remember you’re looking for .deb packages.
Just the Start :
In my next blog post I’ll expand on this and show you how to add pre-built extensions that are compatible with BAS.
Let me know if you have and questions or issues by leaving me a question below or better yet, asking it on the SAP community.
|Partners: If you have a question, click here to ask it in the SAP Community . Be sure to tag it with Partnership and leave your company name in the question so that we can better assist you.|