Skip to content

Commit

Permalink
Remove install-lj and install-rocks commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mah0x211 committed Apr 5, 2024
1 parent 70068c8 commit 42d8720
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 61 deletions.
19 changes: 9 additions & 10 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,25 @@ Commands:
vers List available versions
ls List installed versions
install <version> <opt...> Install and use a <version> of lua
install-lj <version> <opt...> Install and use a <version> of luajit
install-rocks <version> Install and use a <version> of lurocks in
current lua environment
use <version> Use a <version> of lua
use-lj <version> Use a <version> of luajit
use-rocks <version> Use a <version> of luajit
Note:
The <version> specifier of the above commands can be specified as follows;
lenv install latest ; that picks the latest version
lenv install 5 ; that picks the latest minor version and patch version
lenv install 5.4 ; that picks the latest patch version
In addition, the install and install-lj commands can be used to install
luarocks at the same time with the following <version> specifier;
lenv install latest ; that picks the latest version
lenv install 5 ; that picks the latest minor version and patch version
lenv install 5.4 ; that picks the latest patch version
lenv install lj-v2.1 ; that picks the version of luajit
lenv install latest:latest ; that picks the the latest version of lua and
; luarocks
; luarocks in current lua environment
lenv install :latest ; that picks the the latest version of luarocks
in current lua environment
If a version of luarocks is specified, the operation will target the lua
environment currently in use.
uninstall <version> Uninstall a <version> of lua
uninstall-lj <version> Uninstall a <version> of luajit
Expand Down
50 changes: 21 additions & 29 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"os"
"path/filepath"
"runtime"
"strings"
)

Expand Down Expand Up @@ -239,6 +240,20 @@ func installRocks(instdir string, cfg *TargetConfig) error {
}

func installLuaJit(instdir string, opts []string) error {
if runtime.GOOS == "darwin" {
// append MACOSX_DEPLOYMENT_TARGET=10.8 by default on macOS platform
found := false
for _, opt := range opts {
found = strings.HasPrefix(opt, "MACOSX_DEPLOYMENT_TARGET")
if found {
break
}
}
if !found {
opts = append(opts, "MACOSX_DEPLOYMENT_TARGET=10.8")
}
}

// clean up working directory
if err := DoExec("make", append([]string{"clean"}, opts...)...); err != nil {
return err
Expand Down Expand Up @@ -422,37 +437,14 @@ func doInstall(cfg *TargetConfig, item *VerItem, opts []string) {
UseInstalledVersion(cfg, item.Ver)
}

func CmdInstall(cfg *TargetConfig, opts []string) {
// check target version
if len(opts) == 0 || (cfg != LuaRocksCfg && opts[0] == ":") {
CmdHelp(1, "no version specified")
}
ver := opts[0]

// check :<luarocks-version>
var rocksVer string
if cfg != LuaRocksCfg {
if delim := strings.Index(ver, ":"); delim != -1 {
rocksVer = ver[delim+1:]
ver = ver[:delim]
}
}

var verItem *VerItem
if len(ver) > 0 {
verItem = PickTargetVersionItem(cfg, ver)
}
var rocksItem *VerItem
if len(rocksVer) > 0 {
rocksItem = PickTargetVersionItem(LuaRocksCfg, rocksVer)
}

if verItem != nil {
doInstall(cfg, verItem, opts[1:])
func CmdInstall(opts []string) {
target := PickTargetVersion(opts[0])
if target.Lua != nil {
doInstall(target.Lua.Config, target.Lua.Version, opts[1:])
}
if rocksItem != nil {
if target.LuaRocks != nil {
ResolveCurrentDir()
CheckLuaRocksRootDir()
doInstall(LuaRocksCfg, rocksItem, opts)
doInstall(target.LuaRocks.Config, target.LuaRocks.Version, opts[1:])
}
}
73 changes: 51 additions & 22 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,56 @@ func CheckLuaRocksRootDir() {
}
}

type Target struct {
Config *TargetConfig
Version *VerItem
}

type TargetVersion struct {
Lua *Target
LuaRocks *Target
}

func PickTargetVersion(vers string) *TargetVersion {
// check target version
if len(vers) == 0 || vers == ":" {
CmdHelp(1, "no version specified")
}

// check :<luarocks-version>
var rocksVer string
if delim := strings.Index(vers, ":"); delim != -1 {
rocksVer = vers[delim+1:]
vers = vers[:delim]
}

target := &TargetVersion{}
if len(vers) > 0 {
if strings.HasPrefix(vers, "lj-") {
// if `lj-' prefix is specified, then the target is LuaJIT version
target.Lua = &Target{
Config: LuaJitCfg,
Version: PickTargetVersionItem(LuaJitCfg, vers[3:]),
}
} else {
// otherwise the target is Lua version.
target.Lua = &Target{
Config: LuaCfg,
Version: PickTargetVersionItem(LuaCfg, vers),
}
}
}

if len(rocksVer) > 0 {
target.LuaRocks = &Target{
Config: LuaRocksCfg,
Version: PickTargetVersionItem(LuaRocksCfg, rocksVer),
}
}

return target
}

func start() {
argv := os.Args[1:]
if len(argv) > 0 {
Expand Down Expand Up @@ -296,28 +346,7 @@ func start() {
CmdList()

case "install":
CmdInstall(LuaCfg, argv[1:])

case "install-lj":
argv = argv[1:]
if runtime.GOOS == "darwin" {
// set MACOSX_DEPLOYMENT_TARGET=10.8 by default
found := false
for _, arg := range argv {
found = strings.HasPrefix(arg, "MACOSX_DEPLOYMENT_TARGET")
if found {
break
}
}
if !found {
argv = append(argv, "MACOSX_DEPLOYMENT_TARGET=10.8")
}
}
CmdInstall(LuaJitCfg, argv)

case "install-rocks":
CheckLuaRocksRootDir()
CmdInstall(LuaRocksCfg, argv[1:])
CmdInstall(argv[1:])

case "uninstall":
CmdUninstall(LuaCfg, argv[1:])
Expand Down

0 comments on commit 42d8720

Please sign in to comment.