📄 ecosconfig.cxx
字号:
}
}
// Cope with --help and any user errors. If --help is used then
// subsequent arguments should be ignored, as should any problems
// with the arguments. This allows the user to type a partial
// command, then switch to --help, and use shell history editing
// to complete/correct the command.
if (help || !args_ok || (command_index == argc)) {
usage_message();
return help ? EXIT_SUCCESS : EXIT_FAILURE;
}
// set the default save file
if (savefile.empty ()) { // if the save file was not specified on the command line
savefile = DEFAULT_SAVE_FILE; // use the default save file
}
// find the repository
if (repository.empty ()) { // if the repository was not specified on the command line
const char * env_var = getenv ("ECOS_REPOSITORY");
if (env_var) { // if the ECOS_REPOSITORY environment variable is defined
repository = env_var;
} else { // the ECOS_REPOSITORY environment variable is not defined
// assume that the tool is located in the root of the repository
#ifdef _MSC_VER
char toolpath [_MAX_PATH + 1];
_fullpath (toolpath, argv [0], sizeof (toolpath)); // get the absolute path to the tool
#else
// NOTE: portability problem. realpath() is not a POSIX function.
// Alternative code may be needed on some platforms.
char toolpath [MAXPATHLEN + 1];
realpath (argv [0], toolpath); // get the absolute path to the tool
#endif
repository = toolpath;
for (unsigned int n = repository.size () - 1; n > 0; n--) { // for each char starting at the tail
if (('\\' == repository [n]) || ('/' == repository [n])) { // if the char is a directory separator
repository.resize (n); // remove the filename from the filepath
break;
}
}
}
}
repository = TRANSLATE_PATH(repository);
savefile = TRANSLATE_PATH(savefile);
install_prefix = TRANSLATE_PATH(install_prefix);
// Initialize the cdl_exec code (not quite sure why this needs a
// separate object rather than just a bunch of statics).
cdl_exec exec (trim_path (repository), savefile, trim_path (install_prefix), no_resolve);
cdl_exec::set_quiet_mode(quiet);
cdl_exec::set_verbose_mode(verbose);
cdl_exec::set_ignore_errors_mode(ignore_errors);
// Now identify and process the sub-command.
const std::string command = argv [command_index];
command_index++;
bool status = false;
if ("new" == command) {
// Usage: ecosconfig new <target> [template [version]]
if ((command_index == argc) || ((command_index + 3) <= argc)) {
usage_message();
} else {
// The default values for template and template_version
// are part of the cdl_exec class, so cdl_exec::cmd_new() has
// to be invoked with the right number of arguments.
if ((command_index + 1) == argc) {
status = exec.cmd_new(argv[command_index]);
} else if ((command_index + 2) == argc) {
status = exec.cmd_new(argv[command_index], argv[command_index + 1]);
} else {
status = exec.cmd_new(argv[command_index], argv[command_index + 1], argv[command_index + 2]);
}
}
} else if ("tree" == command) {
// Usage: ecosconfig tree
if (command_index == argc) {
status = exec.cmd_tree ();
} else {
usage_message ();
}
} else if ("list" == command) {
// Usage: ecosconfig list
if (command_index == argc) {
status = exec.cmd_list ();
} else {
usage_message ();
}
} else if ("check" == command) {
// Usage: ecosconfig check
if (command_index == argc) {
status = exec.cmd_check ();
} else {
usage_message ();
}
} else if ("resolve" == command) {
// Usage: ecosconfig resolve
if (command_index == argc) {
status = exec.cmd_resolve ();
} else {
usage_message ();
}
} else if ("add" == command) {
// Usage: ecosconfig add <package> [<package2> ...]
if (command_index < argc) {
std::vector<std::string> packages;
for (int n = command_index; n < argc; n++) {
packages.push_back (argv [n]);
}
status = exec.cmd_add (packages);
} else {
usage_message ();
}
} else if ("remove" == command) {
// Usage: ecosconfig remove <package> [<package2> ...]
if (command_index < argc) {
std::vector<std::string> packages;
for (int n = command_index; n < argc; n++) {
packages.push_back (argv [n]);
}
status = exec.cmd_remove (packages);
} else {
usage_message ();
}
} else if ("version" == command) {
// Usage: ecosconfig version <version> <package> [<package2> ...]
// Note that it is not possible to change several packages to different versions.
if (command_index + 1 < argc) {
std::vector<std::string> packages;
for (int n = command_index + 1; n < argc; n++) {
packages.push_back (argv [n]);
}
status = exec.cmd_version (argv [command_index], packages);
} else {
usage_message ();
}
} else if ("target" == command) {
// Usage: ecosconfig target <target>
if (command_index + 1 == argc) {
status = exec.cmd_target (argv [command_index]);
} else {
usage_message ();
}
} else if ("template" == command) {
// Usage: ecosconfig template <template> [<version>]
if (command_index + 1 == argc) {
status = exec.cmd_template (argv [command_index]);
} else if (command_index + 2 == argc) {
status = exec.cmd_template (argv [command_index], argv [command_index]);
} else {
usage_message ();
}
} else if ("export" == command) {
// Usage: ecosconfige export <filename>
if (command_index + 1 == argc) {
std::string filename = std::string(argv[command_index]);
filename = TRANSLATE_PATH(filename);
status = exec.cmd_export(filename);
} else {
usage_message ();
}
} else if ("import" == command) {
// Usage: ecosconfig import <filename>
if (command_index + 1 == argc) {
std::string filename = std::string(argv[command_index]);
filename = TRANSLATE_PATH(filename);
status = exec.cmd_import(filename);
} else {
usage_message ();
}
} else {
usage_message ();
}
return status ? EXIT_SUCCESS : EXIT_FAILURE;
}
// remove the trailing directory separator from a file path if present
std::string trim_path (const std::string input) {
std::string output = input;
if (! output.empty ()) {
const char last_char = output [output.size () - 1];
if (('\\' == last_char) || ('/' == last_char)) { // if the last char is a directory separator
output.resize (output.size () - 1); // remove the last char
}
}
return output;
}
// print a usage message
void usage_message () {
printf ("Usage: ecosconfig [ qualifier ... ] [ command ]\n");
printf (" commands are:\n");
printf (" list : list repository contents\n");
printf (" new TARGET [ TEMPLATE [ VERSION ] ] : create a configuration\n");
printf (" target TARGET : change the target hardware\n");
printf (" template TEMPLATE [ VERSION ] : change the template\n");
printf (" add PACKAGE [ PACKAGE ... ] : add package(s)\n");
printf (" remove PACKAGE [ PACKAGE ... ] : remove package(s)\n");
printf (" version VERSION PACKAGE [ PACKAGE ... ] : change version of package(s)\n");
printf (" export FILE : export minimal config info\n");
printf (" import FILE : import additional config info\n");
printf (" check : check the configuration\n");
printf (" resolve : resolve conflicts\n");
printf (" tree : create a build tree\n");
printf (" qualifiers are:\n");
printf (" --config=FILE : the configuration file\n");
printf (" --prefix=DIRECTORY : the install prefix\n");
printf (" --srcdir=DIRECTORY : the source repository\n");
printf (" --no-resolve : disable conflict resolution\n");
printf (" --version : show version and copyright\n");
printf (" -q, --quiet : reduce verbosity\n");
printf (" -v, --verbose : increase verbosity\n");
printf (" -i, --ignore-errors : ignore unresolved conflicts\n");
printf (" --help : display this message\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -