CML2 rule file is autogenerated from arm.cml and the containers template

Container rules are too many and repetitive for each container. With this
change, the cml file is autogenerated from a container template cml and
the architecture cml, e.g. arm.cml. -c option determines the number of
containers. See build.py -h for more.
This commit is contained in:
Bahadir Balban
2009-09-26 16:39:04 +03:00
parent fbb1800562
commit 10d2d7269f
8 changed files with 299 additions and 352 deletions

View File

@@ -103,11 +103,22 @@ class BareContGenerator:
self.copy_bare_build_desc(config, cont)
self.generate_linker_script(config, cont)
def update_configuration(self, config, cont):
self.build_readme_out = join(self.CONT_SRC_DIR, self.build_readme_name)
self.build_desc_out = join(self.CONT_SRC_DIR, self.build_desc_name)
self.linker_lds_out = join(join(self.CONT_SRC_DIR, 'include'), \
self.linker_lds_name)
self.copy_bare_build_desc(config, cont)
self.generate_linker_script(config, cont)
def check_create_bare_sources(self, config):
for cont in config.containers:
if cont.type == "bare":
if not os.path.exists(join(self.BARE_SRC_BASEDIR, cont.dirname)):
self.create_bare_sources(config, cont)
# Don't create new sources but update configuration
else:
self.update_configuration(config, cont)
def generate_linker_script(self, config, cont):
with open(self.linker_lds_in) as fin:

0
scripts/cml/__init__.py Normal file
View File

View File

@@ -0,0 +1,72 @@
#! /usr/bin/env python2.6
# -*- mode: python; coding: utf-8; -*-
#
# Codezero -- a microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
import os, sys, shelve, glob
from os.path import join
PROJRELROOT = '../../'
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT)))
sys.path.append(os.path.abspath("../"))
from config.projpaths import *
from config.configuration import *
containers_menu = \
'''
menu containers_menu
'''
containers_constraint = \
'''
unless CONTAINERS > %d suppress cont%d_menu
'''
containers_default = \
'''
default CONTAINERS from %d
'''
def add_container_constraint(cid):
cml_string = ""
if cid == 0:
return ""
cml_string = containers_constraint % (cid, cid)
return cml_string
def generate_container_cml(arch, ncont):
contid_occurence = 223 # Exact number of arguments
fbody = ""
with open(join(CML2_CONFIG_SRCDIR, arch + '.cml')) as in_cml:
fbody += in_cml.read()
# Add container visibility constraint
for cont in range(ncont):
fbody += add_container_constraint(cont)
# Add number of default containers
fbody += containers_default % ncont
# Generate the containers menu with as many entries as containers
fbody += containers_menu
for cont in range(ncont):
fbody += '\tcont%d_menu\n' % cont
# Write each container's rules
for cont in range(ncont):
with open(CML2_CONT_DEFFILE, "rU") as contdefs:
defbody = contdefs.read()
defbody = defbody.replace("%\n", "%%\n")
fbody += defbody % tuple(contid_occurence * [cont])
# Write the result to output rules file.
with open(join(CML2_CONFIG_SRCDIR, "out.cml"), "w+") as out_cml:
out_cml.write(fbody)
if __name__ == "__main__":
generate_container_cml('arm', 4)