|
|
| 46 |
from bake.Exceptions import TaskError |
46 |
from bake.Exceptions import TaskError |
| 47 |
from bake.ModuleSource import SystemDependency |
47 |
from bake.ModuleSource import SystemDependency |
| 48 |
from bake.ModuleBuild import NoneModuleBuild |
48 |
from bake.ModuleBuild import NoneModuleBuild |
|
|
49 |
from bake.Module import ModuleDependency |
| 49 |
|
50 |
|
| 50 |
def signal_handler(signal, frame): |
51 |
def signal_handler(signal, frame): |
| 51 |
""" Handles Ctrl+C keyboard interruptions """ |
52 |
""" Handles Ctrl+C keyboard interruptions """ |
|
|
| 89 |
|
90 |
|
| 90 |
parser = OptionParser(usage='usage: %prog fix-config [options]') |
91 |
parser = OptionParser(usage='usage: %prog fix-config [options]') |
| 91 |
self._enable_disable_options(parser) |
92 |
self._enable_disable_options(parser) |
| 92 |
parser.add_option("-c", "--conffile", action="store", type="string", |
93 |
parser.add_option("-f", "--conffile", action="store", type="string", |
| 93 |
dest="bakeconf", default="bakeconf.xml", |
94 |
dest="bakeconf", default="bakeconf.xml", |
| 94 |
help="The Bake meta-data configuration from where to" |
95 |
help="The Bake meta-data configuration from where to" |
| 95 |
" get the updated modules file to use. Default: %default.") |
96 |
" get the updated modules file to use. Default: %default.") |
|
|
| 117 |
|
118 |
|
| 118 |
config = self.check_configuration_file(config, True) |
119 |
config = self.check_configuration_file(config, True) |
| 119 |
|
120 |
|
|
|
121 |
contribconf = [] |
| 122 |
try: |
| 123 |
for cfile in os.listdir("contrib"): |
| 124 |
if cfile.endswith(".xml"): |
| 125 |
contribconf.append("contrib/"+cfile) |
| 126 |
except Exception as e: |
| 127 |
True |
| 128 |
|
| 120 |
# Stores the present configuration |
129 |
# Stores the present configuration |
| 121 |
old_config = Configuration(config) |
130 |
old_config = Configuration(config) |
| 122 |
old_config.read() |
131 |
old_config.read() |
|
|
| 133 |
new_config.read_metadata(options.bakeconf) |
142 |
new_config.read_metadata(options.bakeconf) |
| 134 |
except Exception as e: |
143 |
except Exception as e: |
| 135 |
self._error('Problem reading Configuration file "%s" \n Error: %s' % (options.bakeconf, str(e))) |
144 |
self._error('Problem reading Configuration file "%s" \n Error: %s' % (options.bakeconf, str(e))) |
|
|
145 |
|
| 146 |
for cconf in contribconf: |
| 147 |
try: |
| 148 |
new_config.read_metadata(cconf) |
| 149 |
except Exception as e: |
| 150 |
self._error('Problem reading Configuration file "%s" \n Error: %s' % (cconf, str(e))) |
| 136 |
|
151 |
|
| 137 |
# Checks if the directories where set and if so set the new config file |
152 |
# Checks if the directories where set and if so set the new config file |
| 138 |
# with the new parameters, or let the old ones |
153 |
# with the new parameters, or let the old ones |
|
|
| 207 |
dest="enable_minimal", default=None, |
222 |
dest="enable_minimal", default=None, |
| 208 |
help="Disable all non-mandatory dependencies.") |
223 |
help="Disable all non-mandatory dependencies.") |
| 209 |
|
224 |
|
|
|
225 |
def resolve_contrib_dependencies (self, module, fmod, configuration): |
| 226 |
""" Handles the contrib type dependencies""" |
| 227 |
for dep in module.dependencies (): |
| 228 |
dep_mod = configuration.lookup (dep.name()) |
| 229 |
if dep_mod.mtype() == "ns-contrib": |
| 230 |
dep_mod.get_source().attribute("module_directory").value = fmod+'/contrib/'+dep_mod.get_source().attribute("module_directory").value |
| 231 |
dep_mod.addDependencies(ModuleDependency(fmod, False)) |
| 232 |
self.resolve_contrib_dependencies (dep_mod, fmod, configuration) |
| 233 |
|
| 210 |
def _enable(self, enable, configuration): |
234 |
def _enable(self, enable, configuration): |
| 211 |
""" Handles the --enable option, setting defined modules as enable.""" |
235 |
""" Handles the --enable option, setting defined modules as enable.""" |
| 212 |
|
|
|
| 213 |
for module_name in enable: |
236 |
for module_name in enable: |
| 214 |
module = configuration.lookup(module_name) |
237 |
module = configuration.lookup(module_name) |
| 215 |
if not module: |
238 |
if not module: |
| 216 |
self._error('Module "%s" not found' % module_name) |
239 |
self._error('Module "%s" not found' % module_name) |
|
|
240 |
if module.mtype() == "ns-contrib": |
| 241 |
found=0 |
| 242 |
fmod = None |
| 243 |
for mod in enable: |
| 244 |
if configuration.lookup(mod).mtype() == "ns" and ((mod>=module.minver() and (mod<=module.maxver() or module.maxver() == None)) or (mod == "ns-3-dev" and module.maxver() == None)): |
| 245 |
found+= 1 |
| 246 |
fmod = mod |
| 247 |
if not found==1: |
| 248 |
self._error('Module "%s" has unmet dependency: %s' % (module_name, module.minver())) |
| 249 |
module.get_source().attribute("module_directory").value = fmod+'/contrib/'+module.get_source().attribute("module_directory").value |
| 250 |
module.addDependencies(ModuleDependency(fmod, False)) |
| 251 |
self.resolve_contrib_dependencies (module, fmod, configuration) |
| 217 |
configuration.enable(module) |
252 |
configuration.enable(module) |
| 218 |
|
253 |
|
| 219 |
def _disable(self, disable, configuration): |
254 |
def _disable(self, disable, configuration): |
|
|
| 224 |
if not module: |
259 |
if not module: |
| 225 |
self._error('Module "%s" not found' % module_name) |
260 |
self._error('Module "%s" not found' % module_name) |
| 226 |
configuration.disable(module) |
261 |
configuration.disable(module) |
|
|
262 |
if module.mtype() == "ns": |
| 263 |
enabled_list = configuration.enabled() |
| 264 |
for mod in enabled_list: |
| 265 |
if mod.mtype() == "ns-contrib": |
| 266 |
configuration.disable(mod) |
| 227 |
|
267 |
|
| 228 |
def _variables_process(self, items, configuration, is_append): |
268 |
def _variables_process(self, items, configuration, is_append): |
| 229 |
""" Handles the defined configured variables .""" |
269 |
""" Handles the defined configured variables .""" |
|
|
| 257 |
|
297 |
|
| 258 |
# enables/disables the explicit enable/disable modules passed as argument |
298 |
# enables/disables the explicit enable/disable modules passed as argument |
| 259 |
self._enable(options.enable, configuration) |
299 |
self._enable(options.enable, configuration) |
|
|
300 |
for mod in options.disable: |
| 301 |
if not mod in options.enable: |
| 302 |
self._error('Module "%s" not enabled' % mod) |
| 260 |
self._disable(options.disable, configuration) |
303 |
self._disable(options.disable, configuration) |
| 261 |
|
304 |
|
| 262 |
# if the option -a is used, meaning all the modules should be enabled |
305 |
# if the option -a is used, meaning all the modules should be enabled |
| 263 |
if options.enable_all: |
306 |
if options.enable_all: |
| 264 |
for module in configuration.modules(): |
307 |
for module in configuration.modules(): |
| 265 |
configuration.enable(module) |
308 |
configuration.enable(module) |
|
|
309 |
|
| 266 |
|
310 |
|
| 267 |
# if the option -m is used, meaning the minimum configuration should be used |
311 |
# if the option -m is used, meaning the minimum configuration should be used |
| 268 |
# it disables all the non mandatory dependencies |
312 |
# it disables all the non mandatory dependencies |
|
|
| 382 |
configuration.append(lastConfig) |
426 |
configuration.append(lastConfig) |
| 383 |
self.save_resource_file(configuration, fileName) |
427 |
self.save_resource_file(configuration, fileName) |
| 384 |
|
428 |
|
|
|
429 |
def _list(self, config, args): |
| 430 |
""" Handles the list option for %prog """ |
| 431 |
|
| 432 |
# sets the options the parser should recognize for the configuration |
| 433 |
parser = OptionParser(usage='usage: %prog list [options]') |
| 434 |
parser.add_option("-f", "--conffile", action="store", type="string", |
| 435 |
dest="bakeconf", default="bakeconf.xml", |
| 436 |
help="The Bake meta-data configuration file to use. " |
| 437 |
"Default: %default.") |
| 438 |
parser.add_option("-c", "--contrib", action="store_true", |
| 439 |
dest="contrib", default="False", |
| 440 |
help="Show only contrib modules.") |
| 441 |
(options, args_left) = parser.parse_args(args) |
| 442 |
listconf = Configuration(config) |
| 443 |
contrib_list = [] |
| 444 |
module_list = [] |
| 445 |
|
| 446 |
contribconf = [] |
| 447 |
try: |
| 448 |
for cfile in os.listdir("contrib"): |
| 449 |
if cfile.endswith(".xml"): |
| 450 |
contribconf.append("contrib/"+cfile) |
| 451 |
except Exception as e: |
| 452 |
True |
| 453 |
|
| 454 |
try: |
| 455 |
listconf.read_metadata(options.bakeconf) |
| 456 |
except Exception as e: |
| 457 |
self._error('Problem reading Configuration file "%s" \n Error: %s' % (options.bakeconf, str(e))) |
| 458 |
|
| 459 |
for cconf in contribconf: |
| 460 |
try: |
| 461 |
listconf.read_metadata(cconf) |
| 462 |
except Exception as e: |
| 463 |
self._error('Problem reading Configuration file "%s" \n Error: %s' % (cconf, str(e))) |
| 464 |
|
| 465 |
for mod in listconf.modules(): |
| 466 |
if mod.mtype() == "ns-contrib": |
| 467 |
contrib_list.append(mod.name()) |
| 468 |
elif not options.contrib == True: |
| 469 |
module_list.append(mod.name()) |
| 470 |
|
| 471 |
contrib_list.sort() |
| 472 |
module_list.sort() |
| 473 |
for m in module_list: |
| 474 |
print("module: "+m) |
| 475 |
for c in contrib_list: |
| 476 |
print("contrib: "+c) |
| 385 |
|
477 |
|
| 386 |
def _configure(self, config, args): |
478 |
def _configure(self, config, args): |
| 387 |
""" Handles the configuration option for %prog """ |
479 |
""" Handles the configuration option for %prog """ |
|
|
| 389 |
# sets the options the parser should recognize for the configuration |
481 |
# sets the options the parser should recognize for the configuration |
| 390 |
parser = OptionParser(usage='usage: %prog configure [options]') |
482 |
parser = OptionParser(usage='usage: %prog configure [options]') |
| 391 |
self._enable_disable_options(parser) |
483 |
self._enable_disable_options(parser) |
| 392 |
parser.add_option("-c", "--conffile", action="store", type="string", |
484 |
parser.add_option("-f", "--conffile", action="store", type="string", |
| 393 |
dest="bakeconf", default="bakeconf.xml", |
485 |
dest="bakeconf", default="bakeconf.xml", |
| 394 |
help="The Bake meta-data configuration file to use. " |
486 |
help="The Bake meta-data configuration file to use. " |
| 395 |
"Default: %default.") |
487 |
"Default: %default.") |
|
|
| 432 |
default=0, help='Increase the log verbosity level') |
524 |
default=0, help='Increase the log verbosity level') |
| 433 |
parser.add_option('-q', '--quiet', action='count', dest='quiet', |
525 |
parser.add_option('-q', '--quiet', action='count', dest='quiet', |
| 434 |
default=0, help='Increase the log quietness level') |
526 |
default=0, help='Increase the log quietness level') |
|
|
527 |
parser.add_option("-c", "--clean", action="store_true", |
| 528 |
dest="remove", default=False, |
| 529 |
help="Remove all enabled modules") |
| 435 |
|
530 |
|
| 436 |
# sets the configuration values got from the line command |
531 |
# sets the configuration values got from the line command |
| 437 |
(options, args_left) = parser.parse_args(args) |
532 |
(options, args_left) = parser.parse_args(args) |
| 438 |
|
|
|
| 439 |
if options.bakeconf == "bakeconf.xml": |
533 |
if options.bakeconf == "bakeconf.xml": |
| 440 |
options.bakeconf = self.check_configuration_file(options.bakeconf, False); |
534 |
options.bakeconf = self.check_configuration_file(options.bakeconf, False); |
| 441 |
|
535 |
|
|
|
536 |
contribconf = [] |
| 537 |
try: |
| 538 |
for cfile in os.listdir("contrib"): |
| 539 |
if cfile.endswith(".xml"): |
| 540 |
contribconf.append("contrib/"+cfile) |
| 541 |
except Exception as e: |
| 542 |
True |
| 543 |
|
| 442 |
configuration = Configuration(config) |
544 |
configuration = Configuration(config) |
|
|
545 |
|
| 546 |
if not options.remove: |
| 547 |
try: |
| 548 |
configuration.read() |
| 549 |
for m in configuration.enabled(): |
| 550 |
if m.name() not in options.enable: |
| 551 |
options.enable.append(m.name()) |
| 552 |
except Exception as e: |
| 553 |
True |
| 554 |
|
| 443 |
try: |
555 |
try: |
| 444 |
configuration.read_metadata(options.bakeconf) |
556 |
configuration.read_metadata(options.bakeconf) |
| 445 |
except Exception as e: |
557 |
except Exception as e: |
| 446 |
self._error('Problem reading Configuration file "%s" \n Error: %s' % (options.bakeconf, str(e))) |
558 |
self._error('Problem reading Configuration file "%s" \n Error: %s' % (options.bakeconf, str(e))) |
|
|
559 |
|
| 560 |
for cconf in contribconf: |
| 561 |
try: |
| 562 |
configuration.read_metadata(cconf) |
| 563 |
except Exception as e: |
| 564 |
self._error('Problem reading Configuration file "%s" \n Error: %s' % (cconf, str(e))) |
| 447 |
|
565 |
|
| 448 |
configuration.set_sourcedir(options.sourcedir) |
566 |
configuration.set_sourcedir(options.sourcedir) |
| 449 |
configuration.set_objdir(options.objdir) |
567 |
configuration.set_objdir(options.objdir) |
|
|
| 490 |
self._error('--predefined: "%s" not found.' % p) |
608 |
self._error('--predefined: "%s" not found.' % p) |
| 491 |
|
609 |
|
| 492 |
# Registers the modules are that enabled/disabled |
610 |
# Registers the modules are that enabled/disabled |
| 493 |
# handles the -a, -m, --disable, --enable tags |
611 |
# handles the -a, -m, --disable, --enable tags |
| 494 |
self._parse_enable_disable(options, configuration) |
612 |
self._parse_enable_disable(options, configuration) |
| 495 |
|
613 |
|
| 496 |
# handles the set command line option, to overwrite the specific |
614 |
# handles the set command line option, to overwrite the specific |
| 497 |
# module setting with the new specified value |
615 |
# module setting with the new specified value |
| 498 |
for variable in options.set: |
616 |
for variable in options.set: |
|
|
| 509 |
module.get_build().attribute(name).value = current_value + ' ' + value |
627 |
module.get_build().attribute(name).value = current_value + ' ' + value |
| 510 |
configuration.write() |
628 |
configuration.write() |
| 511 |
|
629 |
|
| 512 |
if not configuration._enabled and not options.append : |
630 |
if not configuration._enabled and not options.append and not options.remove: |
| 513 |
env = self._get_dummy_env(options) |
631 |
env = self._get_dummy_env(options) |
| 514 |
env._logger.commands.write(' > No module enabled: Bake configuration requires at least one module to be enabled' |
632 |
env._logger.commands.write(' > No module enabled: Bake configuration requires at least one module to be enabled' |
| 515 |
' (enable, predefined), or appended.\n' |
633 |
' (enable, predefined), or appended.\n' |
|
|
| 1116 |
if not state: |
1234 |
if not state: |
| 1117 |
return |
1235 |
return |
| 1118 |
for mod in state: |
1236 |
for mod in state: |
| 1119 |
print('module: %s (%s)' % (mod.name(), label)) |
1237 |
if mod.mtype(): |
|
|
1238 |
print('module %s: %s (%s)' % (mod.mtype(), mod.name(), label)) |
| 1239 |
else: |
| 1240 |
print('module: %s (%s)' % (mod.name(), label)) |
| 1120 |
dependencies = mod.dependencies() |
1241 |
dependencies = mod.dependencies() |
| 1121 |
|
1242 |
|
| 1122 |
# Stores the system dependencies |
1243 |
# Stores the system dependencies |
|
|
| 1127 |
if not mod.name() in depen: |
1248 |
if not mod.name() in depen: |
| 1128 |
depen[mod.name()] = dict() |
1249 |
depen[mod.name()] = dict() |
| 1129 |
|
1250 |
|
| 1130 |
if dependencies: |
1251 |
if dependencies and not options.brief == True: |
| 1131 |
print(' depends on:') |
1252 |
print(' depends on:') |
| 1132 |
for dependsOn in mod.dependencies(): |
1253 |
for dependsOn in mod.dependencies(): |
| 1133 |
print(' %s (optional:%s)' % |
1254 |
print(' %s (optional:%s)' % |
| 1134 |
(dependsOn.name(), dependsOn.is_optional())) |
1255 |
(dependsOn.name(), dependsOn.is_optional())) |
| 1135 |
depen[mod.name()][dependsOn.name()]= dependsOn.is_optional() |
1256 |
depen[mod.name()][dependsOn.name()]= dependsOn.is_optional() |
| 1136 |
else: |
1257 |
elif not options.brief == True: |
| 1137 |
print(' No dependencies!') |
1258 |
print(' No dependencies!') |
| 1138 |
|
1259 |
|
| 1139 |
|
1260 |
|
|
|
| 1306 |
parser.add_option('--showSystemDep', action='store_true', dest='showSystemDep', |
1427 |
parser.add_option('--showSystemDep', action='store_true', dest='showSystemDep', |
| 1307 |
default=True, |
1428 |
default=True, |
| 1308 |
help='Shows the system dependency of the enabled/disabled modules') |
1429 |
help='Shows the system dependency of the enabled/disabled modules') |
|
|
1430 |
parser.add_option('-b', '--brief', action='store_true', dest='brief', |
| 1431 |
default=False, |
| 1432 |
help='Show only the module name') |
| 1433 |
parser.add_option('-c', '--configured', action='store_true', dest='configured', |
| 1434 |
default=False, |
| 1435 |
help='Show only the configured module') |
| 1309 |
(options, args_left) = parser.parse_args(args) |
1436 |
(options, args_left) = parser.parse_args(args) |
| 1310 |
# adds a default value so that show will show something even if there is |
1437 |
# adds a default value so that show will show something even if there is |
| 1311 |
# no option |
1438 |
# no option |
|
|
| 1313 |
options.enabled = True |
1440 |
options.enabled = True |
| 1314 |
options.showSystemDep = True |
1441 |
options.showSystemDep = True |
| 1315 |
else: |
1442 |
else: |
| 1316 |
if not options.disabled and not options.enabled: |
1443 |
if not options.disabled and not options.enabled and not options.configured: |
| 1317 |
options.enabled=True |
1444 |
options.enabled=True |
| 1318 |
|
1445 |
|
| 1319 |
config= self.check_configuration_file(config, True); |
1446 |
config= self.check_configuration_file(config, True); |
|
|
| 1327 |
" Call bake with -f [full path configuration file name].\n") |
1454 |
" Call bake with -f [full path configuration file name].\n") |
| 1328 |
return |
1455 |
return |
| 1329 |
# configuration = Configuration(config) |
1456 |
# configuration = Configuration(config) |
| 1330 |
# configuration.read_metadata(config) |
1457 |
# configuration.read_metadata(config) |
| 1331 |
|
|
|
| 1332 |
if options.all: |
1458 |
if options.all: |
| 1333 |
options.enabled = True |
1459 |
options.enabled = True |
| 1334 |
options.disabled = True |
1460 |
options.disabled = True |
|
|
| 1356 |
if options.enabled: |
1482 |
if options.enabled: |
| 1357 |
self.show_module(enabled, options, config, 'enabled') |
1483 |
self.show_module(enabled, options, config, 'enabled') |
| 1358 |
|
1484 |
|
|
|
1485 |
if options.configured: |
| 1486 |
self.show_module(configuration.configured(), options, config, 'configured') |
| 1487 |
|
| 1359 |
if options.disabled: |
1488 |
if options.disabled: |
| 1360 |
self.show_module(disabled, options, config, 'disabled') |
1489 |
self.show_module(disabled, options, config, 'disabled') |
| 1361 |
|
1490 |
|
|
|
| 1484 |
['show', self._show], |
1613 |
['show', self._show], |
| 1485 |
['show-builtin', self._show_builtin], |
1614 |
['show-builtin', self._show_builtin], |
| 1486 |
['check', self._check], |
1615 |
['check', self._check], |
|
|
1616 |
['list', self._list], |
| 1487 |
] |
1617 |
] |
| 1488 |
recognizedCommand = False |
1618 |
recognizedCommand = False |
| 1489 |
|
1619 |
|