Skip to content

Commit

Permalink
rename module to azrtos componment (#11)
Browse files Browse the repository at this point in the history
Co-authored-by: Zhen Kong <[email protected]>
  • Loading branch information
zhen9910 and zhen9910 authored Apr 17, 2023
1 parent 3eabb13 commit 2f85ba6
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 80 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ Requirements: Python 3.9 or higher.
```
## Generate cmsis-packs
```
# generate packs for all Azure RTOS modules using the existing pack description files (*.pdsc).
# generate packs for all Azure RTOS system components using the existing pack description files (*.pdsc).
python3 ./scripts/generate.py
# Generate CMSIS-Packs for specific Azure RTOS modules
# Generate CMSIS-Packs for specific Azure RTOS system components
python3 ./scripts/generate.py -m "threadx, usbx"
# Force to (re)generate pack description files (*.pdsc) before generating CMSIS-Packs
Expand All @@ -48,7 +48,7 @@ Requirements: Python 3.9 or higher.
```
## Repository Structure
This repo add all Azure RTOS modules repo as submodules.
This repo add all Azure RTOS system components repo as submodules.

```
.
Expand All @@ -58,7 +58,7 @@ This repo add all Azure RTOS modules repo as submodules.
│ ├── gen_pdsc.py # python module to generate pack description file from azure-rtos source code and pdsc_template.xml
│ └── gen_pack.sh # bash script to generate cmsis-pack
├── data # Each module's pack description file, pdsc_template.xml, and any additional files to be added to CMSIS-Pack, such as example projects
├── data # Each Azure RTOS system component's pdsc file, pdsc_template.xml, any additional files to be added to CMSIS-Pack, such as examples
│ │
│ ├── filex
│ │ ├── Microsoft.AzureRTOS-FileX.pdsc
Expand Down
4 changes: 2 additions & 2 deletions data/filex/pdsc_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<!-- porting files directory -->
<ports_dir>../ports</ports_dir>

<!-- azrtos_module_name -->
<azrtos_module_name>FileX</azrtos_module_name>
<!-- azrtos_component_name -->
<azrtos_component_name>FileX</azrtos_component_name>

<!-- supported porting devices -->
<port_devices>
Expand Down
4 changes: 2 additions & 2 deletions data/guix/pdsc_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<!-- porting files directory -->
<ports_dir>../ports</ports_dir>

<!-- azrtos_module_name -->
<azrtos_module_name>GUIX</azrtos_module_name>
<!-- azrtos_component_name -->
<azrtos_component_name>GUIX</azrtos_component_name>

<!-- supported porting devices -->
<port_devices>
Expand Down
4 changes: 2 additions & 2 deletions data/levelx/pdsc_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<!-- common source files directory -->
<common_dir>../common</common_dir>

<!-- azrtos_module_name -->
<azrtos_module_name>LevelX</azrtos_module_name>
<!-- azrtos_component_name -->
<azrtos_component_name>LevelX</azrtos_component_name>

<vendor>Microsoft</vendor>
<name>AzureRTOS-LevelX</name>
Expand Down
4 changes: 2 additions & 2 deletions data/usbx/pdsc_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<!-- porting files directory -->
<ports_dir>../ports</ports_dir>

<!-- azrtos_module_name -->
<azrtos_module_name>USBX</azrtos_module_name>
<!-- azrtos_component_name -->
<azrtos_component_name>USBX</azrtos_component_name>

<!-- supported porting devices -->
<port_devices>
Expand Down
46 changes: 23 additions & 23 deletions scripts/gen_pdsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_component_from_cmake_file(cmake_file):
Get component from common/CMakeLists.txt
Args:
cmake_file(string) : CMakeLists.txt for this azure-rtos module
cmake_file(string) : CMakeLists.txt for this azure-rtos component
"""
# Open the CMakeLists.txt file
contents = ""
Expand Down Expand Up @@ -180,29 +180,29 @@ def update_conditions(root, port_devices, ports_dir):

return porting_files

def update_component(component, bundle_subcomponent, azrtos_module_name,
def update_pack_component(component, bundle_subcomponent, azrtos_component_name,
porting_files):
"""
update component element with description, RTE_Components_h, porting files
update pack component element with description, RTE_Components_h, porting files
Args:
component(string): component name
component(string): pack component name
bundle_subcomponent: bundle subcomponent in pdsc file
azrtos_module_name(string): azrtos module name
azrtos_component_name(string): azrtos component name
porting_files: porting files for specific device and compiler
"""
component_element = ET.SubElement(bundle_subcomponent, "component")
component_element.attrib["Cgroup"] = azrtos_module_name
component_element.attrib["Cgroup"] = azrtos_component_name
component_element.attrib["Csub"] = component
component_element.attrib["maxInstances"] = "1"
description_element = ET.SubElement(component_element, "description")
description_element.text = ("Azure RTOS " + azrtos_module_name
description_element.text = ("Azure RTOS " + azrtos_component_name
+ " " + component)
rte_element = ET.SubElement(component_element, "RTE_Components_h")
if component in ("core", "common"):
rte_element.text = ("#define AZURE_RTOS_"
+ azrtos_module_name.upper() + "_ENABLED")
+ azrtos_component_name.upper() + "_ENABLED")
else:
rte_element.text = ("#define AZURE_RTOS_"
+ component.upper() + "_ENABLED")
Expand All @@ -220,14 +220,14 @@ def update_component(component, bundle_subcomponent, azrtos_module_name,
return files_element


def update_components(root, common_dir_subcomponent, azrtos_module_name, porting_files):
def update_pack_components(root, common_dir_subcomponent, azrtos_component_name, porting_files):
"""
update components with component and files
update pack components with component and files
Args:
root: the root object of psdc_template.xml file
common_dir_subcomponent: common_dir_subcomponent object of psdc_template.xml
azrtos_module_name: module name of this azure rtos component
azrtos_component_name: this azure rtos component name
porting_files: device and compiler specific porting files
"""
components_subcomponent = root.find("components")
Expand All @@ -243,8 +243,8 @@ def update_components(root, common_dir_subcomponent, azrtos_module_name, porting
if components_list:
for component in components_list:
# print(f"components {component} found in {cmake_file}")
files_element = update_component(component, bundle_subcomponent,
azrtos_module_name, porting_files)
files_element = update_pack_component(component, bundle_subcomponent,
azrtos_component_name, porting_files)
sub_cmake_file = os.path.join(common_dir_subcomponent.text, component,
"CMakeLists.txt")
# add source and inc into each component
Expand All @@ -253,18 +253,18 @@ def update_components(root, common_dir_subcomponent, azrtos_module_name, porting
# No individual components, add all files into one "common" component
# print(f"Add all files into one common component")
component = "common"
files_element = update_component(component, bundle_subcomponent,
azrtos_module_name, porting_files)
files_element = update_pack_component(component, bundle_subcomponent,
azrtos_component_name, porting_files)
# add source and inc into each component
get_file_from_cmake_file(cmake_file, files_element)


def generate_pdsc_file(module_data_path, cmsis_pack_working_path):
def generate_pdsc_file(azrtos_component_data_path, cmsis_pack_working_path):
"""
generate package description file from this module's pdsc_template.xml
generate package description file from this azrtos component's pdsc_template.xml
Args:
module_data_path(string): this module's data path where the generated pdsc file is saved to.
azrtos_component_data_path(string): data path where the generated pdsc is saved to
cmsis_pack_working_path(string): the working path where pdsc_template.xml is located
"""
Expand All @@ -290,15 +290,15 @@ def generate_pdsc_file(module_data_path, cmsis_pack_working_path):
else:
ports_dir = ""

azrtos_module_name_subcomponent = root.find("azrtos_module_name")
azrtos_module_name = azrtos_module_name_subcomponent.text
azrtos_component_name_subcomponent = root.find("azrtos_component_name")
azrtos_component_name = azrtos_component_name_subcomponent.text

port_devices = [elem.text for elem in root.iter("port_device")]
port_devices_subcomponent = root.find("port_devices")

# remove these component from xml
root.remove(common_dir_subcomponent)
root.remove(azrtos_module_name_subcomponent)
root.remove(azrtos_component_name_subcomponent)
if ports_dir_subcomponent is not None:
root.remove(ports_dir_subcomponent)
if port_devices_subcomponent is not None:
Expand All @@ -316,7 +316,7 @@ def generate_pdsc_file(module_data_path, cmsis_pack_working_path):
porting_files = update_conditions(root, port_devices, ports_dir)

# update components in pdsc
update_components(root, common_dir_subcomponent, azrtos_module_name, porting_files)
update_pack_components(root, common_dir_subcomponent, azrtos_component_name, porting_files)

tree = ET.ElementTree(root)
ET.indent(tree, " ")
Expand All @@ -325,5 +325,5 @@ def generate_pdsc_file(module_data_path, cmsis_pack_working_path):
xml_declaration=True)

# save the generated pdsc file
shutil.copy(output_file, module_data_path)
shutil.copy(output_file, azrtos_component_data_path)
print(f"{output_file} is generated successfully")
90 changes: 45 additions & 45 deletions scripts/generate.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
This Python script generates cmsis-packs for Azure RTOS modules.
This Python script generates cmsis-packs for Azure RTOS.
Usage:
-- Generate CMSIS-Packs for all Azure RTOS modules.
-- Generate CMSIS-Packs for all Azure RTOS system components.
$ python3 /path/to/generate.py
-- Generate CMSIS-Packs for specific Azure RTOS modules.
-- Generate CMSIS-Packs for specific Azure RTOS system components.
$ python3 /path/to/generate.py -m "threadx, usbx"
-- Force to (re)generate pack description files(*.pdsc) before generating CMSIS-Packs.
Expand Down Expand Up @@ -38,77 +38,77 @@
}


def process_module(azrtos_module_name):
def process_azrtos_system_component(azrtos_component_name):
"""
This function generates cmsis-pack for specified Azure-RTOS module.
This function generates cmsis-pack for specified Azure-RTOS system component.
It can generate cmsis-pack from pdsc file directly if without "-f" option;
or it will first generate pdsc file from pdsc_template.xml if "-f" is present.
Args:
azrtos_module_name (string): threadx, netxduo, filex, usbx, guix, or levelx.
azrtos_component_name (string): threadx, netxduo, filex, usbx, guix, or levelx.
"""
# Construct the directory path
module_source_path = os.path.join(root_path, azrtos_module_name)
module_data_path = os.path.join(data_path, azrtos_module_name)
azrtos_component_source_path = os.path.join(root_path, azrtos_component_name)
azrtos_component_data_path = os.path.join(data_path, azrtos_component_name)

if not os.path.exists(module_source_path):
print(module_source_path + " not found!")
if not os.path.exists(azrtos_component_source_path):
print(azrtos_component_source_path + " not found!")
sys.exit(1)

if not os.path.exists(module_data_path):
print(module_data_path + " not found!")
if not os.path.exists(azrtos_component_data_path):
print(azrtos_component_data_path + " not found!")
sys.exit(1)

# create the cmsis_pack_working folder at {module_source_path}/cmsis_pack
print("Copy data/" + azrtos_module_name + " to " + module_source_path)
cmsis_pack_working_path = os.path.join(module_source_path + "/cmsis_pack")
# create the cmsis_pack_working folder at {azrtos_component_source_path}/cmsis_pack
print("Copy data/" + azrtos_component_name + " to " + azrtos_component_source_path)
cmsis_pack_working_path = os.path.join(azrtos_component_source_path + "/cmsis_pack")
if not os.path.exists(cmsis_pack_working_path):
os.mkdir(cmsis_pack_working_path)

# copy every folder in module_data_path to cmsis_pack_working_path
# copy every folder in azrtos_component_data_path to cmsis_pack_working_path
copied_folders = []
for item in os.listdir(module_data_path):
item_path = os.path.join(module_data_path, item)
for item in os.listdir(azrtos_component_data_path):
item_path = os.path.join(azrtos_component_data_path, item)
if os.path.isdir(item_path):
shutil.copytree(item_path, os.path.join(module_source_path, item))
copied_folders.append(os.path.join(module_source_path, item))
shutil.copytree(item_path, os.path.join(azrtos_component_source_path, item))
copied_folders.append(os.path.join(azrtos_component_source_path, item))

# if arg.f, generate pdsc file, but not for threadx or netxduo
if args.f and azrtos_module_name not in ("threadx", "netxduo"):
print("Generate pack description file for module: " + azrtos_module_name)
if args.f and azrtos_component_name not in ("threadx", "netxduo"):
print("Generate pack description file for azrtos_component: " + azrtos_component_name)
# process pdsc_template.xml in cmsis_pack_working_path
shutil.copyfile(
os.path.join(module_data_path, "pdsc_template.xml"),
os.path.join(azrtos_component_data_path, "pdsc_template.xml"),
os.path.join(cmsis_pack_working_path, "pdsc_template.xml"),
)
os.chdir(cmsis_pack_working_path)
gen_pdsc.generate_pdsc_file(
module_data_path, cmsis_pack_working_path
azrtos_component_data_path, cmsis_pack_working_path
)
os.remove(os.path.join(cmsis_pack_working_path, "pdsc_template.xml"))

copied_gen_pack_sh = os.path.join(module_source_path, "gen_pack.sh")
copied_gen_pack_sh = os.path.join(azrtos_component_source_path, "gen_pack.sh")
shutil.copy(os.path.join(scripts_path, "gen_pack.sh"), copied_gen_pack_sh)

src_pdsc_file = ""
copied_pdsc_file = ""
for file in os.listdir(module_data_path):
for file in os.listdir(azrtos_component_data_path):
if file.endswith(".pdsc"):
src_pdsc_file = os.path.join(module_data_path, file)
copied_pdsc_file = os.path.join(module_source_path, file)
src_pdsc_file = os.path.join(azrtos_component_data_path, file)
copied_pdsc_file = os.path.join(azrtos_component_source_path, file)
shutil.copyfile(src_pdsc_file, copied_pdsc_file)

if copied_pdsc_file == "":
print("Error: no pdsc file")
sys.exit(1)

# goto module_source_path, call "./gen_pack.sh" bash there.
os.chdir(module_source_path)
# goto azrtos_component_source_path, call "./gen_pack.sh" bash there.
os.chdir(azrtos_component_source_path)

# run gen_pack.sh with argument PACK_DIRS[azrtos_module_name]
# run gen_pack.sh with argument PACK_DIRS[azrtos_component_name]
print("Call ./gen_pack.sh to generate cmsis_pack")
cmd = "./gen_pack.sh " + '"' + PACK_DIRS[azrtos_module_name] + '"'
cmd = "./gen_pack.sh " + '"' + PACK_DIRS[azrtos_component_name] + '"'
os.system(cmd)

# copy generated cmsis-pack file to root_path
Expand All @@ -128,9 +128,9 @@ def process_module(azrtos_module_name):


parser = ArgumentParser(
description="Generate CMSIS-Packs for Azure RTOS modules.\n\n"
description="Generate CMSIS-Packs for Azure RTOS.\n\n"
"Requirement: Python 3.9 or higher.\n\n"
"By default it generate packs for all Azure RTOS modules "
"By default it generate packs for all Azure RTOS system components "
"using the existing pack description files (*.pdsc).\n"
"$ python3 ./scripts/generate.py",
formatter_class=RawTextHelpFormatter,
Expand All @@ -139,7 +139,7 @@ def process_module(azrtos_module_name):
parser.add_argument(
"-m",
type=str,
help="Generate CMSIS-Packs for specific Azure RTOS modules, "
help="Generate CMSIS-Packs for specific Azure RTOS system components, "
"their names are separated by comma. \n"
'Example: $ python3 ./scripts/generate.py -m "threadx, usbx" \n',
)
Expand All @@ -154,14 +154,14 @@ def process_module(azrtos_module_name):
args = parser.parse_args()

if args.m:
MODULES = args.m
AZRTOS_SYSTEM_COMPONENTS = args.m
else:
MODULES = "threadx, netxduo, usbx, filex, guix, levelx"
AZRTOS_SYSTEM_COMPONENTS = "threadx, netxduo, usbx, filex, guix, levelx"

print("*******************************************************************")
if args.f:
print("Generate pack description files first, and then")
print("Generate cmsis-packs for Azure RTOS modules: " + MODULES)
print("Generate cmsis-packs for Azure RTOS system components: " + AZRTOS_SYSTEM_COMPONENTS)
print("*******************************************************************")

cwd = os.getcwd()
Expand All @@ -181,11 +181,11 @@ def process_module(azrtos_module_name):
print("data folder: " + data_path)
print("scripts folder: " + scripts_path)

if MODULES:
# split modules into a list
modules = MODULES.replace(",", " ").split()
# process each module
for module in modules:
if AZRTOS_SYSTEM_COMPONENTS:
# split system components into a list
azrtos_components = AZRTOS_SYSTEM_COMPONENTS.replace(",", " ").split()
# process each system component
for azrtos_component in azrtos_components:
print("**************************************************************")
print("process_module: " + module)
process_module(module)
print("process_azrtos_system_component: " + azrtos_component)
process_azrtos_system_component(azrtos_component)

0 comments on commit 2f85ba6

Please sign in to comment.