def _redirect_logs(): util.lazy_remove_file("log/out.log") os.mkfifo("log/out.log") log_ratelimit = os.getenv("LOG_RATELIMIT", None) if log_ratelimit is None: subprocess.Popen([ "sed", "--unbuffered", "s|^[0-9\-]\+\s[0-9:\.]\+\s||", "log/out.log", ]) else: log_filter_thread = LogFilterThread(log_ratelimit) log_filter_thread.daemon = True log_filter_thread.start()
def stage(build_path, cache_path, local_path, runtime_version, java_version): mono_location = mono.ensure_and_get_mono(runtime_version, cache_path) logging.info("Mono available: %s", mono_location) mono_env = mono.get_env_with_monolib(mono_location) mxbuild_location = os.path.join(local_path, "mxbuild") ensure_mxbuild_in_directory(mxbuild_location, runtime_version, cache_path) jvm_location = java.ensure_and_get_jvm(java_version, cache_path, local_path) util.lazy_remove_file(BUILD_ERRORS_JSON) args = [ os.path.join(mono_location, "bin/mono"), "--config", os.path.join(mono_location, "etc/mono/config"), os.path.join(mxbuild_location, "modeler/mxbuild.exe"), "--target=package", "--output=/tmp/model.mda", "--java-home=%s" % jvm_location, "--java-exe-path=%s" % os.path.join(jvm_location, "bin/java"), ] if runtime_version >= 6.4 or os.environ.get("FORCE_WRITE_BUILD_ERRORS"): args.append("--write-errors=%s" % BUILD_ERRORS_JSON) logging.debug("Will write build errors to %s", BUILD_ERRORS_JSON) if os.environ.get("FORCED_MXBUILD_URL"): args.append("--loose-version-check") logging.warning( "Using forced mxbuild version, the model will be converted") args.append(util.get_mpr_file_from_dir(build_path)) try: logging.debug("subprocess call %s", args) subprocess.check_call(args, env=mono_env) except subprocess.CalledProcessError as ex: buildstatus_callback(BUILD_ERRORS_JSON) raise RuntimeError(ex) for file_name in os.listdir(build_path): filepath = os.path.join(build_path, file_name) if file_name != ".local": if os.path.isdir(filepath): shutil.rmtree(filepath) else: os.unlink(filepath) zf = zipfile.ZipFile("/tmp/model.mda") try: zf.extractall(build_path) finally: zf.close() try: with open(os.path.join(build_path, ".sourcepush"), "w") as dsp: dsp.write("sourcepush") except OSError as ex: logging.warning("Could not write source push indicator: %s", str(ex))
def build_from_source( buildpack_path, build_path, cache_path, local_path, runtime_version, java_version, ): logging.info("Building from source...") mono_location = mono.ensure_and_get_mono(runtime_version, buildpack_path, cache_path) mono_env = mono.get_env_with_monolib(mono_location) mxbuild_location = os.path.join(local_path, "mxbuild") runtime.resolve_runtime_dependency( buildpack_path, build_path, cache_path, destination=mxbuild_location, prefix="mxbuild", ) jdk_location = java.ensure_and_get_jvm(java_version, buildpack_path, cache_path, local_path) util.lazy_remove_file(BUILD_ERRORS_JSON) args = [ os.path.join(mono_location, "bin/mono"), "--config", os.path.join(mono_location, "etc/mono/config"), os.path.join(mxbuild_location, "modeler/mxbuild.exe"), "--target=package", "--output=/tmp/model.mda", "--java-home=%s" % jdk_location, "--java-exe-path=%s" % os.path.join(jdk_location, "bin/java"), ] if runtime_version >= 6.4 or os.environ.get("FORCE_WRITE_BUILD_ERRORS"): args.append("--write-errors=%s" % BUILD_ERRORS_JSON) logging.debug("Will write build errors to %s", BUILD_ERRORS_JSON) if os.environ.get("FORCED_MXBUILD_URL"): args.append("--loose-version-check") logging.warning( "Using forced MxBuild version, the model will be converted") args.append(util.get_mpr_file_from_dir(build_path)) try: subprocess.check_call(args, env=mono_env) except subprocess.CalledProcessError as ex: _log_buildstatus_errors(BUILD_ERRORS_JSON) raise RuntimeError(ex) for file_name in os.listdir(build_path): filepath = os.path.join(build_path, file_name) if file_name != ".local": if os.path.isdir(filepath): shutil.rmtree(filepath) else: os.unlink(filepath) zf = zipfile.ZipFile("/tmp/model.mda") try: zf.extractall(build_path) finally: zf.close() try: with open(os.path.join(build_path, ".sourcepush"), "w") as dsp: dsp.write("sourcepush") except OSError as ex: logging.warning("Could not write source push indicator: %s", str(ex)) logging.debug("Deleting Mxbuild, Mono and JDK...") for path in (mono_location, mxbuild_location, jdk_location): shutil.rmtree(path, ignore_errors=False) if os.path.exists(path): logging.error("%s not deleted", path) logging.info("Building from source completed")