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

(-)a/bake/Bake.py (-13 / +143 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 207-219    Link Here 
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):
 Lines 224-229    Link Here 
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 ."""
 Lines 257-268    Link Here 
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
 Lines 382-387    Link Here 
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 """
 Lines 389-395    Link Here 
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.")
 Lines 432-449    Link Here 
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)
 Lines 490-498    Link Here 
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:
 Lines 509-515    Link Here 
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'
 Lines 1116-1122    Link Here 
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
 Lines 1127-1139    Link Here 
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
            
 Lines 1306-1311    Link Here 
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 
 Lines 1313-1319    Link Here 
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);
 Lines 1327-1334    Link Here 
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
 Lines 1356-1361    Link Here 
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
            
 Lines 1484-1489    Link Here 
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
        
(-)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