+ def complete_environment(self, make_options):
+ assert self.build_environ is not None
+ # pass additional variables to environment
+ # (may be used by the build script)
+ self.build_environ.set("APPLICATION_NAME", self.config.APPLICATION.name)
+ self.build_environ.set("SOURCE_DIR", str(self.source_dir))
+ self.build_environ.set("INSTALL_DIR", str(self.install_dir))
+ self.build_environ.set("PRODUCT_INSTALL", str(self.install_dir))
+ self.build_environ.set("BUILD_DIR", str(self.build_dir))
+ self.build_environ.set("PRODUCT_BUILD", str(self.build_dir))
+ self.build_environ.set("MAKE_OPTIONS", make_options)
+ self.build_environ.set("DIST_NAME", self.config.VARS.dist_name)
+ self.build_environ.set("DIST_VERSION", self.config.VARS.dist_version)
+ self.build_environ.set("DIST", self.config.VARS.dist)
+ self.build_environ.set("VERSION", self.product_info.version)
+ # if product is in hpc mode, set SAT_HPC to 1
+ # in order for the compilation script to take it into account
+ if src.product.product_is_hpc(self.product_info):
+ self.build_environ.set("SAT_HPC", "1")
+
+ def do_batch_script_build(self, script, nb_proc):
+
+ if src.architecture.is_windows():
+ make_options = "/maxcpucount:%s" % nb_proc
+ else :
+ make_options = "-j%s" % nb_proc
+
+ self.log_command(" " + _("Run build script %s\n") % script)
+ self.complete_environment(make_options)
+
+ res = subprocess.call(script,
+ shell=True,
+ stdout=self.logger.logTxtFile,
+ stderr=subprocess.STDOUT,
+ cwd=str(self.build_dir),
+ env=self.build_environ.environ.environ)
+
+ res_check=self.check_install()
+ if res_check > 0 :
+ self.log_command("Error in sat check install - some files are not installed!")
+
+ self.put_txt_log_in_appli_log_dir("script")
+ res += res_check
+ if res == 0:
+ return res
+ else:
+ return 1
+
+ def do_script_build(self, script, number_of_proc=0):
+ # define make options (may not be used by the script)
+ if number_of_proc==0:
+ nb_proc = src.get_cfg_param(self.product_info,"nb_proc", 0)
+ if nb_proc == 0:
+ nb_proc = self.config.VARS.nb_proc
+ else:
+ nb_proc = min(number_of_proc, self.config.VARS.nb_proc)
+
+ extension = script.split('.')[-1]
+ if extension in ["bat","sh"]:
+ return self.do_batch_script_build(script, nb_proc)
+ if extension == "py":
+ return self.do_python_script_build(script, nb_proc)
+
+ msg = _("The script %s must have .sh, .bat or .py extension." % script)
+ raise src.SatException(msg)
+
+ def put_txt_log_in_appli_log_dir(self, file_name):
+ '''Put the txt log (that contain the system logs, like make command
+ output) in the directory <APPLICATION DIR>/LOGS/<product_name>/
+
+ :param file_name Str: the name of the file to write
+ '''
+ if self.logger.logTxtFile == sys.__stdout__:
+ return
+ dir_where_to_put = os.path.join(self.config.APPLICATION.workdir,
+ "LOGS",
+ self.product_info.name)
+ file_path = os.path.join(dir_where_to_put, file_name)
+ src.ensure_path_exists(dir_where_to_put)
+ # write the logTxtFile copy it to the destination, and then recreate
+ # it as it was
+ self.logger.logTxtFile.close()
+ shutil.move(self.logger.txtFilePath, file_path)
+ self.logger.logTxtFile = open(str(self.logger.txtFilePath), 'w')
+ self.logger.logTxtFile.write(open(file_path, "r").read())
+