Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove compiler and use nimscript with nim e instead #635

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
93ba4a0
Fix for #398
genotrance Jan 14, 2018
de18319
Merge remote-tracking branch 'upstream/master'
genotrance Jan 15, 2018
7adfd7b
Updated fix for #398
genotrance Jan 15, 2018
e9a8850
Merge remote-tracking branch 'upstream/master'
genotrance Mar 8, 2018
2fc3106
Merge remote-tracking branch 'upstream/master'
genotrance Apr 26, 2018
cf7263d
Merge remote-tracking branch 'upstream/master'
genotrance Sep 14, 2018
3d7227c
Merge remote-tracking branch 'upstream/master'
genotrance Oct 17, 2018
220ebae
Merge remote-tracking branch 'upstream/master'
genotrance Dec 13, 2018
b9ef88b
Merge remote-tracking branch 'upstream/master' into nocompiler
genotrance Mar 27, 2019
ab38b81
Initial version
genotrance Apr 13, 2019
0ed53d6
Return bool from hooks
genotrance Apr 13, 2019
cbb3af3
Remove nims from package dir after exec
genotrance Apr 15, 2019
7d0a40a
Before/after hook info
genotrance Apr 15, 2019
51d03b3
getPkgDir impl
genotrance Apr 16, 2019
1e95fd4
getParams once, hash nimscriptapi, fix loop in setcommand
genotrance Apr 16, 2019
deecd90
API cleanup, json setCommand fix
genotrance Apr 16, 2019
b05d948
Add switch support
genotrance Apr 16, 2019
8c2e65e
Fix packageName to name
genotrance Apr 16, 2019
74201bc
No success for missing task
genotrance Apr 16, 2019
85f3865
Remove ospaths, fix tests for Windows
genotrance Apr 16, 2019
2942f11
Remove osx, test with stable
genotrance Apr 17, 2019
5cf0240
No hints, live output
genotrance Apr 17, 2019
b22fe37
Merge branch 'nocompiler' of https://github.com/genotrance/nimble int…
genotrance Apr 17, 2019
24131de
Fix empty param, json echo
genotrance Apr 17, 2019
d49916e
Interactive live, json to file
genotrance Apr 17, 2019
a031fff
Add devel to travis
genotrance Apr 17, 2019
64e5489
Remove compiler dependency
genotrance Apr 18, 2019
c278bd6
Hardcode version, json{}, code width 80, isScriptResultCached, no bla…
genotrance Apr 22, 2019
915d6b2
Keep nimscript separate, pin devel
genotrance Apr 25, 2019
ae3ef9f
Fix for 0.19.4
genotrance Apr 25, 2019
640ce3f
Clean up per feedback
genotrance Apr 25, 2019
e86a376
Fix caching issue
genotrance Apr 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
os:
- linux
dist: trusty
- osx

language: c

env:
- BRANCH=0.19.4
- BRANCH=devel
genotrance marked this conversation as resolved.
Show resolved Hide resolved

cache:
directories:
- "$HOME/.nimble"
- "$HOME/.choosenim"
- "$HOME/.choosenim/toolchains/nim-0.19.4"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this? In fact, this will be wrong for BRANCH=devel.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing worth caching in ~/.nimble. Also, caching only stable since the binary won't change. Devel shouldn't be cached so that we always test with latest. Otherwise we are testing with an old devel after first cache.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing worth caching in ~/.nimble.

There is.

The .nimble/bin is added to the PATH below, if this directory doesn't get cached then failures will happen.

Copy link
Collaborator

@dom96 dom96 Apr 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@genotrance as far as I'm concerned you need to revert this because it will break things, please do so (or explain why it must be this way).


install:
- export CHOOSENIM_CHOOSE_VERSION="#7bb93c730ea87f"
- export NIM_LIB_PREFIX="$HOME/.choosenim/toolchains/nim-"$CHOOSENIM_CHOOSE_VERSION
- export CHOOSENIM_CHOOSE_VERSION=$BRANCH
- |
curl https://nim-lang.org/choosenim/init.sh -sSf > init.sh
sh init.sh -y

before_script:
- set -e
- set -x
- export CHOOSENIM_NO_ANALYTICS=1
- export PATH=$HOME/.nimble/bin:$PATH

Expand Down
10 changes: 6 additions & 4 deletions nimble.nimble
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import ospaths
template thisModuleFile: string = instantiationInfo(fullPaths = true).filename
import strutils

when fileExists(thisModuleFile.parentDir / "src/nimblepkg/common.nim"):
const
parentDir = currentSourcePath.rsplit(seps={'/', '\\', ':'}, maxsplit=1)[0]
genotrance marked this conversation as resolved.
Show resolved Hide resolved

when fileExists(parentDir & "/src/nimblepkg/common.nim"):
genotrance marked this conversation as resolved.
Show resolved Hide resolved
# In the git repository the Nimble sources are in a ``src`` directory.
import src/nimblepkg/common
else:
Expand All @@ -21,7 +23,7 @@ installExt = @["nim"]

# Dependencies

requires "nim >= 0.13.0", "compiler#head"
requires "nim >= 0.13.0"

when defined(nimdistros):
import distros
Expand Down
6 changes: 3 additions & 3 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import nimblepkg/packageinfo, nimblepkg/version, nimblepkg/tools,
nimblepkg/cli, nimblepkg/packageinstaller, nimblepkg/reversedeps,
nimblepkg/nimscriptexecutor, nimblepkg/init

import nimblepkg/nimscriptsupport
import nimblepkg/nimscriptwrapper

proc refresh(options: Options) =
## Downloads the package list from the specified URL.
Expand Down Expand Up @@ -896,7 +896,7 @@ proc uninstall(options: Options) =

proc listTasks(options: Options) =
let nimbleFile = findNimbleFile(getCurrentDir(), true)
nimscriptsupport.listTasks(nimbleFile, options)
nimscriptwrapper.listTasks(nimbleFile, options)

proc developFromDir(dir: string, options: Options) =
if options.depsOnly:
Expand Down Expand Up @@ -1103,7 +1103,7 @@ proc doAction(options: Options) =
return
let isPreDefined = options.action.command.normalize == "test"

var execResult: ExecutionResult[void]
var execResult: ExecutionResult[bool]
if execCustom(options, execResult, failFast=not isPreDefined):
if execResult.hasTaskRequestedCommand():
doAction(execResult.getOptionsForCommand(options))
Expand Down
154 changes: 134 additions & 20 deletions src/nimblepkg/nimscriptapi.nim
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

## This module is implicitly imported in NimScript .nimble files.

import system except getCommand, setCommand, switch, `--`
import strformat, strutils, tables

var
packageName* = "" ## Set this to the package name. It
## is usually not required to do that, nims' filename is
Expand All @@ -22,46 +25,157 @@ var
foreignDeps*: seq[string] = @[] ## The foreign dependencies. Only
## exported for 'distros.nim'.

beforeHooks: seq[string] = @[]
afterHooks: seq[string] = @[]
commandLineParams: seq[string] = @[]
flags: TableRef[string, seq[string]]

command = "e"
project = ""
success = false
retVal = true

proc requires*(deps: varargs[string]) =
## Call this to set the list of requirements of your Nimble
## package.
for d in deps: requiresData.add(d)

proc getParams() =
for i in 5 .. paramCount():
if paramStr(i).len != 0:
genotrance marked this conversation as resolved.
Show resolved Hide resolved
commandLineParams.add paramStr(i).normalize
genotrance marked this conversation as resolved.
Show resolved Hide resolved

proc getCommand(): string =
return command

proc setCommand(cmd: string, prj = "") =
command = cmd
if prj.len != 0:
project = prj

proc switch(key: string, value="") =
if flags.isNil:
flags = newTable[string, seq[string]]()

if flags.hasKey(key):
flags[key].add(value)
else:
flags[key] = @[value]

template `--`(key, val: untyped) =
genotrance marked this conversation as resolved.
Show resolved Hide resolved
switch(astToStr(key), strip astToStr(val))

template `--`(key: untyped) =
switch(astToStr(key), "")

template printIfLen(varName) =
if varName.len != 0:
iniOut &= astToStr(varName) & ": \"" & varName & "\"\n"

template printSeqIfLen(varName) =
if varName.len != 0:
iniOut &= astToStr(varName) & ": \"" & varName.join(", ") & "\"\n"

proc printPkgInfo() =
if backend.len == 0:
backend = "c"

var
iniOut = "[Package]\n"
if packageName.len != 0:
iniOut &= "name: \"" & packageName & "\"\n"
printIfLen version
printIfLen author
printIfLen description
printIfLen license
printIfLen srcdir
printIfLen binDir
printIfLen backend

printSeqIfLen skipDirs
printSeqIfLen skipFiles
printSeqIfLen skipExt
printSeqIfLen installDirs
printSeqIfLen installFiles
printSeqIfLen installExt
printSeqIfLen bin
printSeqIfLen beforeHooks
printSeqIfLen afterHooks

if requiresData.len != 0:
iniOut &= "\n[Deps]\n"
iniOut &= &"requires: \"{requiresData.join(\", \")}\"\n"

echo iniOut

proc onExit() =
if "printPkgInfo".normalize in commandLineParams:
printPkgInfo()
else:
var
output = ""
output &= "\"success\": " & $success & ", "
genotrance marked this conversation as resolved.
Show resolved Hide resolved
output &= "\"command\": \"" & command & "\", "
if project.len != 0:
output &= "\"project\": \"" & project & "\", "
if not flags.isNil and flags.len != 0:
output &= "\"flags\": {"
for key, val in flags.pairs:
output &= "\"" & key & "\": ["
for v in val:
output &= "\"" & v & "\", "
output = output[0 .. ^3] & "], "
output = output[0 .. ^3] & "}, "

output &= "\"retVal\": " & $retVal

writeFile(currentSourcePath & ".out", "{" & output & "}")

# TODO: New release of Nim will move this `task` template under a
genotrance marked this conversation as resolved.
Show resolved Hide resolved
# `when not defined(nimble)`. This will allow us to override it in the future.
when not declared(task):
template task*(name: untyped; description: string; body: untyped): untyped =
## Defines a task. Hidden tasks are supported via an empty description.
## Example:
##
## .. code-block:: nim
## task build, "default build is via the C backend":
## setCommand "c"
proc `name Task`*() = body

let cmd = getCommand()
if cmd.len == 0 or cmd == "help":
setCommand "help"
echo(astToStr(name), " ", description)
elif cmd == astToStr(name):
setCommand "nop"
`name Task`()
template task*(name: untyped; description: string; body: untyped): untyped =
## Defines a task. Hidden tasks are supported via an empty description.
## Example:
##
## .. code-block:: nim
## task build, "default build is via the C backend":
## setCommand "c"
proc `name Task`*() = body

if commandLineParams.len == 0 or "help" in commandLineParams:
success = true
echo(astToStr(name), " ", description)
elif astToStr(name).normalize in commandLineParams:
success = true
`name Task`()

template before*(action: untyped, body: untyped): untyped =
## Defines a block of code which is evaluated before ``action`` is executed.
proc `action Before`*(): bool =
result = true
body

beforeHooks.add astToStr(action)
genotrance marked this conversation as resolved.
Show resolved Hide resolved

if (astToStr(action) & "Before").normalize in commandLineParams:
success = true
retVal = `action Before`()

template after*(action: untyped, body: untyped): untyped =
## Defines a block of code which is evaluated after ``action`` is executed.
proc `action After`*(): bool =
result = true
body

template builtin = discard
afterHooks.add astToStr(action)

if (astToStr(action) & "After").normalize in commandLineParams:
success = true
retVal = `action After`()

proc getPkgDir*(): string =
proc getPkgDir(): string =
## Returns the package directory containing the .nimble file currently
## being evaluated.
builtin
result = currentSourcePath.rsplit(seps={'/', '\\', ':'}, maxsplit=1)[0]

getParams()
4 changes: 2 additions & 2 deletions src/nimblepkg/nimscriptexecutor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import os, tables, strutils, sets

import packageparser, common, packageinfo, options, nimscriptsupport, cli
import packageparser, common, packageinfo, options, nimscriptwrapper, cli

proc execHook*(options: Options, before: bool): bool =
## Returns whether to continue.
Expand Down Expand Up @@ -31,7 +31,7 @@ proc execHook*(options: Options, before: bool): bool =
result = res.retVal

proc execCustom*(options: Options,
execResult: var ExecutionResult[void],
execResult: var ExecutionResult[bool],
failFast = true): bool =
## Executes the custom command using the nimscript backend.
##
Expand Down
Loading