项目作者: VladimirMarkelov

项目描述 :
A task/command runner inspired by 'make'
高级语言: Rust
项目地址: git://github.com/VladimirMarkelov/haku.git
创建时间: 2019-12-28T04:15:04Z
项目社区:https://github.com/VladimirMarkelov/haku

开源协议:Other

下载


Table of Contents

Documentation

Intro

haku is a simple command runner, kind of a make alternative but it is not a
make replacement. It provides a limited set of internal commands(for,
if, while etc) that allow anyone to write cross-platform task files. If it
is not enough, haku has a Rust-like attributes for marking a block of a
script to run, e.g., only on a specific platform.

Warning: platform specific properties are detected at compile time, not at run time.
So, let’s assume you build haku on Windows 32-bit, and run it on Linux 64-bit(e.g., using Wine).
The application will keep executing scripts with flags: platform=windows and bit=32.

Commands are stored in files named:

  • Windows: Hakufile, and Taskfile
  • Other Os: Hakufile, Taskfile, hakufile, and taskfile

When haku starts without task file name, first, it looks for Taskfile. If it does not exist,
haku looks for Hakufile.

All commands are either free ones(those must be in the file beginning), or grouped by sections -
a section is called a recipe. The file syntax is relaxed and simplified makefile one.

Internally haku uses powershell on Windows and sh on any other OS to execute an external
command. You can override the default using shell built-in function.

Vim support

For more comfortable work with Hakufiles in Vim, the basic Vim support is included: just copy
everything from vim/* to your Vim files directory(either ~/.vimfiles or %USERPROFILE%/vimfiles
depending on OS). The Vim support includes basic syntax highlighting and file detection. Here is
and example of syntax highlighting in gVIM:

Haku syntax hightlight in gVim using gruvbox colorscheme and Fantasque Sans Mono font

License

Haku is released under Apache License Version 2.0

Similar projects

Haku is heavily inspired by two great projects: GNU make
and just. They do their job well but some things still are
a bit inconvenient to me. What made me to implement my own command runner:

  • both utilities above are picky about whitespaces and indentation. And make sometimes have puzzling requirements
  • it is not easy to create cross-platform makefiles. just provides a way but it is a limited one
  • a set of built-in functions to manipulate file path: replace extension, add, create name with current time etc

At the same time, haku lacks some features that others have. See detailed comparison haku with
just in docs. As for comparison with make, haku should not be used as
build system because haku does not check timestamps and does not try to minimize build time. So,
both tools are for different purposes and it does not make much sense to compare them.

Installation

You can compile the application from sources, or install using cargo:

  1. $ cargo install haku

You need Rust compiler that supports Rust 2018 edition (Rust 1.38 or newer) to do it. If you want
to upgrade existing haku, execute the following command:

  1. $ cargo install haku --force

For rust 1.41 and newer flag --force can be omitted.

Precompiled binaries

For Windows and Ubuntu you can download precompiled binaries from Release page.

  • Windows binary tested on Windows 10.
  • Ubuntu binary tested on Ubuntu 18.
  • musl-Linux build

Syntax highlighting

For Vim and Neovim

Get it there haku-vim.

For KSyntaxHighlighting

Syntax highlighting for editors that uses KSyntaxHighlighting: Kate, KDevelop, Qt Creator etc.

Example with comments

  1. // Script header starts.
  2. // select the correct name of the utility "rm" depending on OS type
  3. #[not family(windows)]
  4. rm = "rm"
  5. #[family(windows)]
  6. rm = "del"
  7. app-name = "myapp"
  8. // set flags for the "rm" utility. Use a bit different way: first, intialize with default
  9. // value, and override if OS is windows
  10. rm-flags = "-f"
  11. #[os(windows)]
  12. rm-flags = "/F"
  13. // Script recipe section starts.
  14. // Let's assume we support only linux 64-bit, and windows 64-bit.
  15. // Stop execution in all other cases.
  16. // "!" and "not" are synonyms
  17. // This recipe does not have dependencies
  18. #[!os(linux,windows)]
  19. precheck-two:
  20. error "Only Windows and Linux are supported"
  21. // default empty recipe for the rest cases: linux and windows 64-bit.
  22. // This recipe has dependencies to do additional check for 32/64-bit
  23. precheck: precheck-two
  24. // it can be written shorter: "#[bit(32)]" because we are here only if parent recipe, that
  25. // activates only on windows and linux, is executed. I wrote a full condition to make an
  26. // example of how to do a few checks in one condition
  27. #[os(linux,windows), bit(32)]
  28. precheck-two:
  29. error "Only 64-bit OS is supported"
  30. // empty default recipe. It is important to put default recipes without attrubutes last
  31. precheck-two:
  32. // build recipes
  33. ## linux build - this line is shown by command "--list"
  34. #[os(linux), bit(64)]
  35. @build: precheck
  36. println("Building on ", os(), "...")
  37. make -f linux.make
  38. ## this comment is doc comment but it is not show by "--list", only the last one is shown
  39. ## windows build - this line is shown in "--list" output
  40. #[os(windows), bit(64)]
  41. @build: precheck
  42. make -f win-gnu.make
  43. // one script for all platforms. It is a bit wordy and has redundant operations that are
  44. // used only as examples of haku features
  45. @clean:
  46. rm_cmd = "${rm} ${rm-flags}"
  47. app-name = app
  48. // windows binary always has exe extension
  49. #[platform(windows)]
  50. app-name = add-ext($app-name, "exe")
  51. // prepend "-" to ignore any errors
  52. -${rm_cmd} *.o
  53. -${rm_cmd} *.obj
  54. -${rm_cmd} ${app-name}

The script above can be run without changes on any platform:

  1. $ haku build
  2. Building on Linux...
  3. <here goes make output>
  4. $ haku clean
  5. rm -f *.o
  6. <other rm calls displayed>