hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 7eef96c89dab964d5ea85a62c507d3d2f2d976fb
parent 6d7da72b864886c7d3647895e2983d9a316d1a99
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat, 20 Mar 2021 11:13:28 -0400

cmd/hare: implement hare version

Also adds build-time default HAREPATH riggings

Diffstat:
MMakefile | 5++++-
Mcmd/hare/subcmds.ha | 20+++++++++++++++++---
Mconfig.example.mk | 16+++++++++++++++-
Mdocs/hare.scd | 5++++-
Mhare/module/context.ha | 10++++------
Aversion | 22++++++++++++++++++++++
6 files changed, 66 insertions(+), 12 deletions(-)

diff --git a/Makefile b/Makefile @@ -30,7 +30,10 @@ hare_srcs=\ $(HARECACHE)/hare.ssa: $(hare_srcs) $(hare_stdlib_deps) @printf 'HAREC\t$@\n' - @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ $(hare_srcs) + @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) \ + -D VERSION:str='"'"$$(./version)"'"' \ + -D HAREPATH:str='"'"$(HAREPATH)"'"' \ + -o $@ $(hare_srcs) $(TESTCACHE)/hare.ssa: $(hare_srcs) $(hare_testlib_deps) @printf 'HAREC\t$@\n' diff --git a/cmd/hare/subcmds.ha b/cmd/hare/subcmds.ha @@ -71,7 +71,7 @@ fn build(args: []str) void = { let tags = default_tags(); defer free(tags); - let ctx = module::context_init(tags); + let ctx = module::context_init(tags, HAREPATH); defer module::context_finish(&ctx); let plan = mkplan(&ctx); @@ -170,7 +170,7 @@ fn run(args: []str) void = { let tags = default_tags(); defer free(tags); - let ctx = module::context_init(tags); + let ctx = module::context_init(tags, HAREPATH); defer module::context_finish(&ctx); let plan = mkplan(&ctx); @@ -222,5 +222,19 @@ fn test(args: []str) void = { }; fn version(args: []str) void = { - abort(); // TODO + fmt::printfln("Hare version {}", VERSION); + fmt::errorln(); + fmt::printf("Build tags\t"); + let tags = default_tags(); + for (let i = 0z; i < len(tags); i += 1) { + let tag = tags[i]; + let inclusive = (tag.mode & module::tag_mode::INCLUSIVE) == module::tag_mode::INCLUSIVE; + fmt::printf("{}{}", if (inclusive) '+' else '-', tag.name); + }; + fmt::println(); + + match (os::getenv("HAREPATH")) { + void => fmt::printfln("HAREPATH\t{}", HAREPATH), + s: str => fmt::printfln("HAREPATH\t{}\t(from environment)", s), + }; }; diff --git a/config.example.mk b/config.example.mk @@ -1,7 +1,18 @@ -HARECACHE=.cache +## Install configuration + +# Where to install the stdlib tree +STDLIB=/usr/src/hare + +# Default HAREPATH +HAREPATH=/usr/src/hare/stdlib:/usr/src/hare/third-party + +## Build configuration + +# Platform to build for PLATFORM=+linux ARCH=+x86_64 +# External tools and flags HAREC=harec HAREFLAGS= QBE=qbe @@ -9,3 +20,6 @@ AS=as LD=ld AR=ar SCDOC=scdoc + +# Where to store build artifacts +HARECACHE=.cache diff --git a/docs/hare.scd b/docs/hare.scd @@ -54,7 +54,10 @@ made eligible for the test run. If the _test_ argument is omitted, all tests are run. Otherwise, the list of named tests are run. *hare version* prints version information for the *hare* program, as well as -some information about the build parameters. +some information about the build parameters. The output format is consistent for +machine reading: the first line is "Hare version $version". Subsequent lines +give configuration values in the form of a name, value, and optional context, +separated by tabs. # OPTIONS diff --git a/hare/module/context.ha b/hare/module/context.ha @@ -7,9 +7,6 @@ use path; use strings; use strio; -// TODO: Specify this at build time once harec supports -D -def DEFAULT_HAREPATH: str = "/usr/src/hare"; - export type context = struct { // Filesystem to use for the cache and source files. fs: *fs::fs, @@ -24,15 +21,16 @@ export type context = struct { }; // Initializes a new context with the system default configuration. The tag list -// is borrowed from the caller. -export fn context_init(tags: []tag) context = { +// is borrowed from the caller. The harepath parameter is not borrowed, but it +// is ignored if HAREPATH is set in the process environment. +export fn context_init(tags: []tag, harepath: str) context = { let ctx = context { fs = os::cwd, tags = tags, paths: []str = match (os::getenv("HAREPATH")) { void => { let path: []str = alloc([ - strings::dup(DEFAULT_HAREPATH), + strings::dup(harepath), dirs::data("hare"), ]); path; diff --git a/version b/version @@ -0,0 +1,22 @@ +#!/bin/sh +# Distro packagers may set the LOCALVER variable to add their distribution to +# the version, e.g. 1.0-alpine. +VERSION=dev + +ver=$(git describe 2>/dev/null) +if [ $? -ne 0 ] +then + ver="dev+$(git log -1 --format='%h')" + if [ $? -ne 0 ] + then + # git presumed unavailable + ver=$VERSION + fi +fi + +localver=${LOCALVER:-} +if [ ${#localver} != 0 ] +then + ver="$ver-$localver" +fi +echo $ver