Skip to content

Commit

Permalink
Merge pull request #61 from xonixx/makesure_stable
Browse files Browse the repository at this point in the history
Makesure stable
  • Loading branch information
xonixx authored Sep 29, 2021
2 parents 0beaca7 + 8699e5a commit 68c2c1c
Show file tree
Hide file tree
Showing 11 changed files with 692 additions and 61 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

- name: "run tests"
run: |
./makesure_stable tested_awks
./makesure tested_awks
macos_gawk:
name: "Run tests macos / gawk"
Expand All @@ -41,7 +41,7 @@ jobs:
- name: "run tests"
run: |
brew install gawk # TODO understand if this step can be cached
./makesure_stable
./makesure
win:
name: "Run tests Win"
Expand All @@ -60,4 +60,4 @@ jobs:

- name: "run tests"
run: |
& bash -e -c "./makesure_stable"
& bash -e -c "./makesure"
60 changes: 36 additions & 24 deletions Makesurefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,45 +99,57 @@
@goal @glob tests/*.tush @private
@depends_on prepared4tests
@use_lib testing_tush
MAKESURE=makesure \
MAKESURE=makesure_dev \
run_tush_file "$ITEM"

@goal tested_stable @glob tests/*.tush @private
@goal tested_candidate @glob tests/*.tush @private
@depends_on prepared4tests
@depends_on candidate_version_prepared
@use_lib testing_tush
MAKESURE=makesure_stable \
MAKESURE=makesure_candidate \
run_tush_file "$ITEM"

@goal stable
@doc rebuilds makesure_stable & README.md for release
@depends_on makesure_stable
@goal candidate
@doc compiles makesure_candidate
@depends_on tested_candidate

@goal release
@doc creates release version of 'makesure' + updates README.md
@depends_on candidate
@depends_on release_makesure
@depends_on README.md

@goal release_makesure @private
cp makesure_candidate makesure

@goal README.md @private
@doc compiles release version of README.md
awk '
/^\$ \.\/makesure -h$/ { print; stop=1; system("./makesure_stable -h") }
/^\$ \.\/makesure -h$/ { print; stop=1; system("./makesure -h") }
/^```$/ { stop=0 }
!stop' README.md > README.md.1
mv README.md.1 README.md

@goal makesure_stable @private
@doc compiles makesure_stable
@goal candidate_version_prepared @private
@depends_on tested
@depends_on stable_version_prepared
@depends_on tested_stable

#TODO ^V this should be more pure
@goal stable_version_prepared @private
F=makesure_candidate
{
echo '#!/bin/sh'
echo "if command -v gawk >/dev/null;then AWK='gawk -ltime -v Gawk=1'; X='';else AWK=awk; X='function gettimeofday(){}';fi"
echo "exec \$AWK -v \"Version=$NEXT_VERSION\" -v \"Prog=\$0\" '"
# We use `makesure_awk`, not `AWK` because otherwise it clashes with `AWK` set for tests.
# The same we can't just use `A` because it can clash with external config variable that user might want to use.
# Since in Posix sh there is no way to declare local var, let's just make names more specific.
echo "if command -v gawk >/dev/null;then makesure_awk='gawk -ltime -v Gawk=1';makesure_pre='';else makesure_awk=awk;makesure_pre='function gettimeofday(){}';fi"
echo 'exec $makesure_awk -v "Version='$NEXT_VERSION'" -v "Prog=$0" "$makesure_pre"'\'
awk -v Q=\' '
function trim(s) { sub(/^[ \t\r\n]+/, "", s); sub(/[ \t\r\n]+$/, "", s); return s }
/^BEGIN/ { in_begin=1 }
in_begin && /^}/ { in_begin=0 }
in_begin && $1 ~ /^split/ { next }
/^function gettimeofday/ { next }
{ gsub("\\s*#.+$", ""); gsub(Q, Q "\\" Q Q); if (trim($0)) print}' makesure.awk
echo \''"$X" Makesurefile "$@"'
} > makesure_stable
echo \'' Makesurefile "$@"'
} > "$F"
chmod +x "$F"

@goal default
@doc calls 'tested' goal
Expand All @@ -154,30 +166,30 @@ in_begin && $1 ~ /^split/ { next }

@goal tested_bwk @private
@depends_on installed_bwk
AWK="$(pwd)/soft/bwk" ./makesure tested
AWK="$(pwd)/soft/bwk" ./makesure_dev tested

@goal tested_mawk134 @private
@depends_on installed_mawk134
AWK="$(pwd)/soft/mawk134" ./makesure tested
AWK="$(pwd)/soft/mawk134" ./makesure_dev tested

@goal tested_gawk51 @private
@depends_on installed_gawk51
AWK="$(pwd)/soft/gawk51" ./makesure tested
AWK="$(pwd)/soft/gawk51" ./makesure_dev tested

@goal tested_goawk @private
@depends_on installed_goawk
AWK="$(pwd)/soft/$GOAWK" ./makesure tested
AWK="$(pwd)/soft/$GOAWK" ./makesure_dev tested

@goal tested_mawk @private
if [[ -x /usr/bin/mawk ]]
then
AWK="/usr/bin/mawk" ./makesure tested
AWK="/usr/bin/mawk" ./makesure_dev tested
else
echo "No default mawk... Skipped testing it."
fi

#@goal tested_busybox
# AWK="busybox awk" ./makesure tested
# AWK="busybox awk" ./makesure_dev tested

@goal installed_awks
@doc installs all awks into ./soft
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Usage: makesure [options...] [-f buildfile] [goals...]
Since `makesure` is a tiny utility represented by a single file, the recommended installation strategy is to keep it local to a project where it's used (this means in code repository). Not only this eliminates the need for repetitive installation for every dev on a project, but also allows using separate `makesure` version per project and update only as needed.

```shell
wget "https://raw.githubusercontent.com/xonixx/makesure/main/makesure_stable?token=$(date +%s)" -Omakesure && \
wget "https://raw.githubusercontent.com/xonixx/makesure/main/makesure?token=$(date +%s)" -Omakesure && \
chmod +x makesure && echo "makesure $(./makesure -v) installed"
```

Expand Down Expand Up @@ -509,6 +509,10 @@ Only single `@use_lib` per goal is allowed.
- parallel execution
- `makesure` is a task runner, not a full-fledged build tool, like `make`, `ninja` or `bazel`. So if you need one, just use a proper build tool of your choice.

## Developer notes

Find some contributor instructions in [DEVELOPER.md](docs/DEVELOPER.md).

## Similar tools

- **just** https://github.com/casey/just
Expand Down
15 changes: 15 additions & 0 deletions docs/DEVELOPER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Files

- [makesure.awk](../makesure.awk)
- **what:** the core of the tool implemented in AWK
- [makesure_dev](../makesure_dev)
- **what:** sh-wrapper over `makesure.awk`. Relatively immutable.
- **why:** used in running tests, has some configurability for this purpose
- [makesure_candidate](../makesure_candidate)
- **what:** self-contained sh script, that embeds the `makesure.awk` content as AWK CLI argument
- **why** the final tool requires some sh additions to correctly initialize the core. Serves a candidate for next release. Need this as separate entity to be able to test the compiled version of a tool.
- **how** is generated via `./makesure candidate` from `makesure.awk`.
- [makesure](../makesure)
- **what** contains a latest released version of a tool
- **why** this one should be very stable and only change with a new release published. Serves the source of `./makesure --self-update`. *Should only change when the `makesure` version is incremented!*
- **how** copied from `makesure_candidate` at the time of release in `./makesure release`.
Loading

0 comments on commit 68c2c1c

Please sign in to comment.