New answers tagged

1

I think you may be asking the wrong question. Good practice or bad practice for a Dockerfile, because they have so many different applications, depends on what exactly you do with them. However, if your real question is: How should I deal with this potential for breakage? The answer is, only build your docker image once, as the very first step of your ...


1

Either the file is editable or it is generated. If you really want it to be both, you're going to have a bad time no matter what method you choose. Preventing the edition of generated files is straightforward: re-generate the file as a compilation step. Make, CMake and so on are the tools of choice for this. The file of course needs to be excluded from ...


0

Do you use continuous integration? If not, why not? As an alternative, read the S.O question running a bash script from a make file. The point is that the header file should be generated ("Just In Time") by the build process (whether Jenkins, etc or make), thus overwriting any manual changes. [Update] if it's a one man project, as you say in a comment, ...


40

Don't commit the generated C header file at all. In fact, delete the current file (thanks @user1936), change the script to call the header file .g.h (thanks @davidbak), and add it to .gitignore, so it doesn't get committed accidentally (thanks @cmaster). Instead, commit the csv and python script, and add some custom step to generate the C header file at ...


6

I've worked in a bunch of codebases with large quantities of auto-generated code. The amount of issues raised by folks modifying these files has been quite low, and usually quick to spot and quick to solve. You've not given enough details about your build setup and what tools you're using. gcc might not have the tools for the job, or it might as @jpa ...


17

First a disclaimer: I don't think this is a good idea. But here is one way to do it anyway: void check_file_time() { if (strcmp(__TIMESTAMP__, "Sun Feb 16 19:38:35 2020") != 0) { asm("do_not_modify_this_file\n"); } } This relies on a few GCC-specific tricks: Non-standard preprocessor macro __TIMESTAMP__ expands to the modification ...


0

Use GNU diffutils or git diff (with GIT...). Use also some good build automation tool (like ninja or at least make), perhaps with ccache. You might have Makefile rules using cmp(1). Run also make -p to understand builtin GNU make rules. You might consider build tools using contents, not modification times, for driving compilation commands. Look into scons ...


94

I think you are approaching this problem from the wrong angle. Better let the generator place a clear and visible comment at the beginning of the C header file like // This file is autogenerated, don't change it manually, // any manual changes will get lost after next regeneration. then make generating the C file from the CSV file part of the build ...


7

Does GCC have any facilities I can use for this kind of thing? Not that I am aware of such feature. But you could do something like generating a MD5 checksum after you generated the header file and put that into a different file (e.g. header_name.md5). Then you could setup a pre-build step to check these by comparison in your build system. As for your ...


Top 50 recent answers are included