diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..7204760 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,77 @@ +name: Tests + +on: + pull_request: + push: + branches: + - master + +jobs: + tests: + env: + NPROC: 2 + strategy: + fail-fast: false + matrix: + platform: + - { + icon: 🏁, + os: windows, + shell: msys2 + } + - { + icon: 🍎, + os: macos, + shell: bash --noprofile --norc -eo pipefail + } + - { + icon: 🐧, + os: ubuntu, + shell: bash --noprofile --norc -eo pipefail + } + name: ${{ matrix.platform.icon }} ${{ matrix.platform.os }} + runs-on: ${{ matrix.platform.os }}-latest + defaults: + run: + shell: ${{ matrix.platform.shell }} {0} + + steps: + + - name: Install awk (gawk) and coreutils via Homebrew + if: matrix.platform.os == 'macos' + run: | + brew install coreutils gawk + + - uses: msys2/setup-msys2@v2 + if: matrix.platform.os == 'windows' + with: + msystem: MINGW64 + update: true + install: > + base-devel + git + mingw-w64-x86_64-toolchain + + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: recursive + + - name: Calculate cache key from submodules tree + id: calc-cache-key + run: | + echo "::set-output name=hash::$(git submodule foreach --quiet --recursive 'git rev-parse $(git rev-parse --abbrev-ref HEAD)' | sha1sum | awk '{print $1}')" + + - uses: actions/cache@v2 + with: + path: vendor/nimbus-build-system/vendor/Nim/bin + key: ${{ matrix.platform.os }}-${{ steps.calc-cache-key.outputs.hash }} + + - name: Install and build dependencies + run: | + make -j${NPROC} NIMFLAGS="--parallelBuild:${NPROC}" V=1 update + make -j${NPROC} NIMFLAGS="--parallelBuild:${NPROC}" V=1 deps + + - name: Build and run tests + run: | + make -j${NPROC} NIMFLAGS="--parallelBuild:${NPROC}" V=1 test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57c1f23 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +/.idea +/.update.timestamp +/.vscode +/task_runner.nims +/nimcache +/test/build +/vendor/.nimble +TODO diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..70fc503 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,14 @@ +[submodule "vendor/nimbus-build-system"] + path = vendor/nimbus-build-system + url = https://github.com/status-im/nimbus-build-system.git + branch = master + ignore = dirty +[submodule "vendor/nim-chronos"] + path = vendor/nim-chronos + url = https://github.com/status-im/nim-chronos.git +[submodule "vendor/nim-stew"] + path = vendor/nim-stew + url = https://github.com/status-im/nim-stew.git +[submodule "vendor/nim-bearssl"] + path = vendor/nim-bearssl + url = https://github.com/status-im/nim-bearssl.git diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9625288 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Status Research & Development GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4575182 --- /dev/null +++ b/Makefile @@ -0,0 +1,59 @@ +SHELL := bash # the shell used internally by "make" + +# used inside the included makefiles +BUILD_SYSTEM_DIR := vendor/nimbus-build-system + +# we don't want an error here, so we can handle things later, in the ".DEFAULT" target +-include $(BUILD_SYSTEM_DIR)/makefiles/variables.mk + +.PHONY: \ + all \ + clean \ + deps \ + test \ + update + +ifeq ($(NIM_PARAMS),) +# "variables.mk" was not included, so we update the submodules. +GIT_SUBMODULE_UPDATE := git submodule update --init --recursive +.DEFAULT: + +@ echo -e "Git submodules not found. Running '$(GIT_SUBMODULE_UPDATE)'.\n"; \ + $(GIT_SUBMODULE_UPDATE) && \ + echo +# Now that the included *.mk files appeared, and are newer than this file, Make will restart itself: +# https://www.gnu.org/software/make/manual/make.html#Remaking-Makefiles +# +# After restarting, it will execute its original goal, so we don't have to start a child Make here +# with "$(MAKE) $(MAKECMDGOALS)". Isn't hidden control flow great? + +else # "variables.mk" was included. Business as usual until the end of this file. + +# default target, because it's the first one that doesn't start with '.' +all: test + +# must be included after the default target +-include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk + +ifeq ($(OS),Windows_NT) + # is Windows_NT on XP, 2000, 7, Vista, 10... + detected_OS := Windows +else ifeq ($(strip $(shell uname)),Darwin) + detected_OS := macOS +else + # e.g. Linux + detected_OS := $(strip $(shell uname)) +endif + +clean: | clean-common clean-build-dirs + +clean-build-dirs: + rm -rf test/build + +deps: | deps-common + +update: | update-common + +test: | deps + $(ENV_SCRIPT) nimble tests + +endif # "variables.mk" was not included diff --git a/README.md b/README.md index bad6e8f..773eb2c 100644 --- a/README.md +++ b/README.md @@ -1 +1,6 @@ # nim-task-runner +[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) +![Stability: experimental](https://img.shields.io/badge/Stability-experimental-orange.svg) +[![Tests (GitHub Actions)](https://github.com/status-im/nim-task-runner/workflows/Tests/badge.svg?branch=master)](https://github.com/status-im/nim-task-runner/actions?query=workflow%3ATests+branch%3Amaster) + +General purpose background task runner for Nim programs diff --git a/env.sh b/env.sh new file mode 100755 index 0000000..697a426 --- /dev/null +++ b/env.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# We use ${BASH_SOURCE[0]} instead of $0 to allow sourcing this file +# and we fall back to a Zsh-specific special var to also support Zsh. +REL_PATH="$(dirname ${BASH_SOURCE[0]:-${(%):-%x}})" +ABS_PATH="$(cd ${REL_PATH}; pwd)" +source ${ABS_PATH}/vendor/nimbus-build-system/scripts/env.sh diff --git a/task_runner.nim b/task_runner.nim new file mode 100644 index 0000000..591bca1 --- /dev/null +++ b/task_runner.nim @@ -0,0 +1,2 @@ +proc foo*(): string = + "bar" diff --git a/task_runner.nimble b/task_runner.nimble new file mode 100644 index 0000000..ee156ae --- /dev/null +++ b/task_runner.nimble @@ -0,0 +1,44 @@ +mode = ScriptMode.Verbose + +version = "0.1.0" +author = "Status Research & Development GmbH" +description = "General purpose background task runner for Nim programs" +license = "MIT" +skipDirs = @["test"] + +requires "nim >= 1.2.0", + "chronos" + +import strutils + +proc buildAndRunTest(name: string, + srcDir = "test/", + outDir = "test/build/", + params = "", + cmdParams = "", + lang = "c") = + rmDir outDir + mkDir outDir + # allow something like "nim test --verbosity:0 --hints:off beacon_chain.nims" + var extra_params = params + for i in 2..