33#include <wx/filename.h>
37#define ARG_TARGET "--target"
38#define ARG_FORCE "--force"
39#define ARG_DRY_RUN "--dry-run"
40#define ARG_REPORT_JSON "--report-json"
41#define ARG_REPORT "--report"
42#define ARG_VARIANT "--variant"
43#define ARG_DROP_APPROXIMATIONS "--drop-approximations"
50 "KiCad version" ) ) );
53 .default_value( std::string() )
55 _(
"Target version name or id, e.g. \"KiCad 10.0\" or \"10.0\". Defaults to the newest." ) ) );
58 .help(
UTF8STDSTR(
_(
"Export even if some features must be dropped or approximated" ) ) )
62 .help(
UTF8STDSTR(
_(
"Print the compatibility report without writing anything" ) ) )
67 _(
"Omit features instead of approximating them; may remove drawing or electrical data" ) ) )
71 .default_value( std::string() )
72 .help(
UTF8STDSTR(
_(
"Also write the compatibility report as JSON to this file" ) ) );
75 .default_value( std::string() )
76 .help(
UTF8STDSTR(
_(
"Also write the compatibility report as text to this file" ) ) );
79 .default_value( std::string() )
80 .help(
UTF8STDSTR(
_(
"Flatten this variant into the export. Default is the base design." ) ) );
102 wxFprintf( stderr,
_(
"Project file does not exist or is not accessible\n" ) );
107 proFn.MakeAbsolute();
109 wxString projectDir = proFn.GetPath();
110 wxString projectName = proFn.GetName();
114 if( targetName.IsEmpty() )
121 wxFprintf( stderr,
_(
"Unknown target version '%s'. Valid targets: %s\n" ), targetName,
129 wxFprintf( stderr,
_(
"An output folder is required. Use --output.\n" ) );
134 wxString reportError;
138 wxFprintf( stderr, wxS(
"%s\n" ), reportError );
147 reportFile.MakeAbsolute();
148 jsonPath = reportFile.GetFullPath();
149 wxArrayString sources;
150 wxDir::GetAllFiles( projectDir, &sources );
152 for(
const wxString&
source : sources )
157 std::error_code error;
158 bool sameFile = std::filesystem::equivalent(
jsonPath.ToStdWstring(),
source.ToStdWstring(), error );
160 if( sameFile || reportFile.SameAs( wxFileName(
source ) ) )
162 wxFprintf( stderr,
_(
"The report file must differ from the source project files.\n" ) );
174 dropInsteadOfApproximate, variant ) )
176 wxFprintf( stderr, wxT(
"%s\n" ), error );
185 wxFprintf( stderr, wxS(
"%s\n" ), reportError );
192 js[
"target"] = std::string( target->
m_name.ToUTF8() );
194 js[
"lossy"] = report.
IsLossy();
195 js[
"drop_approximations"] = dropInsteadOfApproximate;
196 js[
"entries"] = nlohmann::json::array();
200 js[
"entries"].push_back( { {
"category",
bucketName( entry.m_bucket ) },
201 {
"feature", std::string( entry.m_feature.ToUTF8() ) },
202 {
"detail", std::string( entry.m_detail.ToUTF8() ) },
203 {
"count", entry.m_count } } );
206 std::string
text = js.dump( 2 ) +
"\n";
210 wxFprintf( stderr,
_(
"Could not write the JSON report to '%s'\n" ),
jsonPath );
220 wxFprintf( stderr,
_(
"Cannot export: the project uses features the target cannot represent.\n" ) );
226 wxFprintf( stderr,
_(
"Export would lose data. Re-run with --force to export anyway.\n" ) );
231 outDir.MakeAbsolute();
234 dropInsteadOfApproximate ) )
236 wxFprintf( stderr, wxT(
"%s\n" ), error );
240 wxPrintf(
_(
"Exported to '%s'\n" ), outDir.GetPath() );
argparse::ArgumentParser m_argParser
COMMAND(const std::string &aName)
Define a new COMMAND instance.
void addCommonArgs(bool aInput, bool aOutput, IO_TYPE aInputType, IO_TYPE aOutputType)
Set up the most common of args used across cli.
wxString m_argOutput
Value of the output arg if configured.
wxString m_argInput
Value of the common input arg if configured.
static CLI_REPORTER & GetInstance()
What an export to a given target will keep, approximate, drop, or block.
void Print(REPORTER *aReporter) const
bool IsLossy() const
True if anything is approximated or dropped. This is what triggers the lossy warning.
bool IsBlocked() const
True if some feature makes the target impossible. The user cannot export anyway.
const std::vector< COMPAT_ENTRY > & Entries() const
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
#define ARG_DROP_APPROXIMATIONS
static const char * bucketName(DOWNGRADE_BUCKET aBucket)
DOWNGRADE_BUCKET
What happens to a feature when we export to an older KiCad.
@ BLOCK
Cannot be represented at all, export to this target is not possible.
@ KEEP
Exists in the target, written unchanged.
@ LOWER
Approximated down to a simpler equivalent.
@ DROP
No equivalent, left out.
bool ValidateDowngradeReportPath(const wxString &aPath, wxString &aError)
A report destination that is a design or library file is a mistyped path, not a report.
bool WriteDowngradeReport(const COMPATIBILITY_REPORT &aReport, const wxString &aTarget, const wxString &aPath, wxString &aError)
Write the readable compatibility report, the same text the export dialog shows.
bool IsDowngradeDesignFile(const wxString &aPath)
Files the project export carries over.
const std::vector< DOWNGRADE_TARGET > & GetDowngradeTargets()
Supported downgrade targets, newest first.
const DOWNGRADE_TARGET * FindDowngradeTarget(const wxString &aNameOrId)
Match a user-supplied target string against name or stable id, case-insensitively.
wxString DowngradeTargetNames()
The valid target choices as one user-facing list, for error messages.
static const int ERR_ARGS
static const int ERR_INVALID_INPUT_FILE
static const int ERR_UNKNOWN
bool ExportProjectForDowngrade(KIWAY &aKiway, const wxString &aProjectDir, const wxString &aProjectName, const wxString &aTargetName, const wxString &aDestDir, wxString &aError, const wxString &aVariant, bool aDropInsteadOfApproximate)
Export a downgraded copy of the project into aDestDir.
bool ClassifyProjectForDowngrade(KIWAY &aKiway, const wxString &aProjectDir, const wxString &aProjectName, const wxString &aTargetName, COMPATIBILITY_REPORT &aReport, wxString &aError, std::vector< wxString > *aFoundVariants, bool aDropInsteadOfApproximate, const wxString &aVariant)
Run the board and schematic classification for a whole project without writing anything.
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.
PROJECT_DOWNGRADE_COMMAND()
One line in the compatibility report.
An older KiCad release we can export a project back to.
wxString m_name
User-facing name, e.g. "KiCad 10.0".