Skip to content

Commit

Permalink
fix: support non-identifier library names
Browse files Browse the repository at this point in the history
  • Loading branch information
tydeu committed Nov 15, 2023
1 parent bbc7595 commit 3474703
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Lean/Util/Path.lean
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace SearchPath
`ext` (`lean` or `olean`) corresponding to `mod`. Otherwise, return `none`. Does
not check whether the returned path exists. -/
def findWithExt (sp : SearchPath) (ext : String) (mod : Name) : IO (Option FilePath) := do
let pkg := mod.getRoot.toString
let pkg := mod.getRoot.toString (escape := false)
let root? ← sp.findM? fun p =>
(p / pkg).isDir <||> ((p / pkg).withExtension ext).pathExists
return root?.map (modToFilePath · mod ext)
Expand Down Expand Up @@ -94,7 +94,7 @@ partial def findOLean (mod : Name) : IO FilePath := do
if let some fname ← sp.findWithExt "olean" mod then
return fname
else
let pkg := FilePath.mk mod.getRoot.toString
let pkg := FilePath.mk <| mod.getRoot.toString (escape := false)
let mut msg := s!"unknown package '{pkg}'"
let rec maybeThisOne dir := do
if ← (dir / pkg).isDir then
Expand Down
2 changes: 1 addition & 1 deletion src/lake/Lake/CLI/Init.lean
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def initPkg (dir : FilePath) (name : String) (tmp : InitTemplate) (env : Lake.En
if tmp = .exe || rootExists then
pure (root, rootFile, rootExists)
else
let root := toUpperCamelCase (toUpperCamelCaseString name |>.toName)
let root := toUpperCamelCase pkgName
let rootFile := Lean.modToFilePath dir root "lean"
pure (root, rootFile, ← rootFile.pathExists)

Expand Down
1 change: 1 addition & 0 deletions src/lake/tests/init/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/hello_world
/hello-world
/lean-data
/123-hello
/meta
1 change: 1 addition & 0 deletions src/lake/tests/init/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ rm -rf Hello
rm -rf hello-world
rm -rf hello_world
rm -rf lean-data
rm -rf 123-hello
rm -rf meta
9 changes: 8 additions & 1 deletion src/lake/tests/init/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ $LAKE -d hello-world build
hello-world/.lake/build/bin/hello-world
test -f hello-world/Hello/World/Basic.lean

# Test creating packages with a `-` (i.e., a non-Lean name)
# Test creating packages with a `-` (i.e., a non-identifier package name)
# https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/lake.20new.20lean-data

$LAKE new lean-data
$LAKE -d lean-data build
lean-data/.lake/build/bin/lean-data

# Test creating packages starting with digits (i.e., a non-identifier library name)
# https://github.com/leanprover/lean4/issues/2865

$LAKE new 123-hello
$LAKE -d 123-hello build
123-hello/.lake/build/bin/123-hello

# Test creating packages with keyword names
# https://github.com/leanprover/lake/issues/128

Expand Down

0 comments on commit 3474703

Please sign in to comment.