Author Topic: Command line build and environment variables  (Read 10890 times)

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Command line build and environment variables
« on: March 05, 2012, 11:30:39 am »
I am using Nightly Build 7789 on WinXP at the moment

I have a C::B workspace with a few projects that builds nicely in the IDE. I would like to also be able to build from the command line. I am trying this:

$\> codeblocks.exe --rebuild --target=W32_Release --no-batch-window-close MyApp.workspace

It starts out ok by cleaning the projects (since I requested rebuild), but it later fails because of missing include directories. More specifically, it fails to resolve this search directory specification in one of the projects

$(CPDE_USR)\include

where CPDE_USR is an environment variable I have defined inside Code::Blocks using
Settings -> Environment -> Environment Variables

These variables are defined under the 'deafult' envvar set

How can I get C::B to use the definition of such environment variables when building from command line?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Command line build and environment variables
« Reply #1 on: March 05, 2012, 11:42:21 am »
How can I get C::B to use the definition of such environment variables when building from command line?
First of all, make sure the plugin is actually active in batch build. Usually it is not.

Alternatively (if it shall really be an envvar), make it present in the shell you are executing C::B from, by setting it.

Alternatively (if you don't know) instead of using the envvars plugin you can safely also use the "custom variables" tab of the build settings of you project. In your case as you use an envvar for a path, this makes more sense IMHO, because you don't need to depend on the envvars plugin (sure you can, if you wish).
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Command line build and environment variables
« Reply #2 on: March 05, 2012, 12:46:56 pm »
Thank you, that answered my question

For the record, I now used
Settings -> Compiler and debugger -> Batch build
... and checked "Environment Variables" under 'plugins to load in batch-build mode'

Now it seems to build ok.

I was aware of the option to define the variable in the shell, but as a policy I want to keep the definition in once place, within Code::Blocks.

I see your point about "custom variables", but some of these definitions are shared between many projects and are also different on different machines. I could perhaps use global variables, but somehow I settled on the envirinment variables.

Follow up question1: I have tried to suppress the "Batch build" dialog that pops up (it is useful sometimes), but it seems to come always. Shouldn't --log-to-file suppress it and send the same output to file? I can't get it to work.

Follow up question 2: When I specify the workspace file, will all projects be built or just the one which is marked as 'active' ?

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Command line build and environment variables
« Reply #3 on: March 06, 2012, 11:42:23 pm »
Follow up question1: I have tried to suppress the "Batch build" dialog that pops up (it is useful sometimes), but it seems to come always. Shouldn't --log-to-file suppress it and send the same output to file? I can't get it to work.

Follow up question 2: When I specify the workspace file, will all projects be built or just the one which is marked as 'active' ?

I have looked at http://wiki.codeblocks.org/index.php?title=Code::Blocks_command_line_arguments
and experimented with the parameters. Apparently, there is no way to suppress the batch build dialog as far as I can tell. I think that means you cannot run batch buld from e.g. a crontab job undel linux, perhaps the same is true for scheduled tasks under Windows.

I have reproduced similar command line parameters from 2 other IDEs I have used, for comparison of possible missing command line parameters to C::B. It seems to me one omission in C::B is the ability to specify which workspace project should be built (or whole workspace). It is possible to specify a *.cbp instead of *.workspace files, but then it seems dependent projects are not built.

Quote from: MS Visual Studio 6.0
Usage:
  MSDEV [myprj.dsp|mywksp.dsw]  - load project/workspace
        [<filename>]            - load source file
        /?                      - display usage information
        /EX <macroname>         - execute a VBScript macro
        /OUT <filename>         - redirect command line output to a file
        /USEENV                 - ignore tools.options.directories settings
        /MAKE [<target>] [...]  - build specified target(s)
              [<project> - <platform> <configname>]
              [[<project>|ALL] - [DEBUG|RELEASE|ALL]]
              /CLEAN            - delete intermediate files but don't build
              /REBUILD          - clean and build
              /NORECURSE        - don't build dependent projects



Quote from: MS Visual Studio 2008 Express
Command line builds:
devenv solutionfile.sln /build [ solutionconfig ] [ /project projectnameorfile [ /projectconfig name ] ]
Available command line switches:

/Log   Logs IDE activity to the specified file for troubleshooting.
/ResetSettings   Restores the IDE's default settings, optionally resets to
   the specified VSSettings file.
/SafeMode   Launches the IDE in safe mode loading minimal windows.


Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Command line build and environment variables
« Reply #4 on: March 07, 2012, 12:40:04 am »
run codeblocks --help from a console to see the possible parameters.
You can specify a target with --target= .

The normal C::B does not work without a running xserver, but there is an experimental branch I started about a year (or so) ago, that is able to create a pure console-version of C::B.
It does not load any plugins, but the compiler-plugin, because all the plugins need an xserver (at the moment).

you can check out the sources via
Code
svn checkout https://svn.berlios.de/svnroot/repos/codeblocks/branches/codeblocks_console [path_to_local_repo]
and then build the console-app-target, call src/update_con and run the app via output/run_con.sh .

output/run_con.sh --help shows the available parameters. You can copy the output folder to any place you want and run C::B for console through the run_con.sh-script.

The sources do not reflect the actual trunk, but should work.

I don't remember at the moment, whether variable expansion and global variables work or not, so you have to try it yourself.

If I find the time, I continue working on the branch.

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Command line build and environment variables
« Reply #5 on: March 07, 2012, 02:38:08 pm »
run codeblocks --help from a console to see the possible parameters.

I know that. I have used that plus the link referred to above. But as it does not answer the questions I have, I ask here.

Quote from: jens
You can specify a target with --target= .

I know that as well. As you can see from my original post, I have been using that option all along.

Unless I am totally mistaken, in Code::Blocks, the --target option refers to a build target which is typically Debug, Release or something like that. I am already using that option, and it is working as expected. What I am missing is something else, a --project option that would allow me to say "Build that project and the projects it depends on" when referring to a workspace as the filename parameter. As far as I can tell, that is not possible from the command line now, you have to open the C::B IDE GUI to do it.

In the old MSV6 IDE, you could specify the project name on the command line even though a workspace (*.dsw) file was specified (see the /MAKE <project> option). This was quite useful, and a --project=<project_name> option in C::B would serve the same purpose I believe.

Quote from: jens
The normal C::B does not work without a running xserver, but there is an experimental branch I started about a year (or so) ago, that is able to create a pure console-version of C::B.
It does not load any plugins, but the compiler-plugin, because all the plugins need an xserver (at the moment).

If I find the time, I continue working on the branch.

Ok, thank you for the information. My build environment does not allow me to build C::B from source (I use the MS compiler on Windows), plus I need the environment variables plugin to work.

So I will simply say that it would be cool if command line build without GUI became part of trunk. The reason for bringing this up in the first place, in addition to needing such features myself, is actually trying to convince a colleague that Code::Blocks does what he needs. But so far he comes back at me pointing at tools like http://maven.apache.org/ . With a little extra on the command line features in C::B it would be enough to end such debates.

In any case, Code::Blocks is a great tool! Thanks for all your hard work....
« Last Edit: March 07, 2012, 02:40:06 pm by cacb »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Command line build and environment variables
« Reply #6 on: March 07, 2012, 03:03:52 pm »
As far as I can tell, that is not possible from the command line now, you have to open the C::B IDE GUI to do it.
That is wrong. The command line parameters work with workspaces just fine.

BTW: You may want to setup "virtual targets" to bundle the targets across projects within a workspace you want to build in batch mode. This allows you to build "sub-parts" of projects in a WS as desired.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Command line build and environment variables
« Reply #7 on: March 07, 2012, 09:57:43 pm »
As far as I can tell, that is not possible from the command line now, you have to open the C::B IDE GUI to do it.
That is wrong. The command line parameters work with workspaces just fine.

BTW: You may want to setup "virtual targets" to bundle the targets across projects within a workspace you want to build in batch mode. This allows you to build "sub-parts" of projects in a WS as desired.

It seems I am not getting through with my message, but nevermind, I'll leave it there. Thanks for reading anyway.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Command line build and environment variables
« Reply #8 on: March 07, 2012, 10:04:19 pm »
It seems I am not getting through with my message, but nevermind, I'll leave it there. Thanks for reading anyway.
I'd say it seems you don't understand. Have a look at the build batch file for Code::Blocks in SVN. There we do what you want to do. I told you how, but it seems I am not getting through.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ