@@ -149,6 +149,27 @@ async function handleJob(taskId, rcl, message) {
149149 var numRetries = process . env . HF_VAR_NUMBER_OF_RETRIES || 1 ;
150150 var backoffSeed = process . env . HF_VAR_BACKOFF_SEED || 10 ;
151151
152+ // Rewrite command args by adding path to input directory if one is defined
153+ function addDirToCommand ( jobIns , args , dir ) {
154+ let newArgs = args ;
155+ let changed = false ;
156+ jobIns . forEach ( function ( jobInput ) {
157+ if ( jobInput . workflow_input ) { // this is a workflow input
158+ newArgs . forEach ( function ( arg , idx ) {
159+ if ( arg === jobInput . name ) {
160+ newArgs [ idx ] = path . join ( dir , arg ) ;
161+ changed = true ;
162+ }
163+ } ) ;
164+ }
165+ } ) ;
166+ if ( changed ) {
167+ console . log ( "INPUT_DIR provided, command rewritten:" , jm [ "executable" ] , newArgs ) ;
168+ logger . info ( "INPUT_DIR provided, command rewritten:" , jm [ "executable" ] , newArgs ) ;
169+ }
170+ return newArgs ;
171+ }
172+
152173 async function executeJob ( jm , attempt ) {
153174 return new Promise ( ( resolve , reject ) => {
154175 if ( process . env . HF_VAR_DRY_RUN ) {
@@ -162,7 +183,13 @@ async function handleJob(taskId, rcl, message) {
162183 options = { shell : true } ;
163184 }
164185
165- const cmd = spawn ( jm [ "executable" ] , jm [ "args" ] , options ) ;
186+ let commandArgs = jm [ "args" ] ;
187+ let jobIns = jm [ "inputs" ] ;
188+ if ( inputDir ) {
189+ commandArgs = addDirToCommand ( jobIns , commandArgs , inputDir ) ;
190+ }
191+
192+ const cmd = spawn ( jm [ "executable" ] , commandArgs , options ) ;
166193 let targetPid = cmd . pid ;
167194 cmd . stdout . pipe ( stdoutLog ) ;
168195 cmd . stderr . pipe ( stderrLog ) ;
@@ -317,7 +344,7 @@ async function handleJob(taskId, rcl, message) {
317344
318345 var workDir = process . cwd ( ) ;
319346 var logDir = process . env . HF_VAR_LOG_DIR || ( workDir + "/logs-hf" ) ;
320- var inputDir = process . env . HF_VAR_INPUT_DIR || workDir ;
347+ var inputDir = process . env . HF_VAR_INPUT_DIR ;
321348 var outputDir = process . env . HF_VAR_OUTPUT_DIR || workDir ;
322349
323350 // make sure log directory is created
0 commit comments