Compiler: Do not attempt to compile pbi file

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Compiler: Do not attempt to compile pbi file

Post by IdeasVacuum »

I would like to have a Compiler Option whereby Compile/Run and Syntax Check only work if the current file is a .pb. Many a time I have accidently started compile/Run in a pbi file where compile will fail because the pbi is dependent on the master pb file - with large files, the failure takes too long to arise.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Compiler: Do not attempt to compile pbi file

Post by ts-soft »

You can set the: Main source file
in the Compiler Options!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
ElementE
Enthusiast
Enthusiast
Posts: 139
Joined: Sun Feb 22, 2015 2:33 am

Re: Compiler: Do not attempt to compile pbi file

Post by ElementE »

Hi IdeasVacuum,
Perhaps defining a constant in the main program that the pbi depends upon to compile?

Code: Select all

; File: "Test.pb"
#Main_Defined = 1
IncludeFile "test.pbi"
Debug "main program"

Code: Select all

; File: "Test.pbi"
CompilerIf #Main_Defined
  Debug "Main Defined"
  Debug "All is OK" 
CompilerEndIf
This prevents the pbi file from being compiled by itself.
Last edited by ElementE on Tue Oct 27, 2015 9:03 pm, edited 1 time in total.
Think Unicode!
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: Compiler: Do not attempt to compile pbi file

Post by GPI »

simpler:

Code: Select all

compilerif #pb_compiler_ismainfile
compilererror "this is a PBI!"
compilerendif
should prevent that you could compile the pbi.
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Compiler: Do not attempt to compile pbi file

Post by skywalk »

I design my pbi's to allow each to be tested independently of the main project. Of course, some pbi's require XIncludeFile's of others to function, but that is normal and mitigated with #CompilerIf's as ElementE shows.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: Compiler: Do not attempt to compile pbi file

Post by ozzie »

Have you set up a PB Project? If you do that, and add your .pb file and all the .pbi files to the project (under Project Options), and set the 'Input source file' as mentioned by ts-soft, then it doesn't matter which file has focus when you compile.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Compiler: Do not attempt to compile pbi file

Post by IdeasVacuum »

Thanks for all the suggestions!
Main source file in the Compiler Options!
I often have more than one main source file in the IDE when I'm using them as on-the-fly-editied utilities to support other code or produce data for external apps such as a CAD program, so defining one Main in Compiler Options does not help.
Have you set up a PB Project?
Again, for this type of use, PB Projects are just too onerous to maintain.
Perhaps defining a constant in the main program that the pbi depends upon to compile?
There almost always is, and the Compiler takes a month of Sundays to decide that the .pbi won't compile because of that, as per my original post.
compilerif #pb_compiler_ismainfile
compilererror "This is a pbi!"
compilerendif
This works. Yet even at the top of a large file, the Compiler takes too long to halt and pop up the message.

At the end of the day, I feel that my request holds good - a simple check box in Compiler Options so that compile does not start if the file is a .pbi, just posts a message in the error log.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply