Maintaining Export for Older Versions
Export for Older KiCad Version writes a copy of a design that an earlier
KiCad release can open. include/downgrade_target.h defines the supported
targets. There is one entry per release. Each entry records the file format
versions that release used.
A new feature breaks an export in one of two ways. It can add syntax the older release has never seen. Or it can change what existing syntax means. The second kind is the dangerous one. The file still opens. This page covers what you need to touch when you change a saved format.
Three terms first. In the code this feature is called the downgrade path. That is why the files and functions below are all named that way.
Every saved KiCad file starts with a version line, like (version 20260206).
The number is a date. It says which format wrote the file. Those dates are what
the decisions on this page compare.
The release you are exporting to is called the target.
Start Here
Find the row that matches what you changed. Most format changes only need one or two of these. Skip the rest.
| You changed | Go to |
|---|---|
A node or value in a board or footprint file |
|
A node or value in a schematic or symbol file |
The same two, using |
Something stored once per schematic, like the sheet hierarchy or a variant |
|
A |
|
Custom design rule vocabulary |
|
A |
|
A whole new design file type |
|
Whatever you changed, two steps always apply. Bump the matching
*_DOWNGRADE_COVERED constant once the rest is done, and finish with
Add tests. A new rule that isn’t declared in the oracle tests
will fail the build.
How Compatibility Is Decided
A rule is everything the exporter knows about one feature. One rule covers one feature. It records the format version the feature arrived in, and what an older release should do with it. It also holds the code that finds instances in a design, and the code that changes them.
boardRules() returns the board rules. screenRules() returns the schematic
ones. Each rule is one row in that list:
struct BOARD_RULE
{
int m_introducedIn; // format version that added the feature
DOWNGRADE_BUCKET m_bucket; // keep, approximate, drop or block
wxString m_feature; // name shown in the report
wxString m_detail; // consequence, shown under the name
std::function<int( const BOARD* )> m_count; // how many in this design?
std::function<void( BOARD* )> m_apply; // make them safe to write
std::function<void( FOOTPRINT* )> m_applyFp; // the same, one .kicad_mod
std::function<void( BOARD* )> m_omit; // replace m_apply when the
std::function<void( FOOTPRINT* )> m_omitFp; // user chooses to omit
wxString m_omitDetail; // the report text then
bool m_keepUnderOmitPolicy; // the omit choice must not apply here
};
Only the first six fields are required. Everything from m_applyFp down is
optional, and each one is covered later on this page. A screen row has the same
shape. It carries m_countSymbol, m_applySymbol and m_omitSymbol for a
single .kicad_sym symbol, where a board row has the Fp variants for one
.kicad_mod footprint.
This page uses the word rule for these rows only. A
custom design rule in a .kicad_dru file is a different thing. So is a rule
area on a board. Both appear later under their full names.
The count (m_count) answers how many instances the design holds. That number goes into the compatibility report.
The transform (m_apply) edits the design so the older release can read it.
It runs only after the user approves the export.
Running every count is called classifying. It builds the report and changes
nothing. The dialog classifies first. --dry-run stops there.
A block diagram of a single file export is shown below. The same order applies to a whole project, one design file at a time.
┌────────────────────────┐
│ the design file │ .kicad_pcb, .kicad_sch, .kicad_mod
└───────────┬────────────┘ or .kicad_sym, never modified
│
▼
┌────────────────────────┐
│ flatten variant │ only when the user picks one
└───────────┬────────────┘
│
▼
┌────────────────────────┐
│ classify │──────► the report goes to the user
└───────────┬────────────┘ blocked stops here
│ lossy needs approval
▼
┌────────────────────────┐
│ transform │ edits the copy in memory
└───────────┬────────────┘
│
▼
┌────────────────────────┐
│ the release's writer │──────► a frozen copy of that release's
└───────────┬────────────┘ own writer, writing a temp file
│
▼
┌────────────────────────┐
│ read back and check │──────► version line, then token scan
└───────────┬────────────┘ a failure deletes the temp
│ and refuses the export
▼
┌────────────────────────┐
│ rename over the output │
└────────────────────────┘
A rule runs when the chosen target is older than m_introducedIn. Otherwise it
stays dormant. A BLOCK row leaves m_apply as nullptr. No transform could
make the feature safe.
The count and the transform sit in one row. So the report and the export always describe the same feature.
The row does not make the two agree on which items they match. They are separate functions. The two directions are not equally safe.
Never count something the transform will not change. That direction is the one
that hurts. The report promises a loss, the exported file keeps the feature,
and nothing counts again after the write to notice. The usual way in is a
forgotten m_applyFp, which Write the transforms
covers.
The other direction is fine, and several rules use it on purpose. Reference image opacity counts only the images whose opacity is below 1.0, then clears the opacity on every reference image. Via protection counts the vias that carry protection, then resets the padstack fields on every via. Clearing an already clear field costs nothing, and the count stays precise so the report stays honest.
A worked example
Ellipses make a good one. That single rule touches every part of the struct above. It is also the one to copy when writing your first rule.
KiCad stores an ellipse as a PCB_SHAPE whose shape is ELLIPSE or
ELLIPSE_ARC. Both arrived in board format 20260508. KiCad 10.0’s board
version is 20260206 and 9.0’s is 20241229, so this rule fires for both targets.
Here is the whole row:
{ VER_ELLIPSE, DOWNGRADE_BUCKET::LOWER, _( "Ellipse graphics" ),
_( "Approximated by a polygon." ),
countEllipses, lowerEllipses, lowerEllipsesFp, omitEllipses, omitEllipsesFp,
_( "Ellipse graphics are omitted instead of approximated." ) },
The count walks three places. Board drawings, the graphics inside each
footprint, and the primitives of custom pads. Two ellipses anywhere in there
make a count of two, and the report line reads Ellipse graphics (2).
The transform turns each one into a polygon, at the design’s maximum error. An elliptical arc takes a little more care. A board polygon is always closed, so an open arc becomes a filled polygon of its stroked ink instead of an outline.
The omission path removes the ellipses rather than converting them, and
m_omitDetail is the line the report shows when the user picks that.
Five entries go on the board token list for this one feature. They are
gr_ellipse, gr_ellipse_arc, fp_ellipse, fp_ellipse_arc and
rotation_angle. If a writer ever emitted one of those to an older target, the
scan after the write would refuse the export.
The four results
| Result | Meaning |
|---|---|
Keep ( |
The target already has the feature. No rule runs. |
Approximate ( |
Convert it into something the target reads. Detail or editability is lost. |
Drop ( |
Leave the data out and report the loss. |
Block ( |
Refuse the export. The target can’t represent the design safely. |
The code calls a rule’s result its bucket, hence DOWNGRADE_BUCKET and
m_bucket.
Keep means there is no rule. The rule doesn’t run when the target’s version is at or past the feature’s introduction date. Nothing about that feature reaches the report. So a feature the target already supports needs no work from you.
DOWNGRADE_BUCKET::KEEP exists in the enum, but no code ever reports it. The
Keep section of a report is always empty.
KiCad asks for approval before any export that approximates or drops data. On
the command line that approval is --force. It won’t override a block.
A user can also choose omission over conversion wherever a rule offers both.
The checkbox is Drop features instead of approximating them. On the command
line it is --drop-approximations. This page calls it the omission preference.
Describe the loss for either choice.
Checks outside the rule tables
Some checks live elsewhere.
Fixups that cover the whole board run in ClassifyBoardForDowngrade() and
DowngradeBoardInPlace(). They do three things:
-
reset a PNG plot format the target has no output for
-
resolve property variables in text
-
correct reference image scale, which older releases computed differently
Structure spanning the whole schematic runs in
ClassifySchematicStructureForDowngrade(). The screen rules only see one sheet
at a time. So the whole schematic checks live here. Multiple top level sheets
get blocked. A variant that selects an alternate symbol gets blocked. Bus alias
vectors are handled. Anything stored once per schematic belongs here.
Project settings, custom design rules and library tables each have a path of their own, covered below.
|
A row in So date a new rule against the format of its table, not the format of the file it touches. |
Making the Change
Work out every file that can store the feature first. A pad property appears
on a board and in a .kicad_mod library file. A symbol field appears in a
schematic and in a .kicad_sym. The same change often adds project settings or
design rule vocabulary as well.
The sections below are in the order you want to do them.
Bump the format and the keywords together
A new node or value goes into common/pcb.keywords.
SEXPR_BOARD_FILE_VERSION moves in the same commit.
So what the bump added is whatever you just wrote. The schematic pair is
eeschema/schematic.keywords with SEXPR_SCHEMATIC_FILE_VERSION. Design rule
vocabulary lives in common/drc_rules.keywords.
Look for three kinds of change.
A new node head is the first word inside a parenthesis. Writing
(gr_ellipse …) adds the node head gr_ellipse.
A new bareword value is an unquoted word in the value position. Writing
(via buried …) adds the value buried. A value is never a node head, which
is why the token lists hold the two separately.
A change in what an existing word means is the third kind, and the hardest to find. Nothing new goes into the keyword file, so a diff of that file shows you nothing. Read what the commit did to the writer and the parser instead.
If the bump only writes to the project file there is nothing to do in the rule
tables. Go to common/project/project_file_downgrade.cpp instead.
Four constants record the formats the rules were last reviewed against:
-
BOARD_DOWNGRADE_COVEREDandFOOTPRINT_LIB_DOWNGRADE_COVEREDinpcbnew/downgrade/board_downgrade.cpp -
SCH_DOWNGRADE_COVEREDandSYMLIB_DOWNGRADE_COVEREDineeschema/downgrade/sch_downgrade.cpp
Bump the one that applies last, once the rest of the work is done. Until you do, every export refuses. Debug builds also assert. That is deliberate. An unreviewed format must not reach a file.
You may also arrive here from the other direction, with a format that someone else moved while the rules stayed behind. Every export then reports an "Unreviewed board format" block, and a debug build asserts.
The covered constant tells you where the last review stopped. Run
git log -p common/pcb.keywords and read the commits dated after it. The added
lines are the vocabulary you now have to account for.
Pick a result for each target
Decide what each supported target should do, separately.
Don’t settle this by opening the export in the older release. The file opening proves nothing. A value can read cleanly there and still mean something different.
Copper-thieving zones are an example. A thieving zone holds a pattern of copper, not solid copper. The target reads the zone fine. But refill that zone in the target and the pattern fills solid. The copper has changed and nothing warned anyone. That is why the rule blocks.
Block when the mistake would change copper or connections and nothing would show it.
Write the transforms
Add a VER_ constant and a row in boardRules() or screenRules(). A row
also carries a transform scoped to one library file. That is m_applyFp for a
footprint, and m_applySymbol for a library symbol.
Those two are easy to forget, and nothing reports the mistake. Write
m_apply without m_applyFp and the library path reports a loss that never
happens.
A .kicad_mod holds one footprint and no board, but counting needs a board.
Every count function takes a BOARD*, and there is no footprint version of it.
So DowngradeFootprintFileToTemp() drops the footprint into an empty throwaway
board and runs every rule against it. Your feature gets counted, and the report
lists it.
DowngradeFootprintInPlace() then applies the rules to the footprint on its
own. It can only call m_applyFp. It cannot call m_apply, which needs the
whole board, and by this point the throwaway board is gone.
┌─────────────────────────┐
│ one .kicad_mod file │ no board anywhere
└────────────┬────────────┘
│
▼
┌─────────────────────────┐
│ classify │──────► the footprint goes into a
│ calls m_count │ throwaway BOARD, so every
└────────────┬────────────┘ rule gets to count it
│
▼
┌─────────────────────────┐
│ transform │──────► every rule runs again, but
│ calls m_applyFp │ m_apply is never called
└─────────────────────────┘
The schematic side has no such gap. A screen row carries its own
m_countSymbol, so a library symbol is counted directly and needs no
throwaway container.
If the omission preference applies, add m_omit, or m_omitFp and
m_omitSymbol. Add the m_omitDetail text that describes it. Every LOWER
rule needs an omission transform.
Test that in a debug build. A wxASSERT_MSG fires there if the omission
transform is missing. Release builds compile the assert out. The transform is
then skipped with no error and no report entry.
A user on a release build would then get a report saying the feature was dropped, and an exported file that still contains it. The token scan after the write may catch that. It only catches it if the feature’s token is on the list.
Some approximations have to survive the preference. Dropping them would
change the board electrically, not just visually. Set m_keepUnderOmitPolicy
on those. Skip vias, buried vias and hatched copper fills are the existing
cases.
Rule order matters. A transform that creates new objects has to run before any rule that would process them. Otherwise the new objects go out unprocessed. That is why the live stackup table row sits ahead of the rows for knockout text boxes and rounded rectangles.
Project settings, design rules and library tables
For project settings, update DowngradeProjectFileJson() in
common/project/project_file_downgrade.cpp. If you incremented a schema
version, raise the matching field in PROJECT_SCHEMAS_REVIEWED
(include/project/project_file_downgrade.h) too. That struct holds the highest
reviewed version of six separate schemas. Anything newer blocks the export. See
Schema Version and Migrations
for the upgrade side of the same change.
For custom design rules, start with what you must not touch. The release
vocabularies live in include/drc_rules_release_vocabulary.h.
tools/generate_drc_rules_vocabulary.py generates them from the release tags.
Don’t edit them by hand. They record what the target releases already shipped
reading. A new KiCad feature never changes them. They only change when a new
target release is added.
What a new feature may need instead, both in include/drc_rules_downgrade.h:
-
a row in
DRC_RULE_SEMANTIC_BREAKS, for a function the target parses but answers differently -
a row in
DRC_CONSTRAINT_RENAMES, for a constraint kind the target reads under its former name
Library tables do not go through the frozen writers at all.
legacyLibraryTables() in kicad/project_downgrade.cpp rewrites them by hand,
so a new library table field has to be added there.
It emits (version 7), the table format both older releases read. Quoting is
the awkward part. KiCad 10.0 takes a quoted value literally. KiCad 9.0 runs it
through DSNLEXER, which decodes escape sequences. So the same value has to be
written one way for one target and a different way for the other. A few values
cannot be written for 10.0 at all, and the export is refused.
Check the output
Each target has its own writer under pcbnew/pcb_io/kicad_sexpr/writers/ or
eeschema/sch_io/kicad_sexpr/writers/. Each one is a copy of that release’s
writer, plus guards added for this feature. So it emits the grammar that
release read, and refuses what it knows it cannot write.
You have two jobs here.
First, check that what your transform leaves behind is something the writer can carry. Compare the output against files that release actually saved. The writer might emit newer data. It might drop data your report promised to keep. Either way the fix belongs in your rule or your transform, not in the writer.
Where a mistake in the transform would reach the writer anyway, add a guard so
it throws instead of writing something wrong. PCB_WRITER_V9 does that for
group placement linkage, which its transform is supposed to have cleared.
Second, list your new vocabulary. Node heads go in BOARD_TOKENS or
SCH_TOKENS. Bareword values go in BOARD_VALUES or SCH_VALUES. Give each
one the format version that introduced it.
KiCad then checks the written file for you. It reads the file back, requires the target’s version line, and scans the text for anything on those lists. Any failure throws the file away and refuses the export.
A new token falls into one of three cases.
Usually you just list it, and the scan catches any leak. That is the easy case.
Sometimes the word is legal in one place and illegal in another. group is
like that. KiCad 9 reads (group …) at board level perfectly well, so the
board list can’t ban the word outright. That would refuse every board with a
group in it. The same word nested inside (zone (placement …)) is newer
vocabulary that 9.0 cannot read.
A plain list matches a word wherever it appears, so it can’t tell the two
apart. containsGroupPlacementSource() walks the nesting instead and fires
only on the nested one. It reports the token as placement/group. That is the
only check of its kind in the tree today.
Sometimes the word can’t be told apart at all. The board list has no entry for hatch fill values, since zones emit hatch tokens in every target format. A hatched shape fill leak is invisible to the scan.
The scan never sees meaning either. A change that reuses old syntax passes it untouched. For that case, and for the hatch case above, a behavioural test is the only thing that will catch the problem.
Add tests
Write focused tests in qa/tests/pcbnew/test_board_downgrade.cpp or
qa/tests/eeschema/test_sch_downgrade.cpp. Cover both targets, the report and
the saved result. Compare geometry, connectivity or settings wherever meaning
matters, rather than grepping the output for a token. Cover the omission option
if your rule offers one, and check that a blocked export writes nothing.
Then declare the rule in the oracle coverage list.
checkBoardTransformCoverage() and checkSchematicTransformCoverage()
hold one expectation per rule, in qa/tests/pcbnew/test_downgrade_oracle.cpp
and qa/tests/eeschema/test_sch_downgrade_oracle.cpp.
CheckTransformCoverage() compares the report against that list and checks the
exact row count, so an undeclared rule fails on the count alone.
Your entry needs the feature name, the introduction date, the bucket, and
m_keepUnderOmitPolicy where it applies. Write the date as a literal, since
the list is deliberately independent of the rule table. Then extend the fixture
so it produces the feature, or the oracle reports that nothing exercises it.
Run the suites and the CLI regressions. The Boost executables need
KICAD_RUN_FROM_BUILD_DIR=1 when you start them yourself, which ctest would
otherwise set for you:
cd /path/to/kicad/build
KICAD_RUN_FROM_BUILD_DIR=1 qa/tests/pcbnew/qa_pcbnew \
--run_test=BoardDowngrade,DowngradeOracle
KICAD_RUN_FROM_BUILD_DIR=1 qa/tests/eeschema/qa_eeschema \
--run_test=SchDowngrade,SchDowngradeOracle
KICAD_CLI=/path/to/kicad-cli python3 -m unittest discover -s qa/tests/cli -p test_downgrade.py
The Testing page covers running individual tests. A dry run prints the report without writing anything, which is the quickest way to see whether a rule fires:
kicad-cli project downgrade design.kicad_pro --target 10.0 --dry-run
kicad-cli project downgrade design.kicad_pro --target 9.0 --dry-run
About the reference files
The golden references in qa/data/downgrade/golden/ are native KiCad 9 and 10
saves, apart from the DRC files, which are written by hand. What matters is
that no expected file came from the exporter under test, so never regenerate
one that way. qa/data/downgrade/golden/README.md has the provenance and the comparison
contract.
When Something Fails
| Symptom | Cause |
|---|---|
Debug build asserts "Board format changed", and every export reports an "Unreviewed board format" block |
A format moved past its |
Exporting a project saved by your build reports a "Newer project settings schema" block |
A settings schema version went up without the matching field in
|
An oracle test fails on the report row count |
A new rule has no entry in the oracle coverage list. |
An oracle test reports "Transform fixture no longer exercises feature" |
The fixture no longer produces a feature the coverage list expects. |
A debug build asserts that a |
A |
The export refuses and names a token |
Newer vocabulary reached the output. Fix the rule or the transform that left it there. Do not remove the token from the list. |
The export refuses, naming a file it says it cannot handle |
|
The report counts your feature, but the |
The rule has |
The older release opens the file and the design is wrong |
Meaning changed under unchanged syntax. The token scan can’t see this. Add a behavioural test, and consider whether the rule should block. |
Export Boundaries
Whole project export checks every file it is about to convert before it writes any of them. The destination has to be new or empty. It also has to be outside the source project.
IsDowngradeDesignFile() decides what gets copied. External libraries,
datasheets, gerbers and other unrelated files stay behind. Editor working state
stays behind too. IsDowngradeWorkingArtifact() skips autosaves, .history,
and any *-backups directory.
Each copy then takes its own path.
destination folder
+-- .kicad_pcb ------> rules, writer, version and token check
+-- .kicad_sch ------> rules, writer, version and token check
+-- .kicad_mod ------> rules, writer, version and token check
+-- .kicad_sym ------> rules, writer, version and token check
+-- .kicad_pro ------> DowngradeProjectFileJson()
+-- .kicad_dru ------> FilterDrcRulesForTarget()
+-- sym-lib-table ---> legacyLibraryTables()
+-- fp-lib-table ----> legacyLibraryTables()
+-- .kicad_wks ------> copied unchanged
firstTooNewFile() then rechecks the four s-expression design files across the
whole copy.
Variants add a step. A target whose schematic format predates 20250922 cannot
store variants at all. The dialog then offers to flatten one into the export,
and FlattenBoardVariant() and FlattenSchematicVariant() bake its overrides
into the base attributes. That is refused for a symbol which appears on more
than one sheet instance with different values in each. The base attributes have
nowhere to record the difference.
The compatibility report describes what the older format can carry, and no more. After accepting a loss, open the result in the target release. Check its DRC results and any zone refill before sending it anywhere.
Source Code Guide
Most of the work happens in pcbnew/downgrade/board_downgrade.cpp and
eeschema/downgrade/sch_downgrade.cpp.
| Source | Purpose |
|---|---|
|
Supported releases and the file format versions each one used. |
|
The four results, and the report they are collected into. |
|
Board and footprint rules, transforms and token lists. |
|
Schematic and symbol rules, transforms and token lists. |
|
One writer per target release, copied from that release, plus guards added for this feature. |
|
Design file selection, the shared token scanner, and the staged write that verifies every output before it replaces anything. |
|
|
|
Custom design rule filtering. The release vocabularies it reads are generated
into |
|
Whole project classification and export, and library table conversion. |
|
The job handlers, which sweep local libraries and verify what was written. |
Command line entry points are in kicad/cli/command_*_downgrade.cpp.
For background on the file syntax, see S-Expressions and the File Formats reference.