@@ -138,6 +138,8 @@ proc processImport(c: var DepContext; it: var Cursor; current: Node) =
138138 var x = it
139139 skip it
140140 inc x # skip the `import`
141+ # ignore conditional imports:
142+ if x.stmtKind == WhenS : return
141143 while x.kind != ParRi :
142144 if x.kind == ParLe and x.exprKind == PragmaxX :
143145 inc x
@@ -163,6 +165,8 @@ proc processSingleImport(c: var DepContext; it: var Cursor; current: Node) =
163165 var x = it
164166 skip it
165167 inc x # skip the tag
168+ # ignore conditional imports:
169+ if x.stmtKind == WhenS : return
166170 var files: seq [ImportedFilename ] = @ []
167171 var hasError = false
168172 filenameVal (x, files, hasError, allowAs = true )
@@ -196,12 +200,15 @@ proc processDeps(c: var DepContext; n: Cursor; current: Node) =
196200 while n.kind != ParRi :
197201 processDep c, n, current
198202
199- proc execNifler (c: var DepContext ; input, output: string ) =
200- if not c.forceRebuild and semos.fileExists (output) and semos.fileExists (input) and
201- getLastModificationTime (output) > getLastModificationTime (input):
203+ proc execNifler (c: var DepContext ; f: FilePair ) =
204+ let output = c.config.parsedFile (f)
205+ let depsFile = c.config.depsFile (f)
206+ if not c.forceRebuild and semos.fileExists (output) and
207+ semos.fileExists (f.nimFile) and getLastModificationTime (output) > getLastModificationTime (f.nimFile) and
208+ semos.fileExists (depsFile) and getLastModificationTime (depsFile) > getLastModificationTime (f.nimFile):
202209 discard " nothing to do"
203210 else :
204- let cmd = quoteShell (c.nifler) & " --portablePaths --deps parse " & quoteShell (input ) & " " &
211+ let cmd = quoteShell (c.nifler) & " --portablePaths --deps parse " & quoteShell (f.nimFile ) & " " &
205212 quoteShell (output)
206213 exec cmd
207214
@@ -210,13 +217,13 @@ proc importSystem(c: var DepContext; current: Node) =
210217 current.deps.add p
211218 if not c.processedModules.containsOrIncl (p.modname):
212219 # echo "NIFLING ", p.nimFile, " -> ", c.config.parsedFile(p)
213- execNifler c, p.nimFile, c.config. parsedFile (p)
220+ execNifler c, p
214221 var imported = Node (files: @ [p], id: c.nodes.len, parent: current.id, isSystem: true )
215222 c.nodes.add imported
216223 parseDeps c, p, imported
217224
218225proc parseDeps (c: var DepContext ; p: FilePair ; current: Node ) =
219- execNifler c, p.nimFile, c.config. parsedFile (p)
226+ execNifler c, p
220227
221228 let depsFile = if c.isGeneratingFinal: c.config.deps2File (p) else : c.config.depsFile (p)
222229 var stream = nifstreams.open (depsFile)
@@ -405,40 +412,7 @@ proc generateFrontendBuildFile(c: DepContext; commandLineArgs: string): string =
405412 if arg.len > 0 :
406413 b.addStrLit arg
407414 b.addStrLit " m"
408- b.withTree " input" :
409- b.addIntLit 0 # main parsed file
410- b.withTree " output" :
411- b.addIntLit 0 # semmed file output
412- b.withTree " output" :
413- b.addIntLit 1 # index file output
414-
415- # Command for nimsem with system flag
416- b.withTree " cmd" :
417- b.addSymbolDef " nimsem_system"
418- b.addStrLit c.nimsem
419- if commandLineArgs.len > 0 :
420- for arg in commandLineArgs.split (' ' ):
421- if arg.len > 0 :
422- b.addStrLit arg
423- b.addStrLit " --isSystem"
424- b.addStrLit " m"
425- b.withTree " input" :
426- b.addIntLit 0 # main parsed file
427- b.withTree " output" :
428- b.addIntLit 0 # semmed file output
429- b.withTree " output" :
430- b.addIntLit 1 # index file output
431-
432- # Command for nimsem with main flag
433- b.withTree " cmd" :
434- b.addSymbolDef " nimsem_main"
435- b.addStrLit c.nimsem
436- if commandLineArgs.len > 0 :
437- for arg in commandLineArgs.split (' ' ):
438- if arg.len > 0 :
439- b.addStrLit arg
440- b.addStrLit " --isMain"
441- b.addStrLit " m"
415+ b.addKeyw " args"
442416 b.withTree " input" :
443417 b.addIntLit 0 # main parsed file
444418 b.withTree " output" :
@@ -451,12 +425,12 @@ proc generateFrontendBuildFile(c: DepContext; commandLineArgs: string): string =
451425 for v in c.nodes:
452426 b.withTree " do" :
453427 # Choose the right command based on flags
454- if v.isSystem:
455- b. addIdent " nimsem_system "
456- elif i == 0 : # first node is main
457- b. addIdent " nimsem_main "
458- else :
459- b. addIdent " nimsem "
428+ b. addIdent " nimsem "
429+ b. withTree " args " :
430+ if v.isSystem:
431+ b. addStrLit " --isSystem "
432+ elif i == 0 : # first node is main
433+ b. addStrLit " --isMain "
460434
461435 # Input: parsed file
462436 var seenDeps = initHashSet [string ]()
0 commit comments