123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)openFilename.InfixmoduleEvents=Updater_events(** Compiler *)letdatadir=refNoneletget_datadir()=letopenLwt_syntaxinmatch!datadirwith|None->let*()=Events.(emitnode_uninitialized)()inLwt_exit.exit_and_raise1|Somem->Lwt.returnmletinitdir=datadir:=Somedirletcompiler_name="octez-protocol-compiler"letdo_compilehashp=letopenLwt_syntaxinlet*datadir=get_datadir()inletsource_dir=datadir//Protocol_hash.to_short_b58checkhash//"src"inletlog_file=datadir//Protocol_hash.to_short_b58checkhash//"LOG"inletplugin_file=datadir//Protocol_hash.to_short_b58checkhash//Format.asprintf"protocol_%a"Protocol_hash.pphashintryDynlink.loadfile_private(plugin_file^".cmxs");Lwt.return_truewithDynlink.Error_->(let*r=Tezos_base_unix.Protocol_files.write_dirsource_dir~hashpinmatchrwith|Errorerr->let*()=Events.(emitcompiler_exit_error)errinLwt.return_false|Ok()->(letcompiler_command=(Sys.executable_name,[|compiler_name;"-register";"-o";plugin_file;source_dir|])inletfd=Unix.(openfilelog_file[O_WRONLY;O_CREAT;O_TRUNC]0o644)inlet*s=Lwt_process.exec~stdin:`Close~stdout:(`FD_copyfd)~stderr:(`FD_movefd)compiler_commandinmatchswith|Unix.WSIGNALED_|Unix.WSTOPPED_->let*()=Events.(emitcompilation_interrupted)log_fileinLwt.return_false|Unix.WEXITEDxwhenx<>0->let*()=Events.(emitcompilation_error)log_fileinLwt.return_false|Unix.WEXITED_->(tryDynlink.loadfile_private(plugin_file^".cmxs");Lwt.return_truewith|Dynlink.(Error(Cannot_open_dynamic_libraryexn))->let*()=Events.(emitdynlink_error_static)(plugin_file,Printexc.to_stringexn)inLwt.return_false|Dynlink.(Errorerr)->let*()=Events.(emitdynlink_error)(plugin_file,Dynlink.error_messageerr)inLwt.return_false)))letcompilehashp=letopenLwt_syntaxinifTezos_protocol_registerer.memhashthenLwt.return_trueelselet*success=do_compilehashpinletloaded=Tezos_protocol_registerer.memhashinifsuccess&¬loadedthenlet*()=Events.(emitinternal_error)hashinLwt.returnloadedelseLwt.returnloaded