Author Topic: CodeBlocks being called from hudson (on linux)  (Read 20230 times)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5193
CodeBlocks being called from hudson (on linux)
« on: December 28, 2010, 11:22:25 pm »
Has anyone setup a job in hudson which should call CB ?

I have done it in the past on windows (well actually a self made executable was actually calling CB), I am trying something similar in linux, but now the hudson job immediately calls CB.

The hudson job executes :
Code: [Select]
/usr/local/bin/codeblocks --no-splash-screen --rebuild --target=Debug Arrays/Arrays.cbp

Note : hudson installation created a special hudson user to run the "hudson application (java war)".

However it fails, gtk issue :
Code: [Select]
Error: Unable to initialize gtk, is DISPLAY set properly?
Finished: FAILURE

This would be a typical error when it would be run as root, but how come this  special user also has these issues. Anyone any experience in this area ?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12122
    • Travis build status
Re: CodeBlocks being called from hudson (on linux)
« Reply #1 on: December 28, 2010, 11:38:18 pm »
Do you have a running X?
Do you start hudson from gui terminal or from cronjob, or hudson is even a daemon?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: CodeBlocks being called from hudson (on linux)
« Reply #2 on: December 29, 2010, 09:24:52 am »
If hudson user seems to be allowed to start programs in your x-server, but it can not use it.
If you run xhost + before it. should work. It allows other users to use your X display.

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: CodeBlocks being called from hudson (on linux)
« Reply #3 on: December 29, 2010, 09:31:37 am »
If hudson user seems to be allowed to start programs in your x-server, but it can not use it.
If you run xhost + before it. should work. It allows other users to use your X display.
Better would be to just allow the hudson user access to your X displyay, because xhost + allows it for each and any user.
It should be doable with an Xaccess-file, but I have no time to look for it at the moment.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5193
Re: CodeBlocks being called from hudson (on linux)
« Reply #4 on: December 29, 2010, 09:44:06 am »
I just tried the suggestions (thanks),  but no luck.

First : hudson is start by a startup script in /etc/init.d/
Started by the user 'hudson', which I verified by doing a 'ps'.

I tried to : xhost + hudson ==> xhost:  bad hostname "hudson"

Then I tried : xhost +  ==> access control disabled, clients can connect from any host
Restarted hudson, but the problem persists.
When I go into YAST (Suse linux), user and groups, no sign of user hudson in there.

I am bumping into my linux knowledge limits :-(

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: CodeBlocks being called from hudson (on linux)
« Reply #5 on: December 29, 2010, 10:47:39 am »
You can try to export your display before running C::B.
It's most likely :0.0, export DISPLAY=:0.0 should work, if it is done immediately befor running C::B (and if it' the correct display of course).

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: CodeBlocks being called from hudson (on linux)
« Reply #6 on: December 29, 2010, 11:24:50 am »
Or make hudson start a new X on a specified display, set the DISPLAY variable and start C::B.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5193
Re: CodeBlocks being called from hudson (on linux)
« Reply #7 on: December 29, 2010, 02:39:37 pm »
oh boy, I am staring to feel a real linux newbie ;-)

Followed your suggestion, no luck (yet) :

Code: [Select]
+ export DISPLAY=:0.0
+ DISPLAY=:0.0
+ /usr/local/bin/codeblocks --no-check-associations --no-dde --no-splash-screen --rebuild --target=Debug Arrays/Arrays.cbp
No protocol specified
Error: Unable to initialize gtk, is DISPLAY set properly?

When I do in a shell (during my regular login ) :
Code: [Select]
[email protected]:~/CodeBlocks/trunk> echo $DISPLAY
:0
so I also tried "export DISPLAY=:0", same result, no luck.

Quote
Or make hudson start a new X on a specified display, set the DISPLAY variable and start C::B.
No clue on how to do that (I know something like startx exists, but ...)

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: CodeBlocks being called from hudson (on linux)
« Reply #8 on: December 29, 2010, 11:47:48 pm »
So, now I'm back home:
the following script works for me from a real console:
Code: [Select]
#!/bin/sh
cd /home/jens/codeblocks-build/codeblocks.trunk/src
xinit -e "export LC_ALL=en_US.UTF-8; codeblocks --build CodeBlocks-unix.cbp; codeblocks --build ContribPlugins-unix.workspace ;./update" -- :101

it changes in my C::B test directory and starts an xserver via xinit.
xinit calls xterm with the arguments before "--" and start an xserver on display 101 (should not be used normaly).
I build the whole C::B in an english environment and run the update-script.

xinit might behave different on other distros, if it does not work you should read the man-page.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5193
Re: CodeBlocks being called from hudson (on linux)
« Reply #9 on: December 30, 2010, 12:00:27 am »
that did start a CB, but strange stuff, both my monitors turned black, in the upper left corner you could see the CB starting and the plugins loading (as you would get when starting CB in shell), then again in the upper left part CB became visible (like a very first start if CB) and saying it detected the compiler. But no project was building ...

Tried it a second time, same thing. Seems this is not yet the solution.


EDIT : I called the same thing in a regular shell, just for testing purposes :
Code: [Select]
xinit -e '/usr/local/bin/codeblocks --no-check-associations --no-dde --no-splash-screen --rebuild --target=Debug Arrays/Arrays.cbp' -- :101
The screens turning black, and then CB visible (no compiler detected window here).
« Last Edit: December 30, 2010, 12:03:11 am by killerbot »

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: CodeBlocks being called from hudson (on linux)
« Reply #10 on: December 30, 2010, 12:20:06 am »
that did start a CB, but strange stuff, both my monitors turned black, in the upper left corner you could see the CB starting and the plugins loading (as you would get when starting CB in shell), then again in the upper left part CB became visible (like a very first start if CB) and saying it detected the compiler. But no project was building ...

Tried it a second time, same thing. Seems this is not yet the solution.


EDIT : I called the same thing in a regular shell, just for testing purposes :
Code: [Select]
xinit -e '/usr/local/bin/codeblocks --no-check-associations --no-dde --no-splash-screen --rebuild --target=Debug Arrays/Arrays.cbp' -- :101
The screens turning black, and then CB visible (no compiler detected window here).
Remove --no-check-associations and --no-dde (or use --no-ipc for the second), because they are windows arguments and seem to break the batch-build.
I think it should build anyways, but at the begin of the log messages you have "unknown long-option ...", so it might be a wxWidgets problem.

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: CodeBlocks being called from hudson (on linux)
« Reply #11 on: December 30, 2010, 12:53:55 am »
By the way: the monitors turn black, because a new xserver is started and xinit switched to it.
If you don't want that, you can run an alternative xserver like Xvnc to run xterm in.

Code: [Select]
xinit -e '/usr/local/bin/codeblocks --rebuild --target=Debug Arrays/Arrays.cbp' -- /Usr/bin/Xvnc :101
In all cases you have to switch to the correct directory before running the command ,of course (or use full path).

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5193
Re: CodeBlocks being called from hudson (on linux)
« Reply #12 on: December 30, 2010, 08:54:29 am »
Thanks, we are getting somewhere

1) when launching the xinit/Xvnc from the shell : works and no black screens (minor issue could be I don't see the build window, but it might be good not to show that, however when something terribly might go wrong and CB pops up a message box,that message box will not be visible I guess, and such can not be clicked)

2) when hudson will issue this command, it is not succeeding, since it is showing that compiler detected dialog box, which need to be clicked, and as such the build never finishes.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5193
Re: CodeBlocks being called from hudson (on linux)
« Reply #13 on: December 30, 2010, 09:18:03 am »
A little recap :

CB is a strong IDE, but it is also a strong build tool (focusing now on command line usage) :
- feed it a workspace, and it can build all projects
- feed it a project, and it can build *all* targets [ONLY if there is a virtual target bundling all the targets] [IDEA : I think when no target is specified all targets should be build] Any comments ???????
- It can run post build things, either by ,anual commands or by launching several plug-ins (for example run a CppCheck)

As such it can be a good replacement for make files, especially towards continuous integration. Where continuous integration would be configured by a shell script to launch the correct makefiles, it now could be configured to call CB.

I have done long time ago such things on windows, where the CI hudson was calling a 'driver program' which in turn called CB (that driver program created for example the correct config spec for clearcase depending on certain criteria), but forget about windows, time to focus on linux.

There are 2 ways of running hudson :

1) under your regular user account during your regular sessions, you fire up a shell and start the hudson.war manually [java -jar hudson.war]. Hudson will store all it stuff in '.hudson' directory in your home directory
GOOD :
 - no issues as described above in the previous replies, there's an xserver, the build window is even visible
BAD :
 - it is not automatically started, after each login you need to open up your shell and reissue the command to fire up the hudson.war
Question : I guess this can be automated (how exactly ?)

2) install a package for your distribution, this will also activate a startup script (for me : OpenSuse ->/etc/init.d/hudson, with a config file /etc/sysconfig/hudson), the hudson stuff now ends up somewhere under /var/lib/hudson and /varr/log/hudson) and it is being launched by the startup script as the user 'hudson' which is a member of the group 'hudson'
GOOD :
 - automatically launched
 - dedicated user for this
 - no need to log in with a certain user account
 - really a server/service
BAD :
 - those gtk issues / xserver issues pop up as described in the previous replies :-(

I tried in the configuration to say the hudson daemon should be run by my account (HUDSON_USER="killerbot") but that didn't help, the issues remain.

So the closet was thet xinit/Xvnc thing but that also fails now due to the compiler detected dialog box invisibly waiting to be clicked ...

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: CodeBlocks being called from hudson (on linux)
« Reply #14 on: December 30, 2010, 10:03:57 am »
The compiler detection dialog only pops up once, if hudson could save the default.conf, but I guess it has no home-directory and so no default place (that is writable) to store it.
A workaround is to copy a working default.conf (or any other *.conf for C::B) to the location where your executable is (for example as hudson_cb.conf) and start C::B normally, or in second case with the personality you use as parameter.
If it is started from a virtual terminal (running under your X), you can also use Xephyr (if installed) as xserver. It needs xhost + to be set before. So the new xserver is started in a nested window on your desktop.