View | Details | Raw Unified | Return to bug 2631
Collapse All | Expand All

(-)a/bake/Bake.py (-13 / +133 lines)
 Lines 46-51    Link Here 
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 """
 Lines 89-95    Link Here 
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.")
 Lines 117-122    Link Here 
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()
 Lines 133-138    Link Here 
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
 Lines 209-219    Link Here 
209
224
210
    def _enable(self, enable, configuration):
225
    def _enable(self, enable, configuration):
211
        """ Handles the --enable option, setting defined modules as enable."""
226
        """ Handles the --enable option, setting defined modules as enable."""
212
        
213
        for module_name in enable:
227
        for module_name in enable:
214
            module = configuration.lookup(module_name)
228
            module = configuration.lookup(module_name)
215
            if not module:
229
            if not module:
216
                self._error('Module "%s" not found' % module_name)
230
                self._error('Module "%s" not found' % module_name)
231
            if module.mtype() == "ns-contrib":
232
                found=0
233
                fmod = None
234
                for mod in enable:
235
                    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)):
236
                        found+= 1
237
                        fmod = mod
238
                if not found==1:
239
                    self._error('Module "%s" has unmet dependency: %s' % (module_name, module.minver()))
240
                module.get_source().attribute("module_directory").value = fmod+'/contrib/'+module.get_source().attribute("module_directory").value
241
                module.addDependencies(ModuleDependency(fmod, False))
217
            configuration.enable(module)
242
            configuration.enable(module)
218
243
219
    def _disable(self, disable, configuration):
244
    def _disable(self, disable, configuration):
 Lines 224-229    Link Here 
224
            if not module:
249
            if not module:
225
                self._error('Module "%s" not found' % module_name)
250
                self._error('Module "%s" not found' % module_name)
226
            configuration.disable(module)
251
            configuration.disable(module)
252
            if module.mtype() == "ns":
253
                enabled_list = configuration.enabled()
254
                for mod in enabled_list:
255
                    if mod.mtype() == "ns-contrib":
256
                        configuration.disable(mod)
227
257
228
    def _variables_process(self, items, configuration, is_append):
258
    def _variables_process(self, items, configuration, is_append):
229
        """ Handles the defined configured variables ."""
259
        """ Handles the defined configured variables ."""
 Lines 257-268    Link Here 
257
        
287
        
258
        # enables/disables the explicit enable/disable modules passed as argument
288
        # enables/disables the explicit enable/disable modules passed as argument
259
        self._enable(options.enable, configuration)
289
        self._enable(options.enable, configuration)
290
        for mod in options.disable:
291
            if not mod in options.enable:
292
                self._error('Module "%s" not enabled' % mod)
260
        self._disable(options.disable, configuration)
293
        self._disable(options.disable, configuration)
261
        
294
        
262
        # if the option -a is used, meaning all the modules should be enabled
295
        # if the option -a is used, meaning all the modules should be enabled
263
        if options.enable_all:
296
        if options.enable_all:
264
            for module in configuration.modules():
297
            for module in configuration.modules():
265
                configuration.enable(module)
298
                configuration.enable(module)
299
            
266
                
300
                
267
        # if the option -m is used, meaning the minimum configuration should be used
301
        # if the option -m is used, meaning the minimum configuration should be used
268
        # it disables all the non mandatory dependencies
302
        # it disables all the non mandatory dependencies
 Lines 382-387    Link Here 
382
        configuration.append(lastConfig)
416
        configuration.append(lastConfig)
383
        self.save_resource_file(configuration, fileName)
417
        self.save_resource_file(configuration, fileName)
384
418
419
    def _list(self, config, args):
420
        """ Handles the list option for %prog """
421
        
422
        # sets the options the parser should recognize for the configuration
423
        parser = OptionParser(usage='usage: %prog list [options]')
424
        parser.add_option("-f", "--conffile", action="store", type="string",
425
                          dest="bakeconf", default="bakeconf.xml",
426
                          help="The Bake meta-data configuration file to use. "
427
                          "Default: %default.")
428
        parser.add_option("-c", "--contrib", action="store_true",
429
                          dest="contrib", default="False",
430
                          help="Show only contrib modules.")
431
        (options, args_left) = parser.parse_args(args)
432
        listconf = Configuration(config)
433
        contrib_list = []
434
        module_list = []
435
436
        contribconf = []
437
        try:
438
            for cfile in os.listdir("contrib"):
439
                if cfile.endswith(".xml"):
440
                    contribconf.append("contrib/"+cfile)
441
        except Exception as e:
442
            True
443
444
        try:
445
            listconf.read_metadata(options.bakeconf)
446
        except Exception as e:
447
            self._error('Problem reading Configuration file "%s" \n Error: %s'  % (options.bakeconf, str(e)))
448
449
        for cconf in contribconf:
450
            try:
451
                listconf.read_metadata(cconf)
452
            except Exception as e:
453
                self._error('Problem reading Configuration file "%s" \n Error: %s'  % (cconf, str(e)))
454
455
        for mod in listconf.modules():
456
            if mod.mtype() == "ns-contrib":
457
                contrib_list.append(mod.name())
458
            elif not options.contrib == True:
459
                module_list.append(mod.name())
460
461
        contrib_list.sort()
462
        module_list.sort()
463
        for m in module_list:
464
            print("module: "+m)
465
        for c in contrib_list:
466
            print("contrib: "+c)
385
        
467
        
386
    def _configure(self, config, args):
468
    def _configure(self, config, args):
387
        """ Handles the configuration option for %prog """
469
        """ Handles the configuration option for %prog """
 Lines 389-395    Link Here 
389
        # sets the options the parser should recognize for the configuration
471
        # sets the options the parser should recognize for the configuration
390
        parser = OptionParser(usage='usage: %prog configure [options]')
472
        parser = OptionParser(usage='usage: %prog configure [options]')
391
        self._enable_disable_options(parser)
473
        self._enable_disable_options(parser)
392
        parser.add_option("-c", "--conffile", action="store", type="string",
474
        parser.add_option("-f", "--conffile", action="store", type="string",
393
                          dest="bakeconf", default="bakeconf.xml",
475
                          dest="bakeconf", default="bakeconf.xml",
394
                          help="The Bake meta-data configuration file to use. "
476
                          help="The Bake meta-data configuration file to use. "
395
                          "Default: %default.")
477
                          "Default: %default.")
 Lines 432-449    Link Here 
432
                          default=0, help='Increase the log verbosity level')
514
                          default=0, help='Increase the log verbosity level')
433
        parser.add_option('-q', '--quiet', action='count', dest='quiet', 
515
        parser.add_option('-q', '--quiet', action='count', dest='quiet', 
434
                          default=0, help='Increase the log quietness level')
516
                          default=0, help='Increase the log quietness level')
517
        parser.add_option("-c", "--clean", action="store_true",
518
                          dest="remove", default=False,
519
                          help="Remove all enabled modules")
435
520
436
        # sets the configuration values got from the line command
521
        # sets the configuration values got from the line command
437
        (options, args_left) = parser.parse_args(args)
522
        (options, args_left) = parser.parse_args(args)
438
439
        if options.bakeconf == "bakeconf.xml":
523
        if options.bakeconf == "bakeconf.xml":
440
            options.bakeconf = self.check_configuration_file(options.bakeconf, False);
524
            options.bakeconf = self.check_configuration_file(options.bakeconf, False);
441
525
526
        contribconf = []
527
        try:
528
            for cfile in os.listdir("contrib"):
529
                if cfile.endswith(".xml"):
530
                    contribconf.append("contrib/"+cfile)
531
        except Exception as e:
532
            True
533
442
        configuration = Configuration(config)
534
        configuration = Configuration(config)
535
536
        if not options.remove:
537
            try:
538
                configuration.read()
539
                for m in  configuration.enabled():
540
                    if m.name() not in options.enable:
541
                        options.enable.append(m.name())
542
            except Exception as e:
543
                True
544
       
443
        try:
545
        try:
444
            configuration.read_metadata(options.bakeconf)
546
            configuration.read_metadata(options.bakeconf)
445
        except Exception as e:
547
        except Exception as e:
446
            self._error('Problem reading Configuration file "%s" \n Error: %s'  % (options.bakeconf, str(e)))
548
            self._error('Problem reading Configuration file "%s" \n Error: %s'  % (options.bakeconf, str(e)))
549
550
        for cconf in contribconf:
551
            try:
552
                configuration.read_metadata(cconf)
553
            except Exception as e:
554
                self._error('Problem reading Configuration file "%s" \n Error: %s'  % (cconf, str(e)))
447
                   
555
                   
448
        configuration.set_sourcedir(options.sourcedir)
556
        configuration.set_sourcedir(options.sourcedir)
449
        configuration.set_objdir(options.objdir)
557
        configuration.set_objdir(options.objdir)
 Lines 490-498    Link Here 
490
                    self._error('--predefined: "%s" not found.' % p)
598
                    self._error('--predefined: "%s" not found.' % p)
491
                    
599
                    
492
        # Registers the modules are that enabled/disabled 
600
        # Registers the modules are that enabled/disabled 
493
        # handles the -a, -m, --disable, --enable tags            
601
        # handles the -a, -m, --disable, --enable tags           
494
        self._parse_enable_disable(options, configuration)
602
        self._parse_enable_disable(options, configuration)
495
        
603
496
        # handles the set command line option, to overwrite the specific 
604
        # handles the set command line option, to overwrite the specific 
497
        # module setting with the new specified value
605
        # module setting with the new specified value
498
        for variable in options.set:
606
        for variable in options.set:
 Lines 509-515    Link Here 
509
                module.get_build().attribute(name).value = current_value + ' ' + value
617
                module.get_build().attribute(name).value = current_value + ' ' + value
510
        configuration.write()
618
        configuration.write()
511
        
619
        
512
        if not configuration._enabled and not options.append :
620
        if not configuration._enabled and not options.append and not options.remove:
513
            env =  self._get_dummy_env(options)
621
            env =  self._get_dummy_env(options)
514
            env._logger.commands.write(' > No module enabled: Bake configuration requires at least one module to be enabled'
622
            env._logger.commands.write(' > No module enabled: Bake configuration requires at least one module to be enabled'
515
                                       ' (enable, predefined), or appended.\n'
623
                                       ' (enable, predefined), or appended.\n'
 Lines 1116-1122    Link Here 
1116
        if not state:
1224
        if not state:
1117
            return
1225
            return
1118
        for mod in state:
1226
        for mod in state:
1119
            print('module: %s (%s)' % (mod.name(), label))
1227
            if mod.mtype():
1228
                print('module %s: %s (%s)' % (mod.mtype(), mod.name(), label))
1229
            else:
1230
                print('module: %s (%s)' % (mod.name(), label))
1120
            dependencies = mod.dependencies()
1231
            dependencies = mod.dependencies()
1121
            
1232
            
1122
            # Stores the system dependencies
1233
            # Stores the system dependencies
 Lines 1127-1139    Link Here 
1127
            if not mod.name() in depen:
1238
            if not mod.name() in depen:
1128
                depen[mod.name()] = dict()
1239
                depen[mod.name()] = dict()
1129
            
1240
            
1130
            if dependencies:
1241
            if dependencies and not options.brief == True:
1131
                print('  depends on:')
1242
                print('  depends on:')
1132
                for dependsOn in mod.dependencies():
1243
                for dependsOn in mod.dependencies():
1133
                    print('     %s (optional:%s)' % 
1244
                    print('     %s (optional:%s)' % 
1134
                          (dependsOn.name(), dependsOn.is_optional())) 
1245
                          (dependsOn.name(), dependsOn.is_optional())) 
1135
                    depen[mod.name()][dependsOn.name()]=  dependsOn.is_optional()
1246
                    depen[mod.name()][dependsOn.name()]=  dependsOn.is_optional()
1136
            else:
1247
            elif not options.brief == True:
1137
                print('  No dependencies!')
1248
                print('  No dependencies!')
1138
                
1249
                
1139
            
1250
            
 Lines 1306-1311    Link Here 
1306
        parser.add_option('--showSystemDep', action='store_true', dest='showSystemDep', 
1417
        parser.add_option('--showSystemDep', action='store_true', dest='showSystemDep', 
1307
                          default=True,
1418
                          default=True,
1308
                          help='Shows the system dependency of the enabled/disabled modules')
1419
                          help='Shows the system dependency of the enabled/disabled modules')
1420
        parser.add_option('-b', '--brief', action='store_true', dest='brief', 
1421
                          default=False,
1422
                          help='Show only the module name')
1423
        parser.add_option('-c', '--configured', action='store_true', dest='configured', 
1424
                          default=False,
1425
                          help='Show only the configured module')
1309
        (options, args_left) = parser.parse_args(args)
1426
        (options, args_left) = parser.parse_args(args)
1310
        # adds a default value so that show will show something even if there is
1427
        # adds a default value so that show will show something even if there is
1311
        # no option 
1428
        # no option 
 Lines 1313-1319    Link Here 
1313
            options.enabled = True
1430
            options.enabled = True
1314
            options.showSystemDep = True
1431
            options.showSystemDep = True
1315
        else:
1432
        else:
1316
            if not options.disabled and not options.enabled:
1433
            if not options.disabled and not options.enabled and not options.configured:
1317
                options.enabled=True
1434
                options.enabled=True
1318
1435
1319
        config= self.check_configuration_file(config, True);
1436
        config= self.check_configuration_file(config, True);
 Lines 1327-1334    Link Here 
1327
                  "   Call bake with -f [full path configuration file name].\n")
1444
                  "   Call bake with -f [full path configuration file name].\n")
1328
            return
1445
            return
1329
#            configuration = Configuration(config)
1446
#            configuration = Configuration(config)
1330
#            configuration.read_metadata(config)
1447
#            configuration.read_metadata(config)       
1331
            
1332
        if options.all:
1448
        if options.all:
1333
            options.enabled = True
1449
            options.enabled = True
1334
            options.disabled = True
1450
            options.disabled = True
 Lines 1356-1361    Link Here 
1356
        if options.enabled:
1472
        if options.enabled:
1357
            self.show_module(enabled, options, config, 'enabled')
1473
            self.show_module(enabled, options, config, 'enabled')
1358
1474
1475
        if options.configured:
1476
            self.show_module(configuration.configured(), options, config, 'configured')
1477
1359
        if options.disabled:
1478
        if options.disabled:
1360
            self.show_module(disabled, options, config, 'disabled')
1479
            self.show_module(disabled, options, config, 'disabled')
1361
            
1480
            
 Lines 1484-1489    Link Here 
1484
                ['show', self._show],
1603
                ['show', self._show],
1485
                ['show-builtin', self._show_builtin],
1604
                ['show-builtin', self._show_builtin],
1486
                ['check', self._check],
1605
                ['check', self._check],
1606
                ['list', self._list],
1487
               ]
1607
               ]
1488
        recognizedCommand = False
1608
        recognizedCommand = False
1489
        
1609
        
(-)a/bake/Configuration.py (-3 / +14 lines)
 Lines 85-90    Link Here 
85
        self._enabled = []
85
        self._enabled = []
86
        self._disabled = []
86
        self._disabled = []
87
        self._modules = []
87
        self._modules = []
88
        self._configured = []
88
        self._installdir = None
89
        self._installdir = None
89
        self._objdir = None
90
        self._objdir = None
90
        self._sourcedir = None
91
        self._sourcedir = None
 Lines 318-323    Link Here 
318
        modules = et.findall('modules/module')
319
        modules = et.findall('modules/module')
319
        for module_node in modules:
320
        for module_node in modules:
320
            name = module_node.get('name')
321
            name = module_node.get('name')
322
            mtype = module_node.get('type')
323
            min_ver = module_node.get('min_version')
324
            max_ver = module_node.get('max_version')
321
            installed = self._read_installed(module_node)
325
            installed = self._read_installed(module_node)
322
326
323
            source_node = module_node.find('source')
327
            source_node = module_node.find('source')
 Lines 333-339    Link Here 
333
            for dep_node in module_node.findall('depends_on'):
337
            for dep_node in module_node.findall('depends_on'):
334
                dependencies.append(ModuleDependency(dep_node.get('name'),
338
                dependencies.append(ModuleDependency(dep_node.get('name'),
335
                                                     bool(dep_node.get('optional', '').upper()=='TRUE')))
339
                                                     bool(dep_node.get('optional', '').upper()=='TRUE')))
336
            module = Module(name, source, build, dependencies=dependencies,
340
            module = Module(name, source, build, mtype, min_ver, max_ver, dependencies=dependencies,
337
                            built_once=bool(module_node.get('built_once', '').upper()=='TRUE'),
341
                            built_once=bool(module_node.get('built_once', '').upper()=='TRUE'),
338
                            installed=installed)
342
                            installed=installed)
339
            self._modules.append(module)
343
            self._modules.append(module)
 Lines 346-352    Link Here 
346
        
350
        
347
        for module in self._modules:
351
        for module in self._modules:
348
            module_attrs = {'name' : module.name()}
352
            module_attrs = {'name' : module.name()}
349
            
353
            if module.mtype():
354
                module_attrs['type'] = module.mtype()
355
            if module.minver():
356
                module_attrs['min_version'] = module.minver()
350
            if module.is_built_once():
357
            if module.is_built_once():
351
                module_attrs['built_once'] = 'True'
358
                module_attrs['built_once'] = 'True'
352
            module_node = ET.Element('module', module_attrs)
359
            module_node = ET.Element('module', module_attrs)
 Lines 441-446    Link Here 
441
        # read which modules are enabled
448
        # read which modules are enabled
442
        modules = root.findall('enabled')
449
        modules = root.findall('enabled')
443
        for module in modules:
450
        for module in modules:
451
            self._configured.append(self.lookup(module.get('name')))
444
            enabled = self.lookup(module.get('name'))
452
            enabled = self.lookup(module.get('name'))
445
            self.enable(enabled)
453
            self.enable(enabled)
446
454
 Lines 499-505    Link Here 
499
        
507
        
500
        if module in self._disabled:
508
        if module in self._disabled:
501
            self._disabled.remove(module)
509
            self._disabled.remove(module)
502
        else:
510
        elif module not in self._enabled:
503
            self._enabled.append(module)
511
            self._enabled.append(module)
504
 
512
 
505
    def disable(self, module):
513
    def disable(self, module):
 Lines 528-530    Link Here 
528
536
529
    def modules(self):
537
    def modules(self):
530
        return self._modules
538
        return self._modules
539
540
    def configured(self):
541
        return self._configured
(-)a/bake/Module.py (+17 lines)
 Lines 57-71    Link Here 
57
    def __init__(self, name, 
57
    def __init__(self, name, 
58
                 source,
58
                 source,
59
                 build,
59
                 build,
60
                 mtype,
61
                 min_ver,
62
                 max_ver,
60
                 dependencies = [],
63
                 dependencies = [],
61
                 built_once = False,
64
                 built_once = False,
62
                 installed = []):
65
                 installed = []):
63
        self._name = name
66
        self._name = name
67
        self._type = mtype
64
        self._dependencies = copy.copy(dependencies)
68
        self._dependencies = copy.copy(dependencies)
65
        self._source = source
69
        self._source = source
66
        self._build = build
70
        self._build = build
67
        self._built_once = built_once
71
        self._built_once = built_once
68
        self._installed = installed
72
        self._installed = installed
73
        self._minVersion = min_ver
74
        self._maxVersion = max_ver
69
75
70
76
71
    @property
77
    @property
 Lines 556-558    Link Here 
556
        return self._name
562
        return self._name
557
    def dependencies(self):
563
    def dependencies(self):
558
        return self._dependencies
564
        return self._dependencies
565
    def mtype(self):
566
        return self._type
567
    def minver(self):
568
        return self._minVersion
569
    def maxver(self):
570
        return self._maxVersion
571
    def addDependencies(self, depend):
572
        for d in self._dependencies:
573
            if d.name() == depend.name():
574
                return
575
        self._dependencies.append(depend)        

Return to bug 2631