import os
from xdevice import platform_logger
from core.utils import scan_support_product
from core.config.config_manager import UserConfigManager, FrameworkConfigManager
from core.build.select_targets import SelectTargets
from core.build.pretreat_targets import PretreatTargets
from core.build.build_testcases import BuildTestcases
from core.command.gen import Gen
LOG = platform_logger("BuildManager")
class BuildManager(object):
@classmethod
def _make_gn_file(cls, filepath, target_list):
LOG.info("The gn file path: %s" % filepath)
with open(filepath, "w") as gn_file:
gn_file.write("group(\"make_temp_test\") {\n")
gn_file.write(" testonly = true\n")
gn_file.write(" deps = []\n")
if target_list:
gn_file.write(" deps += [\n")
for target in target_list:
if target:
gn_file.write(" \"%s\",\n" % target)
gn_file.write(" ]\n")
gn_file.write("}\n")
@classmethod
def _compile_test_cases_by_target(cls, project_root_path, product_form,
build_target):
if BuildTestcases(project_root_path).build_testcases(product_form,
build_target):
LOG.info("Test case compilation successed.")
build_result = True
else:
LOG.info("Test case compilation failed, please modify.")
build_result = False
return build_result
@classmethod
def _compile_acts_test_cases(cls, project_root_path, para):
if BuildTestcases(project_root_path).build_acts_testcases(para):
LOG.info("Acts test case compilation successed.")
build_result = True
else:
LOG.info("Acts test compilation failed, please modify.")
build_result = False
return build_result
@classmethod
def _compile_fuzz_test_case(cls, project_root_path, para):
build_result = BuildTestcases(
project_root_path).build_fuzz_testcases(para)
if build_result:
LOG.info("Test case compilation successed.")
else:
LOG.info("Test case compilation failed, please modify.")
return build_result
def _compile_testcases(self, project_root_path, para):
all_product_list = scan_support_product()
product_list = FrameworkConfigManager().get_framework_config("productform")
if para.productform in product_list and para.productform.find("wifiiot") == -1:
all_product_list.append(para.productform)
if para.productform not in all_product_list:
from core.build.build_lite_manager import BuildLiteManager
build_lite_manager = BuildLiteManager(project_root_path)
return build_lite_manager.build_testcases(para)
if para.testsuit != "":
return self._compile_test_cases_by_target(
project_root_path,
para.productform,
para.testsuit)
if (len(para.partname_list) == 0 and para.testmodule == "" and
"ALL" in para.testtype):
return self._compile_test_cases_by_target(
project_root_path,
para.productform,
"make_test")
target_list = SelectTargets(
project_root_path).filter_build_targets(para)
if len(target_list) == 0:
LOG.warning("No build target found.")
return False
build_cfg_filepath = os.path.join(project_root_path,
"test",
"testfwk",
"developer_test",
"BUILD.gn")
self._make_gn_file(build_cfg_filepath, target_list)
if "fuzztest" in para.testtype:
Gen().gen_fuzzer_list_file(target_list)
build_result = self._compile_fuzz_test_case(
project_root_path, para)
else:
build_result = self._compile_test_cases_by_target(
project_root_path,
para.productform,
"make_temp_test")
self._make_gn_file(build_cfg_filepath, [])
return build_result
@classmethod
def build_version(cls, project_root_path, product_form):
if BuildTestcases(project_root_path).build_version(product_form):
LOG.info("The version compiled successfully.")
build_result = True
else:
LOG.info("The version compilation failed, please modify.")
build_result = False
return build_result
@classmethod
def build_gn_file(cls, project_root_path, product_form):
if BuildTestcases(project_root_path).build_gn_file(product_form):
LOG.info("The gn compiled successfully.")
build_result = True
else:
LOG.info("The gn compilation failed, please modify.")
build_result = False
return build_result
def build_testcases(self, project_root_path, param):
if not os.path.exists(project_root_path):
LOG.error("%s is not exists." % project_root_path)
return False
LOG.info("--------------------------------------------------")
LOG.info("Building parameter:")
LOG.info("productform = %s" % param.productform)
LOG.info("testtype = %s" % str(param.testtype))
LOG.info("partname_list = %s" % str(param.partname_list))
LOG.info("testmodule = %s" % param.testmodule)
LOG.info("testsuit = %s" % param.testsuit)
LOG.info("testcase = %s" % param.testcase)
LOG.info("--------------------------------------------------")
LOG.info("")
LOG.info("**************************************************")
LOG.info("*************** Start build testcases ************")
LOG.info("**************************************************")
LOG.info("")
build_acts_result = True
build_result = True
if "actstest" in param.testtype:
LOG.info("**********************Start build acts testcases****************************")
build_acts_result = self._compile_acts_test_cases(project_root_path, param)
else:
LOG.info("**********************Start build subsystem testcases****************************")
build_result = self._compile_testcases(project_root_path, param)
LOG.info("")
LOG.info("**************************************************")
LOG.info("*************** Ended build testcases ************")
LOG.info("**************************************************")
LOG.info("")
return build_result and build_acts_result