Deterministic scripted generation of schematic PDFs and Gerbers

For the convenience of users browsing my projects on GitHub or similar, I commit not just the *.kicad_* files, but also a PDF of the schematic, the Gerbers and drill files, and a ZIP file for upload of the necessary subset of the Gerbers and Drill files to JLCPCB. (This avoids having to install KiCad, clone the repo, and start up KiCad on the files if all you want to do is glance through the schematic or upload to JLCPCB or whatever.)

Obviously it’s nice to have an automated tool for this so that you can just run a command-line program to update all the generated files in your repo, rather than doing a bunch of manual work in KiCad followed by zipping up various files and whatnot. A while back I wrote such a script (using kicad-cli and zip), but the problem with it was that even if there were no changes at all, it would change more than a dozen files per project (the schematic PDF, all the Gerbers and the JLCPCB ZIP file), causing new commits to have a lot of unnecessary and irrelevant changes. The source of all this was simply changes to the creation date of the files.

I’ve since tweaked my script to handle this: it does the same generation but updates the working copy of a generated file only if something other than the creation date has changed. (This is what’s often called a reproducible build.)

I don’t know if this is of interest to anybody else, but in case you want something like this you can find my render script here. It uses git diff --no-index with --ignore-matching-lines to see if something other than creation dates have changed, and strip-nondeterminism to avoid changing creation/modification dates in ZIP files.

If the general idea appeals to you but the script itself is missing something you need, I’m happy to collaborate on fixing and generalising things, and turning it into more of a product immediately usable by others.

It may also be worth mentioning that my method of generating the ZIP file for JLCPCB differs from what the various plugins for this do. I simply pack up a subset of the standard Gerber and drill files that KiCad generates, with no changes or renames, and this seems to work just fine (I’ve run three or four boards through JLPCB using this, and they came out with only with the errors I’d put into the original source files. :-P)

1 Like