T7.4: Dependency resolution — deps.edn parser, Git deps, cljnim deps command, 12 tests
This commit is contained in:
+31
-6
@@ -1,6 +1,6 @@
|
||||
# Clojure/Nim — AI-First Clojure Compiler
|
||||
import os, osproc, strutils, times
|
||||
import reader, emitter, types, repl, macros
|
||||
import reader, emitter, types, repl, macros, deps
|
||||
|
||||
proc getLibPath(): string =
|
||||
let appDir = getAppDir()
|
||||
@@ -44,17 +44,20 @@ proc extractRequires(forms: seq[CljVal]): seq[(string, string)] =
|
||||
alias = req.items[2].symName
|
||||
result.add((libName, alias))
|
||||
|
||||
proc compileFile*(inputPath: string, outputPath: string) =
|
||||
proc compileFile*(inputPath: string, outputPath: string, extraPaths: seq[string] = @[]) =
|
||||
let source = readFile(inputPath)
|
||||
let forms = reader.readAll(source)
|
||||
|
||||
|
||||
if forms.len == 0:
|
||||
stderr.writeLine("Error: No forms found in " & inputPath)
|
||||
quit(1)
|
||||
|
||||
|
||||
# Resolve requires and collect all forms from required files
|
||||
let inputDir = inputPath.parentDir
|
||||
let searchPaths = @[inputDir, getCurrentDir()]
|
||||
var searchPaths: seq[string] = @[inputDir, getCurrentDir()]
|
||||
for p in extraPaths:
|
||||
if p notin searchPaths:
|
||||
searchPaths.add(p)
|
||||
let requires = extractRequires(forms)
|
||||
|
||||
var allForms: seq[CljVal] = @[]
|
||||
@@ -114,6 +117,10 @@ proc runFile*(inputPath: string) =
|
||||
let nimPath = tmpDir / baseName & "_generated.nim"
|
||||
let binPath = tmpDir / baseName & "_generated"
|
||||
|
||||
# Resolve project dependencies
|
||||
let inputDir = inputPath.parentDir
|
||||
let depPaths = deps.loadAndResolve(if inputDir.len > 0: inputDir else: getCurrentDir())
|
||||
|
||||
# Check nimcache for cached output
|
||||
let projectDir = inputPath.parentDir
|
||||
let cacheDir = projectDir / "nimcache"
|
||||
@@ -136,7 +143,7 @@ proc runFile*(inputPath: string) =
|
||||
let runResult = execCmd(cacheBinPath)
|
||||
quit(runResult)
|
||||
|
||||
compileFile(inputPath, nimPath)
|
||||
compileFile(inputPath, nimPath, depPaths)
|
||||
|
||||
let compileResult = nimCompile(nimPath, binPath)
|
||||
if compileResult != 0:
|
||||
@@ -169,6 +176,7 @@ proc main() =
|
||||
echo " cljnim run <file.clj> Compile and run binary"
|
||||
echo " cljnim read <file.clj> Parse and print AST"
|
||||
echo " cljnim repl [--json] Start REPL (human or AI mode)"
|
||||
echo " cljnim deps Resolve dependencies from deps.edn"
|
||||
echo " cljnim -e '<code>' Evaluate expression"
|
||||
echo ""
|
||||
echo "REPL Commands:"
|
||||
@@ -261,6 +269,23 @@ proc main() =
|
||||
finally:
|
||||
state.cleanup()
|
||||
|
||||
of "deps":
|
||||
let projectDir = getCurrentDir()
|
||||
let depsPath = deps.findDepsFile(projectDir)
|
||||
if depsPath.len == 0:
|
||||
echo "No deps.edn or project.clj found"
|
||||
quit(0)
|
||||
echo "Found: ", depsPath
|
||||
let depsFile = deps.parseDepsFile(depsPath)
|
||||
echo "Dependencies: ", depsFile.deps.len
|
||||
let paths = deps.resolveDeps(depsFile, depsPath.parentDir)
|
||||
if paths.len > 0:
|
||||
echo "Resolved paths:"
|
||||
for p in paths:
|
||||
echo " ", p
|
||||
else:
|
||||
echo "No dependencies to resolve"
|
||||
|
||||
else:
|
||||
stderr.writeLine("Unknown command: " & cmd)
|
||||
quit(1)
|
||||
|
||||
Reference in New Issue
Block a user