Author Topic: Saving everything automatically before every build  (Read 5515 times)

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Saving everything automatically before every build
« on: March 01, 2018, 07:31:32 pm »
I've been using Code::blocks for quite a while and really love it. I am now running 17.12 on Win7 and Linux Kubuntu 17.10.

But I have not found out if there is a feature to save everything before every build. I would like to enable such a feature because I sometimes (too often!) run into issues like this
  • Forgetting to save everything before I check in the project to source control, therefore missing updated files.
  • Losing recently added files in the project or project settings when C::B crashes (it happens!)
So, is there a way to always automatically run the equivalent of "Save Everything" (Shift+Alt+S) just before every build (Ctrl+F9 / F9 / Ctril+F11)? This would work for me.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Saving everything automatically before every build
« Reply #1 on: March 01, 2018, 09:22:44 pm »
this option does not exist and this bothers me since a long time.

There is a ticket on SF with a workaround (basically a squirrel script in every project that makes a save as pre build step). But SF is down right now (for 24h? without update....) so i can not find it...

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Saving everything automatically before every build
« Reply #2 on: March 01, 2018, 10:46:42 pm »
I have a patch applied for some time, but there is a concern that this will force a CC reparse which means there will would be slowdowns.
So I'm reluctant to apply it... If anyone is willing to modify the patch to prevent this reparse, I'll be happy to apply it.
(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 oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Saving everything automatically before every build
« Reply #3 on: March 01, 2018, 10:47:25 pm »
But if you're loosing work because of C::B crashes then it is better to report the crashes, so they could be tracked and fixed.
(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 cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Saving everything automatically before every build
« Reply #4 on: March 01, 2018, 11:01:41 pm »
But if you're loosing work because of C::B crashes then it is better to report the crashes, so they could be tracked and fixed.
Agreed if they are repeatable. But it is not always so.

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Saving everything automatically before every build
« Reply #5 on: March 01, 2018, 11:10:19 pm »
I have a patch applied for some time, but there is a concern that this will force a CC reparse which means there will would be slowdowns.
So I'm reluctant to apply it... If anyone is willing to modify the patch to prevent this reparse, I'll be happy to apply it.

I guess all the source files are already saved when you run a build, so it is mostly the project file and possibly some wxsmith files that are affected. Will saving the project file force a reparse? Even if the answer is yes, I would consider enabling such an option.

[ In my experience reparsing sometimes does not happen often enough, finding definitions does not always work ]

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Saving everything automatically before every build
« Reply #6 on: March 02, 2018, 09:37:41 am »
Agreed if they are repeatable. But it is not always so.
If you are on linux it is pretty easy to always run under debugger. This way if it crashes you can gather the backtrace.
(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 cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Saving everything automatically before every build
« Reply #7 on: March 05, 2018, 09:03:39 am »
Will saving the project file force a reparse?

Any answer?

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Saving everything automatically before every build
« Reply #8 on: September 24, 2019, 10:49:52 am »
I've been using Code::blocks for quite a while and really love it. I am now running 17.12 on Win7 and Linux Kubuntu 17.10.

But I have not found out if there is a feature to save everything before every build. I would like to enable such a feature because I sometimes (too often!) run into issues like this
  • Forgetting to save everything before I check in the project to source control, therefore missing updated files.
  • Losing recently added files in the project or project settings when C::B crashes (it happens!)
So, is there a way to always automatically run the equivalent of "Save Everything" (Shift+Alt+S) just before every build (Ctrl+F9 / F9 / Ctril+F11)? This would work for me.

I would like to bump this question, because it still applies to the way I work, I see this issue several times every day. Note there is (usually) no issue with crashes here, only that I fail to check in the Code::Blocks project (and maybe workspace) file into my git repository, because those files are not saved to disk after successful project build, so git does not detect them as modified. The result is incomplete commits.

I would be happy with any way to enable this (it does not have to be default C::B behaviour). It could be some option I had to enable in the GUI that would e.g. save the project file (.cbp) as a final build step. Alternatively it would also work for me if there was some way I could specify this in the project Post-build step, as indicated in the attachment. 

So the question remains: Can I achieve this in any way using the latest nightly build? (I am on Win10 now and Kubuntu 18.04 using recent nightly builds)

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Saving everything automatically before every build
« Reply #9 on: September 24, 2019, 06:15:39 pm »
here is the relevant ticket:
https://sourceforge.net/p/codeblocks/tickets/396/

there is a small squirrel snippet you can use as pre build step

Preferably i would introduce a option that enables the saving on building...

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Saving everything automatically before every build
« Reply #10 on: September 24, 2019, 09:45:07 pm »
here is the relevant ticket:
https://sourceforge.net/p/codeblocks/tickets/396/

there is a small squirrel snippet you can use as pre build step

Preferably i would introduce a option that enables the saving on building...
Thank you, thank you, I will try the squirrel snippet! I agree there should be a built-in option to do this, the squirrel snippet is a work around, but much better than nothing.

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Saving everything automatically before every build
« Reply #11 on: September 27, 2019, 11:06:42 pm »
I have now tested the squirrel script and it works! It can be enabled by adding it in <ExtraCommands> outside all build targets, so it always happens, regardless of which build target is active:

<ExtraCommands>
    <Add before="[[ GetProjectManager().SaveAllProjects(); ]]" />
</ExtraCommands>


This obviously saves all projects in a workspace, so it does not make sense to add this in every project in a workspace, and it would be cumbersome too. I have several workspaces with quite a few projects, so I found that I can instead create a dummy "Prebuild" project in such workspaces and let it do nothing except run the above squirrel script in its own prebuild step. The other projects can then depend on that Prebuild project. All project files in the workspace are then always saved before every build and the setting for this is in one place.

Still a work-around, but quite a nice one. It fixes the issue with project files not being checked in to source control.