Conditional compilation using cloud compiler?

I need to develop a work around for this issue:

Am thinking if I could conditionally compile certain source files I may get over issues with the compiler not handling the workload (it seems).

There’s nothing stopping you from compiling locally…

I created po to do just that and have been maintaining it for over two years.

You can install it with:

bash <(curl -sL get.po-util.com)

You can check out the repository on GitHub here.

3 Likes

What exactly do you intend to conditionally compile?

If you mean compiler directives like #if .... #endif to conditionally include/exclude code blocks, it’s all there.

@ScruffR, by conditional compile I mean like in a make file - eg for product type A compile a.cpp, b.cpp, c.cpp for product type B compile b.cpp, c.cpp.

Am just trying to get around the Server Error issue I am getting which looks to be due to the amount of source code I have.

PS - I tried putting conditionals around whole file source code so as to exclude that code as a work around to the issue did not help, eg

#undef XXX
#ifdef XXX
// code to exclude
#endif

@nrobinson2000, I have been avoiding local compile install as it is just one more thing to maintain… but I may be “forced” into it. If so, will take up po-util for sure!

I see.
One way to work around these things may be “virtual” project directories per product.
You keep your related “physical” files in a real “master” project directory and have some “secondary/virtual” product specific projet directory that just contains links to the relevant files.
When compiling from the “virtual” project directories CLI will only see the relevant files.

Nevertheless, a feature request to add some way to include/exclude files in the project.properties on the basis of target platform and/or a specific command line switch may be worth a try - since Particle is currently in the process of reworking their whole IDE world, this might be a good time to file ome
CLI specific feature requests
general cloud related requests

Another option is to build your application as if it were a library.

examples/
    productTypeA/
        productTypeA.ino
    productTypeB/
        productTypeB.ino
        otherFiles.cpp
src/
    common.cpp
    common.h
    moreCommon.cpp
    moreCommon.h
library.properties

From the Particle CLI, you position yourself at the top level, in the directory with library.properties, and then you can build:

particle compile photon examples/productA/ --saveTo firmware.bin

When you have a library.properties file, it will then build using the files in productA, as well as all of the files in the src directory, completely ignoring the things in the other examples directories like productB.

Not ideal, but it can be a useful trick.

1 Like

@ScruffR,

Good idea! Done. Raised github issue - https://github.com/particle-iot/particle-cli/issues/410

@rickkas7,

Neat trick! But as you say, not ideal. Am using the one .ino file and set up a whole lot of #defines and #ifdef’s within it to allow one to readily select the product you want to build.

I only want to leave out specific files because of the source code size issue that I am currently suffering with.

Am wondering if there are compiler options available from the CLI which we could use?

Currently not, since there are no other switches passed from CLI to the build farm than platform and system target.

Have you considered my suggestion about sym-links?

@ScruffR, I did consider the sym links, and I can see that it would work, but it would be quite awkward in my situation.

I develop in two places: at work (Windows 7) and at home (Macbook). There are at least 10 product variations and development is constantly on the go.

My current work around is to simply move a few unused source code files (say for Product B) to somewhere else whilst I build Product A.