Track source code variations

Soon, I started supporting a line of products containing variants of the same firmware. Since I have been playing with git for one year and really appreciate it, I will most likely use it for version control.

There are several options that I can see to support firmware options, but I don't like anything. What are the best practices that you apply for your own work?

Alternatives I can think of:

  • defines . Preliminary processing. Pros: everything is always present in the source code, it is more difficult to skip updating one of the products. Cons: harder to read. This may be normal, while we have only two options, when it will be four or more, it will be a pain. Also, it seems harder to apply the DRY principle (don't repeat yourself).

  • one branch for each product variant . When changes that apply to all products are included, that change should be combined with other products. Cons: if the fixation contains both changes for all products and changes for a specific option, problems will arise. Of course, you can make sure that the commit contains only one type of change: changes to this product or changes to entire families. But try to get it on the team? Plus, then the merger would not work, instead we should be cherry. Correctly?

  • A primary repository as a submodule . Make all the files containing the main functions a repository of their own. All products contain a version of the main repository as a submodule. Cons: I do not see that in the end there will be no options for the main submodule. Then we have problems again, and again we will use definitions or something bad. The repository core with branches? Then we return to the previous alternative: the change that applies to all branches must be merged, but the merge also includes product-specific elements.

  • . , , , ,... : . , ! , , , -. : , ( ). . - - ? - , . - . , git.

? ?

, .

+5
6

#define. .

#define , .

+5

, , . (Makefile - ) , , .

, , , . , #ifdef, #elif, #endif ..

, , ( ). , ( , , ). , , .

, .

+6

, " ", Scintilla - . , ( Windows/GTK +/Mac, VMS, Fox ..).

- , : , .
, (, Java).

OO: (, ..) ( ) , .
make .

+5

, , .

, , . , . - ; , . , , 100 , , . 100, 300, 500 900 , , , .

; , , ( , !). , , , . , . ( ) , , , :

#include "config.h"
#if defined(USE_VARIANT_A)
#include "variant_a.c"
#elif defined(USE_VARIANT_B)
#include "variant_b.c"
#else
#include "basecase.c"
#endif
+2

!

, . , . .

.

#define, , :

#else 
    #error You MUST specify a variant!
#endif

, .

+1

. , (, Mono vs. Visual studio. , , , / Git., , / . , . , ? -?

, , , , , , / , . OO , .

, , - / git . , , , , , , . , , . ( ?).

0
source

All Articles