📄 cdl_exec.cxx
字号:
//####COPYRIGHTBEGIN####
//
// ----------------------------------------------------------------------------
// Copyright (C) 1998, 1999, 2000, 2001 Red Hat, Inc.
//
// This program is part of the eCos host tools.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// ----------------------------------------------------------------------------
//
//####COPYRIGHTEND####
//==========================================================================
//
// cdl_exec.cxx
//
// The implementation of each ecosconfig command
//
//==========================================================================
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): jld
// Date: 1999-11-08
//
//####DESCRIPTIONEND####
//==========================================================================
#ifdef _MSC_VER
#include <direct.h> /* for getcwd() */
#else
#include <unistd.h> /* for getcwd() */
#endif
#ifdef __CYGWIN__
#include <windows.h>
#include <sys/cygwin.h> /* for cygwin_conv_to_win32_path() */
#endif
#include "build.hxx"
#include "cdl_exec.hxx"
// ----------------------------------------------------------------------------
bool cdl_exec::quiet = false;
bool cdl_exec::verbose = false;
bool cdl_exec::ignore_errors = false;
cdl_exec::cdl_exec (const std::string repository_arg, const std::string savefile_arg,
const std::string install_arg, bool no_resolve_arg)
: repository(repository_arg),
savefile(savefile_arg),
install_prefix(install_arg),
no_resolve(no_resolve_arg),
pkgdata (NULL),
interp (NULL),
config (NULL)
{
// The inference callback does not actually do anything at present.
// In future it may be useful for diagnostic purposes.
CdlTransactionBody::set_inference_callback_fn (&inference_callback);
// Automatic inference is always disabled. The inference engine
// only gets invoked explicitly, after a suitable transaction callback
// has been invoked. The problem here is that the transaction callback
// has to report changes made by the inference engine but there is
// no way of distinguishing between inferred values that come out of
// savefiles and inferred values determined by the inference engine.
CdlTransactionBody::disable_automatic_inference ();
}
void
cdl_exec::set_quiet_mode(bool new_val)
{
quiet = new_val;
}
void
cdl_exec::set_verbose_mode(bool new_val)
{
verbose = new_val;
CdlPackagesDatabaseBody::set_verbose(new_val);
}
void
cdl_exec::set_ignore_errors_mode(bool new_val)
{
ignore_errors = new_val;
}
// ----------------------------------------------------------------------------
void
cdl_exec::init(bool load_config)
{
pkgdata = CdlPackagesDatabaseBody::make(repository, &diagnostic_handler, &diagnostic_handler);
interp = CdlInterpreterBody::make();
if (load_config) {
config = CdlConfigurationBody::load (savefile, pkgdata, interp, &diagnostic_handler, &diagnostic_handler);
}
}
// ----------------------------------------------------------------------------
void
cdl_exec::delete_cdl_data ()
{
if (0 != config) {
delete config;
config = 0;
}
if (0 != interp) {
delete interp;
interp = 0;
}
if (0 != pkgdata) {
delete pkgdata;
pkgdata = 0;
}
}
// ----------------------------------------------------------------------------
bool cdl_exec::cmd_new (const std::string cdl_hardware,
const std::string cdl_template /* = "default" */,
const std::string cdl_version /* = "" */)
{
bool status = false;
try {
init(false);
config = CdlConfigurationBody::make ("eCos", pkgdata, interp);
// The hardware and template should be loaded in a single transaction.
// Validating the target name etc. can be left to libcdl.
CdlLocalTransaction transact(config);
config->set_hardware(transact.get(), resolve_hardware_alias(cdl_hardware), &diagnostic_handler, &diagnostic_handler);
config->set_template(transact.get(), cdl_template, cdl_version, &diagnostic_handler, &diagnostic_handler);
transact.body();
transact.destroy();
// Unless inference has been suppressed, make sure that the
// inference engine gets invoked and that its results get
// reported.
if (!no_resolve) {
CdlTransactionBody::set_callback_fn(&transaction_callback);
config->resolve_all_conflicts();
}
// Now report any conflicts which the inference engine could not report.
report_conflicts();
// A savefile should be generated/updated even if there are conflicts.
// Otherwise the user does not have a chance to edit the savefile
// and fix things.
config->save (savefile);
if (ignore_errors || (0 == config->get_all_conflicts().size())) {
status = true;
}
} catch (CdlStringException exception) {
exception_handler (exception);
} catch (...) {
exception_handler ();
}
delete_cdl_data ();
return status;
}
// ----------------------------------------------------------------------------
bool
cdl_exec::cmd_target (const std::string cdl_target)
{
bool status = false;
try {
init(true);
config->set_hardware (resolve_hardware_alias (cdl_target), &diagnostic_handler, &diagnostic_handler);
if (!no_resolve) {
CdlTransactionBody::set_callback_fn(&transaction_callback);
config->resolve_all_conflicts();
}
report_conflicts();
config->save (savefile);
if (ignore_errors || (0 == config->get_all_conflicts().size())) {
status = true;
}
} catch (CdlStringException exception) {
exception_handler (exception);
} catch (...) {
exception_handler ();
}
delete_cdl_data ();
return status;
}
// ----------------------------------------------------------------------------
bool
cdl_exec::cmd_template (const std::string cdl_template, const std::string cdl_version /* = "" */)
{
bool status = false;
try {
init(true);
config->set_template (cdl_template, cdl_version, &diagnostic_handler, &diagnostic_handler);
if (!no_resolve) {
CdlTransactionBody::set_callback_fn(&transaction_callback);
config->resolve_all_conflicts();
}
report_conflicts();
config->save (savefile);
if (ignore_errors || (0 == config->get_all_conflicts().size())) {
status = true;
}
} catch (CdlStringException exception) {
exception_handler (exception);
} catch (...) {
exception_handler ();
}
delete_cdl_data ();
return status;
}
// ----------------------------------------------------------------------------
bool
cdl_exec::cmd_export (const std::string cdl_savefile)
{
bool status = false;
try {
init(true);
if (!no_resolve) {
CdlTransactionBody::set_callback_fn(&transaction_callback);
config->resolve_all_conflicts();
}
report_conflicts();
// Exporting to another file should only happen if the
// configuration is conflict-free. This is different from
// updating the savefile.
if (ignore_errors || (0 == config->get_all_conflicts().size())) {
config->save (cdl_savefile, /* minimal = */ true);
status = true;
}
} catch (CdlStringException exception) {
exception_handler (exception);
} catch (...) {
exception_handler ();
}
delete_cdl_data ();
return status;
}
// ----------------------------------------------------------------------------
bool
cdl_exec::cmd_import (const std::string cdl_savefile)
{
bool status = false;
try {
init(true);
config->add(cdl_savefile, &diagnostic_handler, &diagnostic_handler);
if (!no_resolve) {
CdlTransactionBody::set_callback_fn(&transaction_callback);
config->resolve_all_conflicts();
}
report_conflicts();
config->save (savefile);
if (ignore_errors || (0 == config->get_all_conflicts().size())) {
status = true;
}
} catch (CdlStringException exception) {
exception_handler (exception);
} catch (...) {
exception_handler ();
}
delete_cdl_data ();
return status;
}
// ----------------------------------------------------------------------------
bool
cdl_exec::cmd_add (const std::vector<std::string> cdl_packages)
{
bool status = false;
try {
init(true);
for (unsigned int n = 0; n < cdl_packages.size (); n++) {
config->load_package (resolve_package_alias (cdl_packages [n]), "", &diagnostic_handler, &diagnostic_handler);
}
if (!no_resolve) {
CdlTransactionBody::set_callback_fn(&transaction_callback);
config->resolve_all_conflicts();
}
report_conflicts();
config->save (savefile);
if (ignore_errors || (0 == config->get_all_conflicts().size())) {
status = true;
}
} catch (CdlStringException exception) {
exception_handler (exception);
} catch (...) {
exception_handler ();
}
delete_cdl_data ();
return status;
}
// ----------------------------------------------------------------------------
bool
cdl_exec::cmd_remove (const std::vector<std::string> cdl_packages)
{
unsigned int n;
bool status = false;
try {
init(true);
for (n = 0; n < cdl_packages.size (); n++) {
if (! config->lookup (resolve_package_alias (cdl_packages [n]))) {
throw CdlStringException ("Unknown package " + cdl_packages [n]);
}
}
for (n = 0; n < cdl_packages.size (); n++) {
config->unload_package (resolve_package_alias (cdl_packages [n]));
}
if (!no_resolve) {
CdlTransactionBody::set_callback_fn(&transaction_callback);
config->resolve_all_conflicts();
}
report_conflicts();
config->save (savefile);
if (ignore_errors || (0 == config->get_all_conflicts().size())) {
status = true;
}
} catch (CdlStringException exception) {
exception_handler (exception);
} catch (...) {
exception_handler ();
}
delete_cdl_data ();
return status;
}
// ----------------------------------------------------------------------------
bool
cdl_exec::cmd_version (const std::string cdl_version, const std::vector<std::string> cdl_packages)
{
bool status = false;
try {
init(true);
for (unsigned int n = 0; n < cdl_packages.size (); n++) {
config->change_package_version(resolve_package_alias (cdl_packages [n]), cdl_version,
&diagnostic_handler, &diagnostic_handler, true);
}
if (!no_resolve) {
CdlTransactionBody::set_callback_fn(&transaction_callback);
config->resolve_all_conflicts();
}
report_conflicts();
config->save (savefile);
if (ignore_errors || (0 == config->get_all_conflicts().size())) {
status = true;
}
} catch (CdlStringException exception) {
exception_handler (exception);
} catch (...) {
exception_handler ();
}
delete_cdl_data ();
return status;
}
// ----------------------------------------------------------------------------
bool
cdl_exec::cmd_tree ()
{
bool status = false;
try {
init(true);
if (!no_resolve) {
CdlTransactionBody::set_callback_fn(&transaction_callback);
config->resolve_all_conflicts();
}
report_conflicts();
config->save (savefile);
// A build tree should only be generated if there are no conflicts.
if (ignore_errors || (0 == config->get_all_conflicts().size())) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -