rs-toolchain/dist/index.js

1 line
12 KiB
JavaScript

module.exports=function(e,t){"use strict";var s={};function __webpack_require__(t){if(s[t]){return s[t].exports}var i=s[t]={i:t,l:false,exports:{}};e[t].call(i.exports,i,i.exports,__webpack_require__);i.l=true;return i.exports}__webpack_require__.ab=__dirname+"/";function startup(){return __webpack_require__(131)}return startup()}({9:function(e,t,s){"use strict";var i=this&&this.__awaiter||function(e,t,s,i){function adopt(e){return e instanceof s?e:new s(function(t){t(e)})}return new(s||(s=Promise))(function(s,n){function fulfilled(e){try{step(i.next(e))}catch(e){n(e)}}function rejected(e){try{step(i["throw"](e))}catch(e){n(e)}}function step(e){e.done?s(e.value):adopt(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())})};Object.defineProperty(t,"__esModule",{value:true});const n=s(87);const r=s(614);const o=s(129);const u=process.platform==="win32";class ToolRunner extends r.EventEmitter{constructor(e,t,s){super();if(!e){throw new Error("Parameter 'toolPath' cannot be null or empty.")}this.toolPath=e;this.args=t||[];this.options=s||{}}_debug(e){if(this.options.listeners&&this.options.listeners.debug){this.options.listeners.debug(e)}}_getCommandString(e,t){const s=this._getSpawnFileName();const i=this._getSpawnArgs(e);let n=t?"":"[command]";if(u){if(this._isCmdFile()){n+=s;for(const e of i){n+=` ${e}`}}else if(e.windowsVerbatimArguments){n+=`"${s}"`;for(const e of i){n+=` ${e}`}}else{n+=this._windowsQuoteCmdArg(s);for(const e of i){n+=` ${this._windowsQuoteCmdArg(e)}`}}}else{n+=s;for(const e of i){n+=` ${e}`}}return n}_processLineBuffer(e,t,s){try{let i=t+e.toString();let r=i.indexOf(n.EOL);while(r>-1){const e=i.substring(0,r);s(e);i=i.substring(r+n.EOL.length);r=i.indexOf(n.EOL)}t=i}catch(e){this._debug(`error processing line. Failed with error ${e}`)}}_getSpawnFileName(){if(u){if(this._isCmdFile()){return process.env["COMSPEC"]||"cmd.exe"}}return this.toolPath}_getSpawnArgs(e){if(u){if(this._isCmdFile()){let t=`/D /S /C "${this._windowsQuoteCmdArg(this.toolPath)}`;for(const s of this.args){t+=" ";t+=e.windowsVerbatimArguments?s:this._windowsQuoteCmdArg(s)}t+='"';return[t]}}return this.args}_endsWith(e,t){return e.endsWith(t)}_isCmdFile(){const e=this.toolPath.toUpperCase();return this._endsWith(e,".CMD")||this._endsWith(e,".BAT")}_windowsQuoteCmdArg(e){if(!this._isCmdFile()){return this._uvQuoteCmdArg(e)}if(!e){return'""'}const t=[" ","\t","&","(",")","[","]","{","}","^","=",";","!","'","+",",","`","~","|","<",">",'"'];let s=false;for(const i of e){if(t.some(e=>e===i)){s=true;break}}if(!s){return e}let i='"';let n=true;for(let t=e.length;t>0;t--){i+=e[t-1];if(n&&e[t-1]==="\\"){i+="\\"}else if(e[t-1]==='"'){n=true;i+='"'}else{n=false}}i+='"';return i.split("").reverse().join("")}_uvQuoteCmdArg(e){if(!e){return'""'}if(!e.includes(" ")&&!e.includes("\t")&&!e.includes('"')){return e}if(!e.includes('"')&&!e.includes("\\")){return`"${e}"`}let t='"';let s=true;for(let i=e.length;i>0;i--){t+=e[i-1];if(s&&e[i-1]==="\\"){t+="\\"}else if(e[i-1]==='"'){s=true;t+="\\"}else{s=false}}t+='"';return t.split("").reverse().join("")}_cloneExecOptions(e){e=e||{};const t={cwd:e.cwd||process.cwd(),env:e.env||process.env,silent:e.silent||false,windowsVerbatimArguments:e.windowsVerbatimArguments||false,failOnStdErr:e.failOnStdErr||false,ignoreReturnCode:e.ignoreReturnCode||false,delay:e.delay||1e4};t.outStream=e.outStream||process.stdout;t.errStream=e.errStream||process.stderr;return t}_getSpawnOptions(e,t){e=e||{};const s={};s.cwd=e.cwd;s.env=e.env;s["windowsVerbatimArguments"]=e.windowsVerbatimArguments||this._isCmdFile();if(e.windowsVerbatimArguments){s.argv0=`"${t}"`}return s}exec(){return i(this,void 0,void 0,function*(){return new Promise((e,t)=>{this._debug(`exec tool: ${this.toolPath}`);this._debug("arguments:");for(const e of this.args){this._debug(` ${e}`)}const s=this._cloneExecOptions(this.options);if(!s.silent&&s.outStream){s.outStream.write(this._getCommandString(s)+n.EOL)}const i=new ExecState(s,this.toolPath);i.on("debug",e=>{this._debug(e)});const r=this._getSpawnFileName();const u=o.spawn(r,this._getSpawnArgs(s),this._getSpawnOptions(this.options,r));const c="";if(u.stdout){u.stdout.on("data",e=>{if(this.options.listeners&&this.options.listeners.stdout){this.options.listeners.stdout(e)}if(!s.silent&&s.outStream){s.outStream.write(e)}this._processLineBuffer(e,c,e=>{if(this.options.listeners&&this.options.listeners.stdline){this.options.listeners.stdline(e)}})})}const l="";if(u.stderr){u.stderr.on("data",e=>{i.processStderr=true;if(this.options.listeners&&this.options.listeners.stderr){this.options.listeners.stderr(e)}if(!s.silent&&s.errStream&&s.outStream){const t=s.failOnStdErr?s.errStream:s.outStream;t.write(e)}this._processLineBuffer(e,l,e=>{if(this.options.listeners&&this.options.listeners.errline){this.options.listeners.errline(e)}})})}u.on("error",e=>{i.processError=e.message;i.processExited=true;i.processClosed=true;i.CheckComplete()});u.on("exit",e=>{i.processExitCode=e;i.processExited=true;this._debug(`Exit code ${e} received from tool '${this.toolPath}'`);i.CheckComplete()});u.on("close",e=>{i.processExitCode=e;i.processExited=true;i.processClosed=true;this._debug(`STDIO streams have closed for tool '${this.toolPath}'`);i.CheckComplete()});i.on("done",(s,i)=>{if(c.length>0){this.emit("stdline",c)}if(l.length>0){this.emit("errline",l)}u.removeAllListeners();if(s){t(s)}else{e(i)}})})})}}t.ToolRunner=ToolRunner;function argStringToArray(e){const t=[];let s=false;let i=false;let n="";function append(e){if(i&&e!=='"'){n+="\\"}n+=e;i=false}for(let r=0;r<e.length;r++){const o=e.charAt(r);if(o==='"'){if(!i){s=!s}else{append(o)}continue}if(o==="\\"&&i){append(o);continue}if(o==="\\"&&s){i=true;continue}if(o===" "&&!s){if(n.length>0){t.push(n);n=""}continue}append(o)}if(n.length>0){t.push(n.trim())}return t}t.argStringToArray=argStringToArray;class ExecState extends r.EventEmitter{constructor(e,t){super();this.processClosed=false;this.processError="";this.processExitCode=0;this.processExited=false;this.processStderr=false;this.delay=1e4;this.done=false;this.timeout=null;if(!t){throw new Error("toolPath must not be empty")}this.options=e;this.toolPath=t;if(e.delay){this.delay=e.delay}}CheckComplete(){if(this.done){return}if(this.processClosed){this._setResult()}else if(this.processExited){this.timeout=setTimeout(ExecState.HandleTimeout,this.delay,this)}}_debug(e){this.emit("debug",e)}_setResult(){let e;if(this.processExited){if(this.processError){e=new Error(`There was an error when attempting to execute the process '${this.toolPath}'. This may indicate the process failed to start. Error: ${this.processError}`)}else if(this.processExitCode!==0&&!this.options.ignoreReturnCode){e=new Error(`The process '${this.toolPath}' failed with exit code ${this.processExitCode}`)}else if(this.processStderr&&this.options.failOnStdErr){e=new Error(`The process '${this.toolPath}' failed because one or more lines were written to the STDERR stream`)}}if(this.timeout){clearTimeout(this.timeout);this.timeout=null}this.done=true;this.emit("done",e,this.processExitCode)}static HandleTimeout(e){if(e.done){return}if(!e.processClosed&&e.processExited){const t=`The STDIO streams did not close within ${e.delay/1e3} seconds of the exit event from process '${e.toolPath}'. This may indicate a child process inherited the STDIO streams and has not yet exited.`;e._debug(t)}e._setResult()}}},87:function(e){e.exports=require("os")},129:function(e){e.exports=require("child_process")},131:function(e,t,s){"use strict";var i=this&&this.__awaiter||function(e,t,s,i){function adopt(e){return e instanceof s?e:new s(function(t){t(e)})}return new(s||(s=Promise))(function(s,n){function fulfilled(e){try{step(i.next(e))}catch(e){n(e)}}function rejected(e){try{step(i["throw"](e))}catch(e){n(e)}}function step(e){e.done?s(e.value):adopt(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())})};var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var s in e)if(Object.hasOwnProperty.call(e,s))t[s]=e[s];t["default"]=e;return t};Object.defineProperty(t,"__esModule",{value:true});const r=n(s(470));const o=n(s(986));const u=n(s(958));function do_exec(e,t){return i(this,void 0,void 0,function*(){try{yield o.exec(e,t)}catch(e){r.setFailed(e.message)}})}function run(){return i(this,void 0,void 0,function*(){let e=u.toolchain_args();yield do_exec("rustup",["toolchain","install",e.name]);if(e.default){yield do_exec("rustup",["default",e.name])}if(e.override){yield do_exec("rustup",["override",e.name])}})}run()},431:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:true});const i=s(87);function issueCommand(e,t,s){const n=new Command(e,t,s);process.stdout.write(n.toString()+i.EOL)}t.issueCommand=issueCommand;function issue(e,t){issueCommand(e,{},t)}t.issue=issue;const n="##[";class Command{constructor(e,t,s){if(!e){e="missing.command"}this.command=e;this.properties=t;this.message=s}toString(){let e=n+this.command;if(this.properties&&Object.keys(this.properties).length>0){e+=" ";for(const t in this.properties){if(this.properties.hasOwnProperty(t)){const s=this.properties[t];if(s){e+=`${t}=${escape(`${s||""}`)};`}}}}e+="]";const t=`${this.message||""}`;e+=escapeData(t);return e}}function escapeData(e){return e.replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function escape(e){return e.replace(/\r/g,"%0D").replace(/\n/g,"%0A").replace(/]/g,"%5D").replace(/;/g,"%3B")}},470:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:true});const i=s(431);const n=s(622);var r;(function(e){e[e["Success"]=0]="Success";e[e["Failure"]=1]="Failure"})(r=t.ExitCode||(t.ExitCode={}));function exportVariable(e,t){process.env[e]=t;i.issueCommand("set-env",{name:e},t)}t.exportVariable=exportVariable;function exportSecret(e,t){exportVariable(e,t);i.issueCommand("set-secret",{},t)}t.exportSecret=exportSecret;function addPath(e){i.issueCommand("add-path",{},e);process.env["PATH"]=`${e}${n.delimiter}${process.env["PATH"]}`}t.addPath=addPath;function getInput(e,t){const s=process.env[`INPUT_${e.replace(" ","_").toUpperCase()}`]||"";if(t&&t.required&&!s){throw new Error(`Input required and not supplied: ${e}`)}return s.trim()}t.getInput=getInput;function setOutput(e,t){i.issueCommand("set-output",{name:e},t)}t.setOutput=setOutput;function setFailed(e){process.exitCode=r.Failure;error(e)}t.setFailed=setFailed;function debug(e){i.issueCommand("debug",{},e)}t.debug=debug;function error(e){i.issue("error",e)}t.error=error;function warning(e){i.issue("warning",e)}t.warning=warning},614:function(e){e.exports=require("events")},622:function(e){e.exports=require("path")},958:function(e,t,s){"use strict";var i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var s in e)if(Object.hasOwnProperty.call(e,s))t[s]=e[s];t["default"]=e;return t};Object.defineProperty(t,"__esModule",{value:true});const n=i(s(470));function getInput(e,t){const s=e.replace(/-/g,"_");let i=n.getInput(s,t);if(i.length>0){return i}return n.getInput(e)}function inputBoolean(e){const t=getInput(e);if(t=="true"||t=="1"){return true}else{return false}}function toolchain_args(){return{name:getInput("toolchain",{required:true}),default:inputBoolean("default"),override:inputBoolean("override")}}t.toolchain_args=toolchain_args},986:function(e,t,s){"use strict";var i=this&&this.__awaiter||function(e,t,s,i){function adopt(e){return e instanceof s?e:new s(function(t){t(e)})}return new(s||(s=Promise))(function(s,n){function fulfilled(e){try{step(i.next(e))}catch(e){n(e)}}function rejected(e){try{step(i["throw"](e))}catch(e){n(e)}}function step(e){e.done?s(e.value):adopt(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())})};Object.defineProperty(t,"__esModule",{value:true});const n=s(9);function exec(e,t,s){return i(this,void 0,void 0,function*(){const i=n.argStringToArray(e);if(i.length===0){throw new Error(`Parameter 'commandLine' cannot be null or empty.`)}const r=i[0];t=i.slice(1).concat(t||[]);const o=new n.ToolRunner(r,t,s);return o.exec()})}t.exec=exec}});