KiCad PCB EDA Suite
Loading...
Searching...
No Matches
command_jobset_run.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2024 Mark Roszko <[email protected]>
5 * Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "command_jobset_run.h"
22#include <cli/exit_codes.h>
23#include <kiface_base.h>
24#include <layer_ids.h>
25#include <string_utils.h>
26#include <wx/crt.h>
27#include <jobs/jobset.h>
28#include <jobs/job_registry.h>
29#include <pgm_base.h>
31
32#include <macros.h>
33#include <wx/tokenzr.h>
34#include <jobs_runner.h>
35#include <reporter.h>
36
37#define ARG_STOP_ON_ERROR "--stop-on-error"
38#define ARG_JOB_FILE "--file"
39#define ARG_OUTPUT "--output"
40
42{
43 addCommonArgs( true, false, false, false );
44
45 m_argParser.add_description( UTF8STDSTR( _( "Runs a jobset file" ) ) );
46
47 m_argParser.add_argument( ARG_STOP_ON_ERROR )
48 .help( UTF8STDSTR(
49 _( "Stops processing jobs as they are executed sequentially on the first failure of a job" ) ) )
50 .flag();
51
52 m_argParser.add_argument( ARG_JOB_FILE, "-f" )
53 .help( UTF8STDSTR( _( "Jobset file to be run" ) ) )
54 .default_value( std::string( "" ) )
55 .metavar( "JOB_FILE" );
56
57 m_argParser.add_argument( ARG_OUTPUT )
58 .help( UTF8STDSTR( _( "Jobset file output to generate, leave blank for all outputs defined in the jobset" ) ) )
59 .default_value( std::string( "" ) )
60 .metavar( "OUTPUT" );
61}
62
63
65{
66 bool bail = m_argParser.get<bool>( ARG_STOP_ON_ERROR );
67 wxString jobsFilePath = From_UTF8( m_argParser.get<std::string>( ARG_JOB_FILE ).c_str() );
68 wxString projectFile = m_argInput.ToStdString();
69
70 wxString outputKey = From_UTF8( m_argParser.get<std::string>( ARG_OUTPUT ).c_str() );
71
72 if( !Pgm().GetSettingsManager().LoadProject( projectFile ) )
73 {
75 }
76
77 PROJECT* project = Pgm().GetSettingsManager().GetProject( projectFile );
78
79 JOBSET jobFile( jobsFilePath.ToStdString() );
80
81 jobFile.LoadFromFile();
82
83 JOBS_RUNNER jobsRunner( &aKiway, &jobFile, project,
85
86 int return_code = CLI::EXIT_CODES::SUCCESS;
87
88 if( !outputKey.IsEmpty() )
89 {
90 JOBSET_OUTPUT* output = jobFile.GetOutput( outputKey );
91 if( output == nullptr || !jobsRunner.RunJobsForOutput( output, bail ) )
92 {
94 }
95 }
96 else
97 {
98 if( !jobsRunner.RunJobsAllOutputs( bail ) )
99 {
101 }
102 }
103
104 return return_code;
105}
argparse::ArgumentParser m_argParser
Definition: command.h:100
void addCommonArgs(bool aInput, bool aOutput, bool aInputIsDir, bool aOutputIsDir)
Set up the most common of args used across cli.
Definition: command.cpp:115
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.
static REPORTER & GetInstance()
Definition: reporter.cpp:142
Definition: jobset.h:77
JOBSET_OUTPUT * GetOutput(wxString &aOutput)
Definition: jobset.cpp:231
bool RunJobsForOutput(JOBSET_OUTPUT *aOutput, bool aBail=false)
Definition: jobs_runner.cpp:92
bool RunJobsAllOutputs(bool aBail=false)
Definition: jobs_runner.cpp:47
virtual bool LoadFromFile(const wxString &aDirectory="")
Loads the backing file from disk and then calls Load()
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:285
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
Container for project specific data.
Definition: project.h:64
PROJECT * GetProject(const wxString &aFullPath) const
Retrieves a loaded project by name.
#define ARG_OUTPUT
Definition: command.h:33
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_JOB_FILE
#define ARG_STOP_ON_ERROR
#define _(s)
This file contains miscellaneous commonly used macros and functions.
static const int ERR_JOBS_RUN_FAILED
Definition: exit_codes.h:37
static const int ERR_INVALID_INPUT_FILE
Definition: exit_codes.h:33
static const int SUCCESS
Definition: exit_codes.h:29
SETTINGS_MANAGER * GetSettingsManager()
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE
wxString From_UTF8(const char *cstring)