build_app: make multi target support readable

This commit is contained in:
Fu Hanxi
2020-04-09 16:40:57 +08:00
committed by Ivan Grokhotkov
parent 2e14149bff
commit 5b2fa1a5ad
164 changed files with 295 additions and 95 deletions

View File

@@ -4,6 +4,7 @@ import subprocess
import logging
import shutil
import re
from .common import BuildSystem, BuildItem, BuildError
BUILD_SYSTEM_CMAKE = "cmake"
@@ -13,7 +14,12 @@ IDF_PY = "idf.py"
# there is no equivalent for the project CMakeLists files. This seems to be the best option...
CMAKE_PROJECT_LINE = r"include($ENV{IDF_PATH}/tools/cmake/project.cmake)"
SUPPORTED_TARGETS_REGEX = re.compile(r"set\(\s*SUPPORTED_TARGETS\s+([a-z_0-9\- ]+)\s*\)")
SUPPORTED_TARGETS_REGEX = re.compile(r'Supported [Tt]argets((?:[\s|]+(?:ESP[0-9A-Z\-]+))+)')
FORMAL_TO_USUAL = {
'ESP32': 'esp32',
'ESP32-S2': 'esp32s2',
}
class CMakeBuildSystem(BuildSystem):
@@ -137,6 +143,32 @@ class CMakeBuildSystem(BuildSystem):
with open(cmakelists_path, "r") as cmakelists_file:
return cmakelists_file.read()
@staticmethod
def _read_readme(app_path):
# Markdown supported targets should be:
# e.g. | Supported Targets | ESP32 |
# | ----------------- | ----- |
# reStructuredText supported targets should be:
# e.g. ================= =====
# Supported Targets ESP32
# ================= =====
def get_md_or_rst(app_path):
readme_path = os.path.join(app_path, 'README.md')
if not os.path.exists(readme_path):
readme_path = os.path.join(app_path, 'README.rst')
if not os.path.exists(readme_path):
return None
return readme_path
readme_path = get_md_or_rst(app_path)
# Handle sub apps situation, e.g. master-slave
if not readme_path:
readme_path = get_md_or_rst(os.path.dirname(app_path))
if not readme_path:
return None
with open(readme_path, "r") as readme_file:
return readme_file.read()
@staticmethod
def is_app(path):
cmakelists_file_content = CMakeBuildSystem._read_cmakelists(path)
@@ -148,13 +180,25 @@ class CMakeBuildSystem(BuildSystem):
@staticmethod
def supported_targets(app_path):
cmakelists_file_content = CMakeBuildSystem._read_cmakelists(app_path)
if not cmakelists_file_content:
readme_file_content = CMakeBuildSystem._read_readme(app_path)
if not readme_file_content:
return None
match = re.findall(SUPPORTED_TARGETS_REGEX, cmakelists_file_content)
match = re.findall(SUPPORTED_TARGETS_REGEX, readme_file_content)
if not match:
return None
if len(match) > 1:
raise NotImplementedError("Can't determine the value of SUPPORTED_TARGETS in {}".format(app_path))
targets = match[0].split(" ")
support_str = match[0].strip()
targets = []
for part in support_str.split('|'):
for inner in part.split(' '):
inner = inner.strip()
if not inner:
continue
elif inner in FORMAL_TO_USUAL:
targets.append(FORMAL_TO_USUAL[inner])
else:
raise NotImplementedError("Can't recognize value of target {} in {}, now we only support '{}'"
.format(inner, app_path, ', '.join(FORMAL_TO_USUAL.keys())))
return targets