3 //============================================================================
7 // Temporary implementation of the CdlPackagesDatabase class
8 // Implementations of the temporary CdlTargetsDatabase and
9 // CdlTemplatesDatabase classes.
11 //============================================================================
12 //####COPYRIGHTBEGIN####
14 // ----------------------------------------------------------------------------
15 // Copyright (C) 2002 Bart Veer
16 // Copyright (C) 1999, 2000, 2001 Red Hat, Inc.
18 // This file is part of the eCos host tools.
20 // This program is free software; you can redistribute it and/or modify it
21 // under the terms of the GNU General Public License as published by the Free
22 // Software Foundation; either version 2 of the License, or (at your option)
25 // This program is distributed in the hope that it will be useful, but WITHOUT
26 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
30 // You should have received a copy of the GNU General Public License along with
31 // this program; if not, write to the Free Software Foundation, Inc.,
32 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 // ----------------------------------------------------------------------------
36 //####COPYRIGHTEND####
37 //============================================================================
38 //#####DESCRIPTIONBEGIN####
45 //####DESCRIPTIONEND####
46 //============================================================================
51 // ----------------------------------------------------------------------------
52 #include "cdlconfig.h"
54 // Get the infrastructure types, assertions, tracing and similar
56 #include <cyg/infra/cyg_ass.h>
57 #include <cyg/infra/cyg_trac.h>
59 // <cdl.hxx> defines everything implemented in this module.
60 // It implicitly supplies <string>, <vector> and <map> because
61 // the class definitions rely on these headers.
64 // strcmp() is useful when dealing with Tcl strings.
71 // ----------------------------------------------------------------------------
72 // Some test cases may want to read in a file other than
73 // "ecos.db", e.g. to facilitate testing the error conditions.
75 CdlPackagesDatabaseBody::database_name = "ecos.db";
77 // Should warnings be issued for minor database inconsistencies?
78 bool CdlPackagesDatabaseBody::verbose_mode = false;
80 // The new_package etc. commands need to store the name of the
81 // current package so that subsequent commands can do the right thing.
82 // Using constant strings as the key avoids typo problems.
83 const char* dbparser_pkgname = "::dbparser_pkgname";
84 const char* dbparser_pkgdata = "__cdl_dbparser_pkgdata";
85 const char* dbparser_targetname = "::dbparser_targetname";
86 const char* dbparser_targetdata = "__cdl_dbparser_targetdata";
87 const char* dbparser_component_repository = "::component_repository";
88 const char* dbparser_database_key = "__dbparser_key"; // for assoc data
89 const char* template_description_key = "__cdl_extract_template_description"; // ditto
90 const char* template_packages_key = "__cdl_extract_template_packages";
92 // These are useful for generating diagnostics.
93 static std::string diag_package = std::string("package ");
94 static std::string diag_target = std::string("target ");
96 CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlPackagesDatabaseBody);
99 //{{{ Tcl commands for the parser
101 //{{{ CdlDbParser class
103 // ----------------------------------------------------------------------------
104 // Commands that get invoked from inside the Tcl interpreter. These
105 // need access to the internals of the database objects, which can be
106 // achieved by making them static members of a CdlDbParser class.
110 static int new_package(CdlInterpreter, int, const char*[]);
111 static int package_description(CdlInterpreter, int, const char*[]);
112 static int package_alias(CdlInterpreter, int, const char*[]);
113 static int package_directory(CdlInterpreter, int, const char*[]);
114 static int package_script(CdlInterpreter, int, const char*[]);
115 static int package_hardware(CdlInterpreter, int, const char*[]);
117 static int new_target(CdlInterpreter, int, const char*[]);
118 static int target_description(CdlInterpreter, int, const char*[]);
119 static int target_alias(CdlInterpreter, int, const char*[]);
120 static int target_packages(CdlInterpreter, int, const char*[]);
121 static int target_enable(CdlInterpreter, int, const char*[]);
122 static int target_disable(CdlInterpreter, int, const char*[]);
123 static int target_set_value(CdlInterpreter, int, const char*[]);
127 //{{{ CdlDbParser::package-related
129 // ----------------------------------------------------------------------------
130 // package <name> <body>
133 CdlDbParser::new_package(CdlInterpreter interp, int argc, const char* argv[])
135 CYG_REPORT_FUNCNAMETYPE("CdlDbParser::new_package", "result %d");
136 CYG_REPORT_FUNCARG1XV(argc);
137 CYG_PRECONDITION_CLASSC(interp);
139 CdlPackagesDatabase db = static_cast<CdlPackagesDatabase>(interp->get_assoc_data(dbparser_database_key));
140 CYG_INVARIANT_CLASSC(CdlPackagesDatabaseBody, db);
144 CdlParse::report_error(interp, "", "Invalid package command, missing name and contents.");
145 } else if (argc == 2) {
146 CdlParse::report_error(interp, diag_package + argv[1], "Invalid package command, missing body.");
148 CdlParse::report_error(interp, diag_package + argv[1],
149 "Invalid package command, expecting just name and body.");
151 CYG_REPORT_RETVAL(TCL_OK);
154 std::string pkg_name = argv[1];
156 // Better make sure that this is not a duplicate definition.
157 if (std::find(db->package_names.begin(), db->package_names.end(), pkg_name) != db->package_names.end()) {
158 CdlParse::report_warning(interp, diag_package + pkg_name, "Duplicate package entry, ignoring second occurence.");
159 CYG_REPORT_RETVAL(TCL_OK);
163 // The package data is constructed locally. It only gets added to
164 // the database in the absence of errors.
165 bool package_ok = true;
166 int old_error_count = CdlParse::get_error_count(interp);
168 CdlPackagesDatabaseBody::package_data package;
169 package.description = "";
170 package.directory = "";
172 package.hardware = false;
174 // aliases and versions are vectors and will take care of themselves
175 // And the name had better be valid as well.
176 if (!Cdl::is_valid_cdl_name(pkg_name)) {
177 CdlParse::report_error(interp, diag_package + pkg_name, "This is not a valid CDL name.");
180 // Sort out the commands, then invoke the script in argv[2]. There is
181 // no need to worry about error recovery here, any errors will be
183 CdlInterpreterCommandEntry commands[] = {
184 CdlInterpreterCommandEntry("description", &CdlDbParser::package_description ),
185 CdlInterpreterCommandEntry("alias", &CdlDbParser::package_alias ),
186 CdlInterpreterCommandEntry("directory", &CdlDbParser::package_directory ),
187 CdlInterpreterCommandEntry("script", &CdlDbParser::package_script ),
188 CdlInterpreterCommandEntry("hardware", &CdlDbParser::package_hardware ),
189 CdlInterpreterCommandEntry("", 0 )
191 CdlInterpreterBody::CommandSupport cmds(interp, commands);
192 CdlInterpreterBody::VariableSupport interp_name(interp, dbparser_pkgname, pkg_name);
193 CdlInterpreterBody::AssocSupport interp_data(interp, dbparser_pkgdata, static_cast<ClientData>(&package));
194 int result = interp->eval(argv[2]);
195 if (TCL_OK == result) {
197 // The body has been parsed OK. Check that it is valid.
198 if ("" == package.directory) {
199 CdlParse::report_error(interp, diag_package + pkg_name, "Missing directory specification.");
201 if ("" == package.script) {
202 CdlParse::report_error(interp, diag_package + pkg_name, "Missing script specification.");
204 if (0 == package.aliases.size()) {
205 CdlParse::report_error(interp, diag_package + pkg_name, "At least one alias should be supplied.");
208 // Additional checks. Is the package directory actually present?
209 // Note that there are scenarios where a package may be listed
210 // in the database but not installed, e.g. an anoncvs checkout
211 // of selected modules.
212 if ("" != package.directory) {
213 std::string repo = interp->get_variable(dbparser_component_repository);
214 CYG_ASSERTC("" != repo);
216 std::string pkgdir = repo + "/" + package.directory;
217 if (!interp->is_directory(pkgdir)) {
218 if (CdlPackagesDatabaseBody::verbose_mode) {
219 CdlParse::report_warning(interp, diag_package + pkg_name,
220 std::string("This package is not present in the component repository.\n"
221 "There is no directory `") + pkgdir + "'.");
226 // Now look for version subdirectories. There should be at least one.
227 std::vector<std::string> subdirs;
229 interp->locate_subdirs(pkgdir, subdirs);
230 std::sort(subdirs.begin(), subdirs.end(), Cdl::version_cmp());
232 for (i = 0; i < subdirs.size(); i++) {
233 if (("CVS" == subdirs[i]) || ("cvs" == subdirs[i])) {
236 if ("" != package.script) {
237 if (!(interp->is_file(pkgdir + "/" + subdirs[i] + "/cdl/" + package.script) ||
238 interp->is_file(pkgdir + "/" + subdirs[i] + "/" + package.script))) {
239 CdlParse::report_warning(interp, diag_package + pkg_name,
240 std::string("Version subdirectory `") + subdirs[i] +
241 "' does not have a CDL script `" + package.script + "'.");
245 package.versions.push_back(subdirs[i]);
247 if (0 == package.versions.size()) {
248 CdlParse::report_warning(interp, diag_package + pkg_name,
249 "This package does not have any valid version subdirectories.");
256 // If the package is still ok, now is the time to add it to the database.
257 if (package_ok && (old_error_count == CdlParse::get_error_count(interp))) {
258 db->package_names.push_back(pkg_name);
259 db->packages[pkg_name] = package;
262 CYG_REPORT_RETVAL(result);
266 // Syntax: description <text>
268 CdlDbParser::package_description(CdlInterpreter interp, int argc, const char* argv[])
270 CYG_REPORT_FUNCNAMETYPE("CdlDbParser::package_description", "result %d");
271 CYG_REPORT_FUNCARG1XV(argc);
272 CYG_PRECONDITION_CLASSC(interp);
274 std::string name = interp->get_variable(dbparser_pkgname);
275 CYG_ASSERTC("" != name);
276 CdlPackagesDatabaseBody::package_data* package =
277 static_cast<CdlPackagesDatabaseBody::package_data*>(interp->get_assoc_data(dbparser_pkgdata));
280 CdlParse::report_error(interp, diag_package + name, "Invalid description, expecting a single string.");
281 } else if ("" != package->description) {
282 CdlParse::report_warning(interp, diag_package + name, "A package should have only one description.");
284 package->description = argv[1];
287 CYG_REPORT_RETVAL(TCL_OK);
291 // Syntax: alias <list>
292 // For example: alias { "This is an alias" another_alias dummy_name }
294 CdlDbParser::package_alias(CdlInterpreter interp, int argc, const char* argv[])
296 CYG_REPORT_FUNCNAMETYPE("CdlDbParser::package_alias", "result %d");
297 CYG_REPORT_FUNCARG1XV(argc);
298 CYG_PRECONDITION_CLASSC(interp);
300 std::string name = interp->get_variable(dbparser_pkgname);
301 CYG_ASSERTC("" != name);
302 CdlPackagesDatabaseBody::package_data* package =
303 static_cast<CdlPackagesDatabaseBody::package_data*>(interp->get_assoc_data(dbparser_pkgdata));
305 // There should be one argument, a list of valid packages.
306 // Also, the alias command should be used only once
308 CdlParse::report_error(interp, diag_package + name,
309 "The alias command should be followed by a list of known aliases.");
310 } else if (0 < package->aliases.size()) {
311 CdlParse::report_warning(interp, diag_package + name, "There should be only one list of aliases.");
314 const char** list_entries = 0;
315 Tcl_Interp* tcl_interp = interp->get_tcl_interpreter();
316 if (TCL_OK != Tcl_SplitList(tcl_interp, CDL_TCL_CONST_CAST(char*, argv[1]), &list_count, CDL_TCL_CONST_CAST(char***, &list_entries))) {
317 CdlParse::report_error(interp, diag_package + name, Tcl_GetStringResult(tcl_interp));
319 if (0 == list_count) {
320 CdlParse::report_error(interp, diag_package + name, "At least one alias should be supplied.");
322 for (int i = 0; i < list_count; i++) {
323 package->aliases.push_back(list_entries[i]);
326 Tcl_Free((char*)list_entries);
330 CYG_REPORT_RETVAL(TCL_OK);
334 // Syntax: directory <path>
335 // The path is of course relative to the component repository.
337 CdlDbParser::package_directory(CdlInterpreter interp, int argc, const char* argv[])
339 CYG_REPORT_FUNCNAMETYPE("CdlDbParser::package_directory", "result %d");
340 CYG_REPORT_FUNCARG1XV(argc);
341 CYG_PRECONDITION_CLASSC(interp);
343 std::string name = interp->get_variable(dbparser_pkgname);
344 CYG_ASSERTC("" != name);
345 CdlPackagesDatabaseBody::package_data* package =
346 static_cast<CdlPackagesDatabaseBody::package_data*>(interp->get_assoc_data(dbparser_pkgdata));
348 // There should be exactly one argument, and the directory command
349 // should be used only once.
351 CdlParse::report_error(interp, diag_package + name, "Only one directory can be specified.");
352 } else if ("" != package->directory) {
353 CdlParse::report_warning(interp, diag_package + name, "A package can be located in only one directory.");
355 package->directory = argv[1];
357 CYG_REPORT_RETVAL(TCL_OK);
362 // There are no arguments.
364 CdlDbParser::package_hardware(CdlInterpreter interp, int argc, const char* argv[])
366 CYG_REPORT_FUNCNAMETYPE("CdlDbParser::package_hardware", "result %d");
367 CYG_REPORT_FUNCARG1XV(argc);
368 CYG_PRECONDITION_CLASSC(interp);
370 std::string name = interp->get_variable(dbparser_pkgname);
371 CYG_ASSERTC("" != name);
372 CdlPackagesDatabaseBody::package_data* package =
373 static_cast<CdlPackagesDatabaseBody::package_data*>(interp->get_assoc_data(dbparser_pkgdata));
376 CdlParse::report_error(interp, diag_package + name, "There should be no further data after hardware.");
377 } else if (package->hardware) {
378 CdlParse::report_warning(interp, diag_package + name, "The hardware property should be specified only once");
380 package->hardware = true;
383 CYG_REPORT_RETVAL(TCL_OK);
387 // Syntax: script <filename>
389 CdlDbParser::package_script(CdlInterpreter interp, int argc, const char* argv[])
391 CYG_REPORT_FUNCNAMETYPE("CdlDbParser::package_script", "result %d");
392 CYG_REPORT_FUNCARG1XV(argc);
393 CYG_PRECONDITION_CLASSC(interp);
395 std::string name = interp->get_variable(dbparser_pkgname);
396 CYG_ASSERTC("" != name);
397 CdlPackagesDatabaseBody::package_data* package =
398 static_cast<CdlPackagesDatabaseBody::package_data*>(interp->get_assoc_data(dbparser_pkgdata));
400 // There should be exactly one argument, and the script command
401 // should be used only once
403 CdlParse::report_error(interp, diag_package + name, "Only one CDL script can be specified.");
404 } else if ("" != package->script) {
405 CdlParse::report_warning(interp, diag_package + name, "A package can have only one starting CDL script.");
407 package->script = argv[1];
410 CYG_REPORT_RETVAL(TCL_OK);
415 //{{{ CdlDbParser::target-related
417 // ----------------------------------------------------------------------------
418 // target <name> <body>
421 CdlDbParser::new_target(CdlInterpreter interp, int argc, const char* argv[])
423 CYG_REPORT_FUNCNAMETYPE("CdlDbParser::new_target", "result %d");
424 CYG_REPORT_FUNCARG1XV(argc);
425 CYG_PRECONDITION_CLASSC(interp);
427 CdlPackagesDatabase db = static_cast<CdlPackagesDatabase>(interp->get_assoc_data(dbparser_database_key));
428 CYG_INVARIANT_CLASSC(CdlPackagesDatabaseBody, db);
432 CdlParse::report_error(interp, "", "Invalid target command, missing name and contents.");
433 } else if (argc == 2) {
434 CdlParse::report_error(interp, diag_target + argv[1], "Invalid target command, missing body.");
436 CdlParse::report_error(interp, diag_target + argv[1], "Invalid target command, expecting just name and body.");
438 CYG_REPORT_RETVAL(TCL_OK);
442 std::string target_name = argv[1];
444 // Better make sure that this is not a duplicate definition.
445 if (std::find(db->target_names.begin(), db->target_names.end(), target_name) != db->target_names.end()) {
446 CdlParse::report_warning(interp, diag_target + target_name,
447 "Duplicate target entry, ignoring second occurence.");
448 CYG_REPORT_RETVAL(TCL_OK);
452 // The target data is constructed locally. It only gets added to the
453 // database in the absence of errors.
454 bool target_ok = true;
455 int old_error_count = CdlParse::get_error_count(interp);
457 CdlPackagesDatabaseBody::target_data target;
458 target.description = "";
459 // aliases, packages and compiler_flags are vectors and will take care of themselves
461 // Sort out the commands, then invoke the script in argv[2]. There is
462 // no need to worry about error recovery here, any errors will be
464 CdlInterpreterCommandEntry commands[] = {
465 CdlInterpreterCommandEntry("description", &CdlDbParser::target_description ),
466 CdlInterpreterCommandEntry("alias", &CdlDbParser::target_alias ),
467 CdlInterpreterCommandEntry("packages", &CdlDbParser::target_packages ),
468 CdlInterpreterCommandEntry("enable", &CdlDbParser::target_enable ),
469 CdlInterpreterCommandEntry("disable", &CdlDbParser::target_disable ),
470 CdlInterpreterCommandEntry("set_value", &CdlDbParser::target_set_value ),
471 CdlInterpreterCommandEntry("", 0 )
473 CdlInterpreterBody::CommandSupport interp_cmds(interp, commands);
474 CdlInterpreterBody::VariableSupport interp_name(interp, dbparser_targetname, target_name);
475 CdlInterpreterBody::AssocSupport interp_data(interp, dbparser_targetdata, static_cast<ClientData>(&target));
476 int result = interp->eval(argv[2]);
477 if (TCL_OK == result) {
479 if (0 == target.aliases.size()) {
480 CdlParse::report_error(interp, diag_target + target_name, "At least one alias should be supplied.");
483 // There is no check for > 0 hardware packages. This is an unlikely
484 // scenario but should be allowed for.
485 // Add this target to the list.
488 if (target_ok && (old_error_count == CdlParse::get_error_count(interp))) {
489 db->target_names.push_back(target_name);
490 db->targets[target_name] = target;
493 CYG_REPORT_RETVAL(result);
497 // Syntax: description <text>
499 CdlDbParser::target_description(CdlInterpreter interp, int argc, const char* argv[])
501 CYG_REPORT_FUNCNAMETYPE("CdlDbParser::target_description", "result %d");
502 CYG_REPORT_FUNCARG1XV(argc);
503 CYG_PRECONDITION_CLASSC(interp);
505 std::string name = interp->get_variable(dbparser_targetname);
506 CYG_ASSERTC("" != name);
507 CdlPackagesDatabaseBody::target_data* target =
508 static_cast<CdlPackagesDatabaseBody::target_data*>(interp->get_assoc_data(dbparser_targetdata));
511 CdlParse::report_error(interp, diag_target + name, "The target description should be a single string.");
512 } else if ("" != target->description) {
513 CdlParse::report_warning(interp, diag_target + name, "A target should have only one description.");
515 target->description = argv[1];
518 CYG_REPORT_RETVAL(TCL_OK);
522 // Syntax: alias <list>
523 // For example: alias { "This is an alias" another_alias dummy_name }
525 CdlDbParser::target_alias(CdlInterpreter interp, int argc, const char* argv[])
527 CYG_REPORT_FUNCNAMETYPE("CdlDbParser::target_alias", "result %d");
528 CYG_REPORT_FUNCARG1XV(argc);
529 CYG_PRECONDITION_CLASSC(interp);
531 std::string name = interp->get_variable(dbparser_targetname);
532 CYG_ASSERTC("" != name);
533 CdlPackagesDatabaseBody::target_data* target =
534 static_cast<CdlPackagesDatabaseBody::target_data*>(interp->get_assoc_data(dbparser_targetdata));
536 // There should be one argument, a list of valid aliases
537 // The alias command should be used only once
539 CdlParse::report_error(interp, diag_target + name, "The alias command should be followed by a list of known aliases");
540 } else if (0 < target->aliases.size()) {
541 CdlParse::report_warning(interp, diag_target + name, "There should be only one list of aliases.");
544 const char** list_entries = 0;
545 Tcl_Interp* tcl_interp = interp->get_tcl_interpreter();
546 if (TCL_OK != Tcl_SplitList(tcl_interp, CDL_TCL_CONST_CAST(char*, argv[1]), &list_count, CDL_TCL_CONST_CAST(char***, &list_entries))) {
547 CdlParse::report_error(interp, diag_target + name, Tcl_GetStringResult(tcl_interp));
549 if (0 == list_count) {
550 CdlParse::report_error(interp, diag_target + name, "At least one alias should be supplied.");
552 for (int i = 0; i < list_count; i++) {
553 target->aliases.push_back(list_entries[i]);
556 Tcl_Free((char*)list_entries);
560 CYG_REPORT_RETVAL(TCL_OK);
564 // Syntax: packages <list> ...
565 // For example: packages { CYGPKG_HAL_XXX CYGPKG_HAL_YYY }
567 CdlDbParser::target_packages(CdlInterpreter interp, int argc, const char* argv[])
569 CYG_REPORT_FUNCNAMETYPE("CdlDbParser::target_packages", "result %d");
570 CYG_REPORT_FUNCARG1XV(argc);
571 CYG_PRECONDITION_CLASSC(interp);
573 std::string name = interp->get_variable(dbparser_targetname);
574 CYG_ASSERTC("" != name);
575 CdlPackagesDatabaseBody::target_data* target =
576 static_cast<CdlPackagesDatabaseBody::target_data*>(interp->get_assoc_data(dbparser_targetdata));
578 // There should be one argument, a list of valid packages.
579 // The packages command should be used only once
581 CdlParse::report_error(interp, diag_target + name, "`packages' should be followed by a list of known packages.");
582 } else if (0 < target->packages.size()) {
583 CdlParse::report_warning(interp, diag_target + name, "There should be only one list of packages.");
586 const char** list_entries = 0;
587 Tcl_Interp* tcl_interp = interp->get_tcl_interpreter();
588 if (TCL_OK != Tcl_SplitList(tcl_interp, CDL_TCL_CONST_CAST(char*, argv[1]), &list_count, CDL_TCL_CONST_CAST(char***, &list_entries))) {
589 CdlParse::report_error(interp, diag_target + name, Tcl_GetStringResult(tcl_interp));
591 // Allow for a dummy target spec, just in case it proves useful.
592 if (0 != list_count) {
593 for (int i = 0; i < list_count; i++) {
594 target->packages.push_back(list_entries[i]);
597 Tcl_Free((char*)list_entries);
601 CYG_REPORT_RETVAL(TCL_OK);
605 // Syntax: enable { opt1 opt2 ... }
606 // For example: enable { CYGPKG_HAL_ARM_CL7xxx_7211 }
608 CdlDbParser::target_enable(CdlInterpreter interp, int argc, const char* argv[])
610 CYG_REPORT_FUNCNAMETYPE("CdlDbParser::target_enable", "result %d");
611 CYG_REPORT_FUNCARG1XV(argc);
612 CYG_PRECONDITION_CLASSC(interp);
614 std::string name = interp->get_variable(dbparser_targetname);
615 CYG_ASSERTC("" != name);
616 CdlPackagesDatabaseBody::target_data* target =
617 static_cast<CdlPackagesDatabaseBody::target_data*>(interp->get_assoc_data(dbparser_targetdata));
619 // There should be one argument, a list of valid flags.
621 CdlParse::report_error(interp, diag_target + name, "`enable' should be followed by a list of CDL options.");
624 const char** list_entries = 0;
625 Tcl_Interp* tcl_interp = interp->get_tcl_interpreter();
626 if (TCL_OK != Tcl_SplitList(tcl_interp, CDL_TCL_CONST_CAST(char*, argv[1]), &list_count, CDL_TCL_CONST_CAST(char***, &list_entries))) {
627 CdlParse::report_error(interp, diag_target + name, Tcl_GetStringResult(tcl_interp));
629 for (int i = 0; i < list_count; i++) {
630 target->enable.push_back(list_entries[i]);
632 Tcl_Free((char *) list_entries);
636 CYG_REPORT_RETVAL(TCL_OK);
641 // Syntax: disable { opt1 opt2 ... }
642 // For example: disable { CYGPKG_HAL_ARM_CL7xxx_7111 }
644 CdlDbParser::target_disable(CdlInterpreter interp, int argc, const char* argv[])
646 CYG_REPORT_FUNCNAMETYPE("CdlDbParser::target_disable", "result %d");
647 CYG_REPORT_FUNCARG1XV(argc);
648 CYG_PRECONDITION_CLASSC(interp);
650 std::string name = interp->get_variable(dbparser_targetname);
651 CYG_ASSERTC("" != name);
652 CdlPackagesDatabaseBody::target_data* target =
653 static_cast<CdlPackagesDatabaseBody::target_data*>(interp->get_assoc_data(dbparser_targetdata));
655 // There should be one argument, a list of valid flags.
657 CdlParse::report_error(interp, diag_target + name, "`disable' should be followed by a list of CDL options.");
660 const char** list_entries = 0;
661 Tcl_Interp* tcl_interp = interp->get_tcl_interpreter();
662 if (TCL_OK != Tcl_SplitList(tcl_interp, CDL_TCL_CONST_CAST(char*, argv[1]), &list_count, CDL_TCL_CONST_CAST(char***, &list_entries))) {
663 CdlParse::report_error(interp, diag_target + name, Tcl_GetStringResult(tcl_interp));
665 for (int i = 0; i < list_count; i++) {
666 target->disable.push_back(list_entries[i]);
668 Tcl_Free((char *) list_entries);
672 CYG_REPORT_RETVAL(TCL_OK);
676 // Syntax: set_value <option> <value>
677 // For example: set_value CYGHWR_MEMSIZE 0x100000
679 CdlDbParser::target_set_value(CdlInterpreter interp, int argc, const char* argv[])
681 CYG_REPORT_FUNCNAMETYPE("CdlDbParser::target_set_value", "result %d");
682 CYG_REPORT_FUNCARG1XV(argc);
683 CYG_PRECONDITION_CLASSC(interp);
685 std::string name = interp->get_variable(dbparser_targetname);
686 CYG_ASSERTC("" != name);
687 CdlPackagesDatabaseBody::target_data* target =
688 static_cast<CdlPackagesDatabaseBody::target_data*>(interp->get_assoc_data(dbparser_targetdata));
690 // There should be one argument, a list of valid flags.
692 CdlParse::report_error(interp, diag_target + name, "`set_value' should be followed by an option name and its value.");
694 target->set_values.push_back(std::make_pair(std::string(argv[1]), std::string(argv[2])));
697 CYG_REPORT_RETVAL(TCL_OK);
704 //{{{ CdlPackagesDatabase:: creation
706 // ----------------------------------------------------------------------------
707 // The exported interface is make(). The hard work is done inside the
711 CdlPackagesDatabaseBody::make(std::string repo, CdlDiagnosticFnPtr error_fn, CdlDiagnosticFnPtr warn_fn)
713 CYG_REPORT_FUNCNAMETYPE("CdlPackagesDatabase::make", "database %p");
715 // Where is the component repository? The location may come from the
716 // parent or from an environment variable ECOS_REPOSITORY
718 char *env = getenv("ECOS_REPOSITORY");
720 throw CdlInputOutputException(std::string("No component repository specified and no ") +
721 std::string("ECOS_REPOSITORY environment variable"));
727 // Replace any backslashes in the repository with forward slashes.
728 // The latter are used throughout the library
729 // NOTE: this is not i18n-friendly.
730 for (unsigned int i = 0; i < repo.size(); i++) {
731 if ('\\' == repo[i]) {
735 CdlPackagesDatabase result = new CdlPackagesDatabaseBody(repo, error_fn, warn_fn);
736 CYG_REPORT_RETVAL(result);
740 // ----------------------------------------------------------------------------
742 CdlPackagesDatabaseBody::CdlPackagesDatabaseBody(std::string repo, CdlDiagnosticFnPtr error_fn, CdlDiagnosticFnPtr warn_fn)
744 CYG_REPORT_FUNCNAME("CdlPackagesDatabase:: constructor");
745 CYG_PRECONDITIONC("" != repo);
747 // There will be calls to check_this() while the database is evaluated,
748 // so make sure that the database is valid first.
749 component_repository = repo;
750 cdlpackagesdatabasebody_cookie = CdlPackagesDatabaseBody_Magic;
752 // We want to read in the entire packages file. Portability problems
753 // can be largely eliminated by using a Tcl interpreter for this, but
754 // under Windows there is a problem if the pathname is a cygwin one.
755 // For now it is assumed that the supplied pathname is acceptable to
758 // No attempt is made at this stage to use a safe interpreter.
759 // Some file I/O operations are needed while processing the data,
760 // for example to check that a package is actually installed.
761 // Additional file I/O may prove useful in future, e.g. to create
762 // some or all of a database on the fly. Obviously some
763 // restrictions are desirable (no modify access to the repository,
764 // no network capabilities, and so on.) These have to be added
767 CdlInterpreter interp = CdlInterpreterBody::make();
771 CdlInterpreterBody::ContextSupport context(interp, database_name);
772 CdlInterpreterCommandEntry commands[] =
774 CdlInterpreterCommandEntry("package", &CdlDbParser::new_package ),
775 CdlInterpreterCommandEntry("target", &CdlDbParser::new_target ),
776 CdlInterpreterCommandEntry("", 0 )
778 CdlInterpreterBody::CommandSupport cmds(interp, commands);
779 CdlInterpreterBody::DiagSupport diag(interp, error_fn, warn_fn);
780 CdlInterpreterBody::AssocSupport assoc(interp, dbparser_database_key, static_cast<ClientData>(this));
781 CdlInterpreterBody::VariableSupport var(interp, dbparser_component_repository, repo);
782 interp->add_command("unknown", &CdlParse::unknown_command);
783 CdlParse::clear_error_count(interp);
785 // Ignore errors at this stage, instead check error count at the end.
786 (void) interp->eval_file(component_repository + "/" + database_name);
788 // Now start looking for templates. These should reside in the
789 // templates subdirectory of the component repository. Each template
790 // should be in its own directory, and inside each directory should
791 // be versioned template files with a .ect extension.
792 std::string templates_dir = repo + "/" + "templates";
793 std::vector<std::string> subdirs;
794 interp->locate_subdirs(templates_dir, subdirs);
797 for (i = 0; i < subdirs.size(); i++) {
798 // Do not add the template to the known ones until we are sure there is
799 // at least one valid template.
800 std::vector<std::string> files;
801 interp->locate_files(templates_dir + "/" + subdirs[i], files);
803 for (j = 0; j < files.size(); j++) {
804 if ((4 < files[j].size()) && (".ect" == files[j].substr(files[j].size() - 4))) {
808 if (j != files.size()) {
809 this->template_names.push_back(subdirs[i]);
810 for ( ; j < files.size(); j++) {
811 if ((4 < files[j].size()) && (".ect" == files[j].substr(files[j].size() - 4))) {
812 this->templates[subdirs[i]].versions.push_back(files[j].substr(0, files[j].size() - 4));
818 // Consistency checks. All target-specific packages should
819 // have the hardware attribute. Also, all the packages should
820 // exist. Problems only result in warnings and only when
821 // operating in verbose mode, to allow for somewhat
822 // inconsistent repositories e.g. an anoncvs tree.
823 if (CdlPackagesDatabaseBody::verbose_mode) {
824 std::vector<std::string>::const_iterator name_i;
825 std::vector<std::string>::const_iterator name_j;
826 for (name_i = target_names.begin(); name_i != target_names.end(); name_i++) {
827 for (name_j = targets[*name_i].packages.begin(); name_j != targets[*name_i].packages.end(); name_j++) {
828 if (std::find(package_names.begin(), package_names.end(), *name_j) == package_names.end()) {
829 CdlParse::report_warning(interp, diag_target + *name_i,
830 std::string("This target refers to an unknown package `") + *name_j + "'.");
832 if (!packages[*name_j].hardware) {
833 CdlParse::report_warning(interp, diag_target + *name_i,
834 std::string("This target refers to a package `") + *name_j +
835 "' that is not hardware-specific.");
840 // Now, were there any errors while reading in the database?
841 // If so it is necessary to throw an exception here, to make sure
842 // that things get cleaned up properly.
843 int error_count = CdlParse::get_error_count(interp);
844 if (0 != error_count) {
845 throw CdlInputOutputException("Invalid package database.");
848 // Something has gone wrong. Clear out all of the data accumulated so far, as well
849 // as the interpreter.
851 package_names.clear();
852 target_names.clear();
853 template_names.clear();
861 CYGDBG_MEMLEAK_CONSTRUCTOR();
867 //{{{ CdlPackagesDatabase:: destructor
869 // ----------------------------------------------------------------------------
870 CdlPackagesDatabaseBody::~CdlPackagesDatabaseBody()
872 CYG_REPORT_FUNCNAME("CdlPackagesDatabase:: default destructor");
873 CYG_REPORT_FUNCARG1XV(this);
874 CYG_PRECONDITION_THISC();
876 cdlpackagesdatabasebody_cookie = CdlPackagesDatabaseBody_Invalid;
877 component_repository = "";
878 package_names.clear();
879 target_names.clear();
880 template_names.clear();
885 CYGDBG_MEMLEAK_DESTRUCTOR();
891 //{{{ CdlPackagesDatabase:: check_this()
893 // ----------------------------------------------------------------------------
896 CdlPackagesDatabaseBody::check_this(cyg_assert_class_zeal zeal) const
898 if (CdlPackagesDatabaseBody_Magic != cdlpackagesdatabasebody_cookie) {
901 CYGDBG_MEMLEAK_CHECKTHIS();
904 case cyg_system_test :
907 std::vector<std::string>::const_iterator names_i;
908 std::map<std::string,package_data>::const_iterator pkgs_i;
910 // Every entry in the names vector should have an entry in the packages vector.
911 for (names_i = package_names.begin(); names_i != package_names.end(); names_i++) {
912 if (packages.find(*names_i) == packages.end()) {
916 // The inverse should be true as well
917 for (pkgs_i = packages.begin(); pkgs_i != packages.end(); pkgs_i++) {
918 if (std::find(package_names.begin(), package_names.end(), pkgs_i->first) == package_names.end()) {
923 // Repeat for targets.
924 std::map<std::string,target_data>::const_iterator targets_i;
925 for (names_i = target_names.begin(); names_i != target_names.end(); names_i++) {
926 if (targets.find(*names_i) == targets.end()) {
930 for (targets_i = targets.begin(); targets_i != targets.end(); targets_i++) {
931 if (std::find(target_names.begin(), target_names.end(), targets_i->first) == target_names.end()) {
937 std::map<std::string,template_data>::const_iterator templates_i;
938 for (names_i = template_names.begin(); names_i != template_names.end(); names_i++) {
939 if (templates.find(*names_i) == templates.end()) {
943 // The inverse should be true as well
944 for (templates_i = templates.begin(); templates_i != templates.end(); templates_i++) {
945 if (std::find(template_names.begin(), template_names.end(), templates_i->first) == template_names.end()) {
950 // Possibly the package directories should be validated as
951 // well, not to mention the various version subdirectories,
952 // but doing file I/O inside an assertion is excessive.
956 if ("" == component_repository) {
968 //{{{ CdlPackagesDatabase:: misc
970 // ----------------------------------------------------------------------------
973 CdlPackagesDatabaseBody::get_component_repository() const
975 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_component_repository");
976 CYG_REPORT_FUNCARG1XV(this);
977 CYG_PRECONDITION_THISC();
980 return component_repository;
984 CdlPackagesDatabaseBody::set_verbose(bool new_mode)
986 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::set_verbose");
987 CYG_REPORT_FUNCARG1XV(new_mode);
989 verbose_mode = new_mode;
995 //{{{ CdlPackagesDatabase:: get package information
997 // ----------------------------------------------------------------------------
999 const std::vector<std::string>&
1000 CdlPackagesDatabaseBody::get_packages(void) const
1002 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_packages");
1003 CYG_REPORT_FUNCARG1XV(this);
1004 CYG_PRECONDITION_THISC();
1006 CYG_REPORT_RETURN();
1007 return package_names;
1011 CdlPackagesDatabaseBody::is_known_package(std::string name) const
1013 CYG_REPORT_FUNCNAMETYPE("CdlPackagesDatabase::is_known_package", "result %d");
1014 CYG_REPORT_FUNCARG1XV(this);
1015 CYG_PRECONDITION_THISC();
1017 bool result = false;
1018 if (std::find(package_names.begin(), package_names.end(), name) != package_names.end()) {
1022 CYG_REPORT_RETVAL(result);
1027 CdlPackagesDatabaseBody::get_package_description(std::string pkg_name) const
1029 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_package_description");
1030 CYG_REPORT_FUNCARG1XV(this);
1031 CYG_PRECONDITION_THISC();
1033 std::map<std::string,package_data>::const_iterator pkgs_i = packages.find(pkg_name);
1034 if (pkgs_i != packages.end()) {
1035 CYG_REPORT_RETURN();
1036 return pkgs_i->second.description;
1039 CYG_FAIL("Invalid package name passed to CdlPackagesDatabase::get_package_description()");
1040 static std::string dummy = "";
1044 const std::vector<std::string>&
1045 CdlPackagesDatabaseBody::get_package_aliases(std::string pkg_name) const
1047 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_package_aliases");
1048 CYG_REPORT_FUNCARG1XV(this);
1049 CYG_PRECONDITION_THISC();
1051 std::map<std::string,package_data>::const_iterator pkgs_i = packages.find(pkg_name);
1052 if (pkgs_i != packages.end()) {
1053 CYG_REPORT_RETURN();
1054 return pkgs_i->second.aliases;
1057 CYG_FAIL("Invalid package name passed to CdlPackagesDatabase::get_package_aliases()");
1058 static std::vector<std::string> dummy;
1062 const std::vector<std::string>&
1063 CdlPackagesDatabaseBody::get_package_versions(std::string pkg_name) const
1065 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_package_versions");
1066 CYG_REPORT_FUNCARG1XV(this);
1067 CYG_PRECONDITION_THISC();
1069 std::map<std::string,package_data>::const_iterator pkgs_i = packages.find(pkg_name);
1070 if (pkgs_i != packages.end()) {
1071 CYG_REPORT_RETURN();
1072 return pkgs_i->second.versions;
1075 CYG_FAIL("Invalid package name passed to CdlPackagesDatabase::get_package_versions()");
1076 static std::vector<std::string> dummy;
1081 CdlPackagesDatabaseBody::get_package_directory(std::string pkg_name) const
1083 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_package_directory");
1084 CYG_REPORT_FUNCARG1XV(this);
1085 CYG_PRECONDITION_THISC();
1087 std::map<std::string,package_data>::const_iterator pkgs_i = packages.find(pkg_name);
1088 if (pkgs_i != packages.end()) {
1089 CYG_REPORT_RETURN();
1090 return pkgs_i->second.directory;
1093 CYG_FAIL("Invalid package name passed to CdlPackagesDatabase::get_package_directory()");
1094 static std::string dummy = "";
1099 CdlPackagesDatabaseBody::get_package_script(std::string pkg_name) const
1101 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_package_script");
1102 CYG_REPORT_FUNCARG1XV(this);
1103 CYG_PRECONDITION_THISC();
1105 std::map<std::string,package_data>::const_iterator pkgs_i = packages.find(pkg_name);
1106 if (pkgs_i != packages.end()) {
1107 CYG_REPORT_RETURN();
1108 return pkgs_i->second.script;
1111 CYG_FAIL("Invalid package name passed to CdlPackagesDatabase::get_package_script()");
1112 static std::string dummy = "";
1117 CdlPackagesDatabaseBody::is_hardware_package(std::string pkg_name) const
1119 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::is_hardware_package");
1120 CYG_REPORT_FUNCARG1XV(this);
1121 CYG_PRECONDITION_THISC();
1123 std::map<std::string,package_data>::const_iterator pkgs_i = packages.find(pkg_name);
1124 if (pkgs_i != packages.end()) {
1125 CYG_REPORT_RETURN();
1126 return pkgs_i->second.hardware;
1129 CYG_FAIL("Invalid package name passed to CdlPackagesDatabase::is_hardware_package()");
1134 //{{{ CdlPackagesDatabase:: get target information
1136 // ----------------------------------------------------------------------------
1138 const std::vector<std::string>&
1139 CdlPackagesDatabaseBody::get_targets(void) const
1141 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_targets");
1142 CYG_PRECONDITION_THISC();
1144 CYG_REPORT_RETURN();
1145 return target_names;
1149 CdlPackagesDatabaseBody::is_known_target(std::string name) const
1151 CYG_REPORT_FUNCNAMETYPE("CdlPackagesDatabase::is_known_target", "result %d");
1152 CYG_REPORT_FUNCARG1XV(this);
1153 CYG_PRECONDITION_THISC();
1155 bool result = false;
1156 if (std::find(target_names.begin(), target_names.end(), name) != target_names.end()) {
1160 CYG_REPORT_RETVAL(result);
1165 CdlPackagesDatabaseBody::get_target_description(std::string target_name) const
1167 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_target_description");
1168 CYG_PRECONDITION_THISC();
1170 std::map<std::string,target_data>::const_iterator target_i = targets.find(target_name);
1171 if (target_i != targets.end()) {
1172 CYG_REPORT_RETURN();
1173 return target_i->second.description;
1176 CYG_FAIL("Invalid target name passed to CdlPackagesDatabase::get_target_description()");
1177 static std::string dummy = "";
1181 const std::vector<std::string>&
1182 CdlPackagesDatabaseBody::get_target_aliases(std::string target_name) const
1184 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_target_aliases");
1185 CYG_PRECONDITION_THISC();
1187 std::map<std::string,target_data>::const_iterator target_i = targets.find(target_name);
1188 if (target_i != targets.end()) {
1189 CYG_REPORT_RETURN();
1190 return target_i->second.aliases;
1193 CYG_FAIL("Invalid target name passed to CdlPackagesDatabase::get_target_aliases()");
1194 static std::vector<std::string> dummy;
1198 const std::vector<std::string>&
1199 CdlPackagesDatabaseBody::get_target_packages(std::string target_name) const
1201 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_target_packages");
1202 CYG_PRECONDITION_THISC();
1204 std::map<std::string,target_data>::const_iterator target_i = targets.find(target_name);
1205 if (target_i != targets.end()) {
1206 CYG_REPORT_RETURN();
1207 return target_i->second.packages;
1210 CYG_FAIL("Invalid target name passed to CdlPackagesDatabase::get_target_packages()");
1211 static std::vector<std::string> dummy;
1215 const std::vector<std::string>&
1216 CdlPackagesDatabaseBody::get_target_enables(std::string target_name) const
1218 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_target_enables");
1219 CYG_PRECONDITION_THISC();
1221 std::map<std::string,target_data>::const_iterator target_i = this->targets.find(target_name);
1222 if (target_i != this->targets.end()) {
1223 CYG_REPORT_RETURN();
1224 return target_i->second.enable;
1227 CYG_FAIL("Invalid target name passed to CdlPackagesDatabase::get_target_enables()");
1228 static std::vector<std::string> dummy;
1232 const std::vector<std::string>&
1233 CdlPackagesDatabaseBody::get_target_disables(std::string target_name) const
1235 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_target_disables");
1236 CYG_PRECONDITION_THISC();
1238 std::map<std::string,target_data>::const_iterator target_i = this->targets.find(target_name);
1239 if (target_i != this->targets.end()) {
1240 CYG_REPORT_RETURN();
1241 return target_i->second.disable;
1244 CYG_FAIL("Invalid target name passed to CdlPackagesDatabase::get_target_disables()");
1245 static std::vector<std::string> dummy;
1249 const std::vector<std::pair<std::string, std::string> >&
1250 CdlPackagesDatabaseBody::get_target_set_values(std::string target_name) const
1252 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_target_set_values");
1253 CYG_PRECONDITION_THISC();
1255 std::map<std::string,target_data>::const_iterator target_i = this->targets.find(target_name);
1256 if (target_i != this->targets.end()) {
1257 CYG_REPORT_RETURN();
1258 return target_i->second.set_values;
1261 CYG_FAIL("Invalid target name passed to CdlPackagesDatabase::get_target_values()");
1262 static std::vector<std::pair<std::string, std::string> > dummy;
1267 //{{{ CdlPackagesDatabase:: get template information
1269 // ----------------------------------------------------------------------------
1270 // Templates are different from packages and targets. The ecos.db file
1271 // does not contain all the information in one convenient file, instead
1272 // it is necessary to trawl through a templates sub-directory of the
1273 // component repository. There are no aliases. Descriptions can be obtained
1274 // only by executing the template file in a suitable interpreter.
1276 const std::vector<std::string>&
1277 CdlPackagesDatabaseBody::get_templates(void) const
1279 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_templates");
1280 CYG_PRECONDITION_THISC();
1282 CYG_REPORT_RETURN();
1283 return template_names;
1287 CdlPackagesDatabaseBody::is_known_template(std::string name) const
1289 CYG_REPORT_FUNCNAMETYPE("CdlPackagesDatabase::is_known_template", "result %d");
1290 CYG_REPORT_FUNCARG1XV(this);
1291 CYG_PRECONDITION_THISC();
1293 bool result = false;
1294 if (std::find(template_names.begin(), template_names.end(), name) != template_names.end()) {
1298 CYG_REPORT_RETVAL(result);
1302 const std::vector<std::string>&
1303 CdlPackagesDatabaseBody::get_template_versions(std::string template_name) const
1305 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_template_versions");
1306 CYG_REPORT_FUNCARG1XV(this);
1307 CYG_PRECONDITION_THISC();
1309 std::map<std::string,template_data>::const_iterator template_i = templates.find(template_name);
1310 if (template_i != templates.end()) {
1311 CYG_REPORT_RETURN();
1312 return template_i->second.versions;
1315 CYG_FAIL("Invalid template name passed to CdlPackagesDatabase::get_template_versions()");
1316 static std::vector<std::string> dummy;
1321 CdlPackagesDatabaseBody::get_template_filename(std::string template_name, std::string version_name) const
1323 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_template_filename");
1324 CYG_REPORT_FUNCARG1XV(this);
1325 CYG_PRECONDITION_THISC();
1327 // Given the way templates are identified, the filename can be determined
1328 // easily by concatenating a few strings. The only complication is that
1329 // version_name may be an empty string, indicating that the most recent
1330 // version should be used.
1331 std::map<std::string,template_data>::const_iterator template_i = templates.find(template_name);
1332 if (template_i == templates.end()) {
1333 CYG_FAIL("Invalid template name passed to CdlPackagesDatabase::get_template_filename");
1334 CYG_REPORT_RETURN();
1337 if ("" == version_name) {
1338 CYG_ASSERTC(0 != template_i->second.versions.size());
1339 version_name = template_i->second.versions[0];
1341 std::vector<std::string>::const_iterator vsn_i = std::find(template_i->second.versions.begin(),
1342 template_i->second.versions.end(), version_name);
1343 if (vsn_i == template_i->second.versions.end()) {
1344 CYG_FAIL("Invalid template version passed to CdlPackagesDatabase::get_template_filename");
1345 CYG_REPORT_RETURN();
1350 std::string result = component_repository + "/templates/" + template_name + "/" + version_name + ".ect";
1351 CYG_REPORT_RETURN();
1355 // ----------------------------------------------------------------------------
1356 // The descriptions now live in an eCos savefile, i.e. a Tcl script, so
1357 // extracting them can be relatively expensive and needs to happen on
1358 // a just-in-time basis.
1361 CdlPackagesDatabaseBody::get_template_description(std::string template_name, std::string version_name)
1363 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_template_description");
1364 CYG_REPORT_FUNCARG1XV(this);
1365 CYG_PRECONDITION_THISC();
1367 // Is this a known template?
1368 std::map<std::string, struct template_data>::iterator template_i = templates.find(template_name);
1369 if (template_i == templates.end()) {
1370 CYG_FAIL("Invalid template name passed to CdlPackagesDatabase::get_template_description");
1371 CYG_REPORT_RETURN();
1375 // Is it a known version of the template?
1376 if ("" == version_name) {
1377 CYG_ASSERTC(0 != template_i->second.versions.size());
1378 version_name = template_i->second.versions[0];
1380 if (std::find(template_i->second.versions.begin(), template_i->second.versions.end(), version_name) ==
1381 template_i->second.versions.end()) {
1383 CYG_FAIL("Invalid template version passed to CdlPackagesDatabase::get_template_description");
1384 CYG_REPORT_RETURN();
1389 // We have a valid template and version. Has the version file in
1390 // question been read in yet?
1391 std::map<std::string, struct template_version_data>::iterator version_i;
1392 version_i = template_i->second.version_details.find(version_name);
1393 if (version_i != template_i->second.version_details.end()) {
1394 CYG_REPORT_RETURN();
1395 return version_i->second.description;
1398 std::string filename = this->get_template_filename(template_name, version_name);
1399 if ("" == filename) {
1400 CYG_REPORT_RETURN();
1403 extract_template_details(filename, template_i->second.version_details[version_name].description,
1404 template_i->second.version_details[version_name].packages);
1405 CYG_REPORT_RETURN();
1406 return template_i->second.version_details[version_name].description;
1409 // ----------------------------------------------------------------------------
1410 // Similarly extracting package information needs to happen on a
1411 // just-in-time basis.
1412 const std::vector<std::string>&
1413 CdlPackagesDatabaseBody::get_template_packages(std::string template_name, std::string version_name)
1415 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_template_packages");
1416 CYG_REPORT_FUNCARG1XV(this);
1417 CYG_PRECONDITION_THISC();
1419 static std::vector<std::string> dummy;
1421 // Is this a known template?
1422 std::map<std::string, struct template_data>::iterator template_i = templates.find(template_name);
1423 if (template_i == templates.end()) {
1424 CYG_FAIL("Invalid template name passed to CdlPackagesDatabase::get_template_packages");
1425 CYG_REPORT_RETURN();
1429 // Is it a known version of the template?
1430 if ("" == version_name) {
1431 CYG_ASSERTC(0 != template_i->second.versions.size());
1432 version_name = template_i->second.versions[0];
1434 if (std::find(template_i->second.versions.begin(), template_i->second.versions.end(), version_name) ==
1435 template_i->second.versions.end()) {
1437 CYG_FAIL("Invalid template version passed to CdlPackagesDatabase::get_packages");
1438 CYG_REPORT_RETURN();
1443 // We have a valid template and version. Has the version file in
1444 // question been read in yet?
1445 std::map<std::string, struct template_version_data>::iterator version_i;
1446 version_i = template_i->second.version_details.find(version_name);
1447 if (version_i != template_i->second.version_details.end()) {
1448 CYG_REPORT_RETURN();
1449 return version_i->second.packages;
1452 std::string filename = this->get_template_filename(template_name, version_name);
1453 if ("" == filename) {
1454 CYG_REPORT_RETURN();
1457 extract_template_details(filename, template_i->second.version_details[version_name].description,
1458 template_i->second.version_details[version_name].packages);
1459 CYG_REPORT_RETURN();
1460 return template_i->second.version_details[version_name].packages;
1463 // ----------------------------------------------------------------------------
1464 // Extracting the description and package information involves running
1465 // the script through a Tcl interpreter extended with the appropriate
1466 // commands. Most of the savefile information is irrelevant and is handled
1467 // by extract_ignore(). The commands of interest are cdl_configuration and
1468 // its sub-commands description and package.
1471 extract_ignore(CdlInterpreter interp, int argc, const char* argv[])
1477 extract_cdl_configuration(CdlInterpreter interp, int argc, const char* argv[])
1479 CYG_REPORT_FUNCNAMETYPE("extract_cdl_configuration", "result %d");
1480 CYG_REPORT_FUNCARG2XV(interp, argc);
1481 CYG_PRECONDITION_CLASSC(interp);
1483 int result = TCL_OK;
1485 // usage: cdl_configuration <name> <body>
1487 interp->set_result("Invalid cdl_configuration command in template, expecting two arguments");
1490 // Ignore the first argument for now.
1492 result = interp->eval(argv[2], tmp);
1494 // After processing the cdl_configuration command the description and
1495 // package information should be known. There is no point in processing
1496 // the rest of the file.
1497 if (TCL_OK == result) {
1498 interp->set_result("OK");
1503 CYG_REPORT_RETVAL(result);
1508 extract_cdl_description(CdlInterpreter interp, int argc, const char* argv[])
1510 CYG_REPORT_FUNCNAMETYPE("extract_cdl_description", "result %d");
1511 CYG_REPORT_FUNCARG2XV(interp, argc);
1512 CYG_PRECONDITION_CLASSC(interp);
1514 int result = TCL_OK;
1516 // usage: package <name>
1518 interp->set_result("Invalid description command in template, expecting just one argument");
1521 ClientData client_data = interp->get_assoc_data(template_description_key);
1522 CYG_ASSERTC(0 != client_data);
1523 std::string* result_ptr = static_cast<std::string*>(client_data);
1524 *result_ptr = argv[1];
1527 CYG_REPORT_RETVAL(result);
1532 extract_cdl_package(CdlInterpreter interp, int argc, const char* argv[])
1534 CYG_REPORT_FUNCNAMETYPE("extract_cdl_package", "result %d");
1535 CYG_REPORT_FUNCARG2XV(interp, argc);
1536 CYG_PRECONDITION_CLASSC(interp);
1538 int result = TCL_OK;
1540 // usage: package <name> <version>
1542 interp->set_result("Invalid package command in template, expecting two arguments");
1545 ClientData client_data = interp->get_assoc_data(template_packages_key);
1546 CYG_ASSERTC(0 != client_data);
1547 std::vector<std::string>* result_ptr = static_cast<std::vector<std::string>*>(client_data);
1548 result_ptr->push_back(argv[1]);
1550 CYG_REPORT_RETVAL(result);
1556 CdlPackagesDatabaseBody::extract_template_details(std::string filename, std::string& description,
1557 std::vector<std::string>& packages)
1559 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::extract_template_description");
1561 CdlInterpreter interp = CdlInterpreterBody::make();
1562 interp->set_assoc_data(template_description_key, static_cast<ClientData>(&description));
1563 interp->set_assoc_data(template_packages_key, static_cast<ClientData>(&packages));
1564 static CdlInterpreterCommandEntry extract_commands[] =
1566 CdlInterpreterCommandEntry("cdl_savefile_version", &extract_ignore ),
1567 CdlInterpreterCommandEntry("cdl_savefile_command", &extract_ignore ),
1568 CdlInterpreterCommandEntry("cdl_configuration", &extract_cdl_configuration ),
1569 CdlInterpreterCommandEntry("hardware", &extract_ignore ),
1570 CdlInterpreterCommandEntry("template", &extract_ignore ),
1571 CdlInterpreterCommandEntry("description", &extract_cdl_description ),
1572 CdlInterpreterCommandEntry("package", &extract_cdl_package ),
1573 CdlInterpreterCommandEntry("unknown", &extract_ignore ),
1574 CdlInterpreterCommandEntry("", 0 )
1576 std::vector<CdlInterpreterCommandEntry> new_commands;
1577 for (int i = 0; 0 != extract_commands[i].command; i++) {
1578 new_commands.push_back(extract_commands[i]);
1580 interp->push_commands(new_commands);
1583 int result = interp->eval_file(filename, tmp);
1584 // Special escape mechanism, see extract_cdl_configuration() above
1585 if ((TCL_ERROR == result) && ("OK" == tmp)) {
1589 if (TCL_OK != result) {
1590 // No obvious way of recovering just yet
1595 CYG_REPORT_RETURN();
1599 //{{{ CdlPackagesDatabase:: get_valid_cflags()
1601 // ----------------------------------------------------------------------------
1603 const std::vector<std::string>&
1604 CdlPackagesDatabaseBody::get_valid_cflags()
1606 CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_valid_compiler_flags");
1608 static std::vector<std::string> result_vec;
1609 static const char* valid_flags[] = {
1610 "ARCHFLAGS", "CARCHFLAGS", "CXXARCHFLAGS", "LDARCHFLAGS",
1611 "ERRFLAGS", "CERRFLAGS", "CXXERRFLAGS", "LDERRFLAGS",
1612 "LANGFLAGS", "CLANGFLAGS", "CXXLANGFLAGS", "LDLANGFLAGS",
1613 "DBGFLAGS", "CDBGFLAGS", "CXXDBGFLAGS", "LDDBGFLAGS",
1614 "EXTRAFLAGS", "CEXTRAFLAGS", "CXXEXTRAFLAGS", "LDEXTRAFLAGS",
1618 if (0 == result_vec.size()) {
1619 for (int i = 0; 0 != valid_flags[i]; i++) {
1620 result_vec.push_back(valid_flags[i]);
1623 CYG_REPORT_RETURN();