From dba0defc40ba7e18c7a54102b99afb2b5936376c Mon Sep 17 00:00:00 2001 From: Jens Date: Sun, 18 Feb 2018 22:51:14 +0100 Subject: [PATCH 1/7] Gitignore sentry-files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 7b9ff58..0f3eaad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ *~ +# Files created by sentry +*sentry* + # Build artifacts and dependencies /lib/ /bin/ From 2403b3e801a91bbaedf848d3c6bcac4e31743e80 Mon Sep 17 00:00:00 2001 From: Jens Date: Tue, 13 Mar 2018 08:49:36 +0100 Subject: [PATCH 2/7] Uppercased `Cli` to follow Crystal conventions `Cli` => `CLI` --- src/myst/cli.cr | 2 +- src/myst_cli.cr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/myst/cli.cr b/src/myst/cli.cr index 15357aa..e193bd1 100644 --- a/src/myst/cli.cr +++ b/src/myst/cli.cr @@ -1,7 +1,7 @@ require "option_parser" module Myst - class Cli + class CLI def self.run source = "" show_ast = false diff --git a/src/myst_cli.cr b/src/myst_cli.cr index 1b8d802..91aa2c7 100644 --- a/src/myst_cli.cr +++ b/src/myst_cli.cr @@ -2,4 +2,4 @@ require "./myst" include Myst -Cli.run +CLI.run From 19cea008bab8974fd4a90a5e7f5783efa273dd42 Mon Sep 17 00:00:00 2001 From: Jens Date: Tue, 13 Mar 2018 09:26:33 +0100 Subject: [PATCH 3/7] Improved makefile Makefile now only builds if there as been any changes to the relevant files. `make spec` will build `bin/spec` (if not otherwise specified) and run it; if it were to be run again with no changes to any files made, `bin/spec` will be reused. `make help` also looks much much better. --- .gitignore | 8 +-- Makefile | 134 +++++++++++++++++++++++++++++++++++++++++------ spec/all_spec.cr | 1 + 3 files changed, 123 insertions(+), 20 deletions(-) create mode 100644 spec/all_spec.cr diff --git a/.gitignore b/.gitignore index 0f3eaad..2ee15ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ *~ -# Files created by sentry -*sentry* +# Local files +/local/ # Build artifacts and dependencies /lib/ @@ -10,7 +10,9 @@ # Crystal generated docs /docs/ + # The myst executable /myst + # DWARF file from compiling on macOS -/myst.dwarf +*.dwarf diff --git a/Makefile b/Makefile index 43a3b08..7824cc1 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,122 @@ -.PHONY: help clean spec mystspec +# Because env `SHELL` might be +# some extremely weird shell +SHELL = bash -spec: ## Runs all specs - crystal spec - crystal run src/myst_cli.cr -- spec/myst/spec.mt +# Parse makefiles named *.mk in the dir `local` +# for local extra makefile targets if wanted. +# It is smart to set MYSTBUILD to your myst dev-build there +-include local/*.mk -myst-spec: ## Runs just the in-language specs - crystal run src/myst_cli.cr -- spec/myst/spec.mt - -build: ## Builds myst into an executable - shards build +# https://www.gnu.org/software/make/manual/html_node/One-Shell.html +.ONESHELL: -check: ## Runs all crystal specs - crystal spec/ +# The docs says i should do this +.SUFFIXES: .cr .mt -clean: ## Cleans (deletes) docs and executables - rm -rf docs - rm bin/* +MYST_CLI = src/myst_cli.cr -# https://gist.github.com/prwhite/8168133 "Help target" -help: ## Show this help. - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' +MYST_INTERPRETER_SPEC = spec/all_spec.cr +MYST_IN_LANG_SPEC = spec/myst/spec.mt + +SOURCE_FILES := $(shell find src -type f -name '*.cr') +SPEC_FILES := $(shell find spec -type f -name '*.cr' -o -name '*.mt') +STDLIB_FILES := $(shell find stdlib -type f -name '*.mt') +ALL_FILES := $(SPEC_FILES) $(STDLIB_FILES) $(SOURCE_FILES) + +INSTALL_LOCATION ?= /usr/local/bin/myst +MYSTBUILD ?= myst + +O ?= bin + +verbose ?= true + +# If another default is intentionally wished for, +# set it in local/*.mk, like this: +# .DEFAULT_GOAL = goal +# +.DEFAULT_GOAL ?= spec + +verbose_log = $(if $(subst false,,$(verbose)), $(info $(1))) + +.PHONY: spec +spec: $(O)/myst $(O)/spec ## Runs all specs + @$(call verbose_log,Running interpreter spec) + $(O)/spec + @$(call verbose_log,Running in-language spec) + $(O)/myst $(MYST_IN_LANG_SPEC) + +myst-spec: $(O)/myst ## Runs just the in-language specs + $(O)/myst $(MYST_IN_LANG_SPEC) + +.PHONY: install +install: $(INSTALL_LOCATION) ## Install myst to INSTALL_LOCATION + +.PHONY: build +build: $(O)/myst ## Builds myst into an executable + +.PHONY: myst-spec_with_build +myst-spec_with_build: ## Runs the in-language specs with MYSTBUILD + $(MYSTBUILD) $(MYST_IN_LANG_SPEC) + +$(O)/myst: $(SOURCE_FILES) + @$(call verbose_log,Building myst...) + @mkdir -p $(O) + crystal build -o $(O)/myst $(MYST_CLI) + +$(O)/spec: $(ALL_FILES) + @$(call verbose_log,Building specs...) + @mkdir -p $(O) + crystal build -o $(O)/spec $(MYST_INTERPRETER_SPEC) + +$(INSTALL_LOCATION): $(SOURCE_FILES) + @mkdir -p $(dir $(INSTALL_LOCATION)) + sudo crystal build --release -o $(INSTALL_LOCATION) $(MYST_CLI) + +.PHONY: clean +clean: ## Cleans (deletes) docs and executables +ifdef O + @[ -f $(O)/myst ] && rm $(O)/myst + @[ -f $(O)/spec ] && rm $(O)/spec +endif + @rm -rf docs + +# Thanks https://stackoverflow.com/questions/4219255/how-do-you-get-the-list-of-targets-in-a-makefile/26339924#26339924 +define TARGET_LIST = +$(shell \ + $(MAKE) -pRrq -f $(MAKEFILE_LIST) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' |\ + sort |\ + egrep -v -e '^[^[a-zA-Z0-9]]' -e '^$@$$' |\ + xargs ) +endef + +# Used in help target +list: + @echo $(TARGET_LIST) + +HELP_INDENTATION ?= 2 +HELP_NAME-DESC_SEP ?= 2 + +LENGTH_OF_LONGEST_TARGET_NAME = $(shell ruby -e 'puts ARGV.sort_by(&:size)[-1].size' $$(make list)) + +parse_help = perl -n -e \ + 'if(/^(\S*)?(?=:).*$(HELP_MARK)\s*(.*)/){ \ + print((" " x $(HELP_INDENTATION)) . "$$1" . (" " x ($(LENGTH_OF_LONGEST_TARGET_NAME) + $(HELP_NAME-DESC_SEP) - length($$1))) . "- $$2\n") \ + }' $(1) |\ + sort + +# Help target that reads text after two '#'s in a target definition and prints it after the target name +.PHONY: help +help: ## Show this help + @echo "The main targets are:" + @$(call parse_help, $(firstword $(MAKEFILE_LIST))); echo + # Iterate through the extra optional makefiles + @for makefile in $(wordlist 2, $(words $(MAKEFILE_LIST)), $(MAKEFILE_LIST)); do + echo "Targets defined in $$makefile:" + $(call parse_help, $$makefile) + echo + done + @echo "The default target is '$(.DEFAULT_GOAL)'" + +define HELP_MARK +## +endef diff --git a/spec/all_spec.cr b/spec/all_spec.cr new file mode 100644 index 0000000..81bc19b --- /dev/null +++ b/spec/all_spec.cr @@ -0,0 +1 @@ +require "./**" From 388a087cbbc154a5e96ef08892f5c7f4a9cace3a Mon Sep 17 00:00:00 2001 From: Jens Date: Tue, 13 Mar 2018 09:28:00 +0100 Subject: [PATCH 4/7] Fixed problem with `info`, blocking commands being printed. --- Makefile | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 7824cc1..2aa71a7 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ MYSTBUILD ?= myst O ?= bin -verbose ?= true +info ?= true # If another default is intentionally wished for, # set it in local/*.mk, like this: @@ -36,13 +36,16 @@ verbose ?= true # .DEFAULT_GOAL ?= spec -verbose_log = $(if $(subst false,,$(verbose)), $(info $(1))) +info_log = $(if $(subst false,,$(info)),$(info $(1))) + +# Make convention +all: $(O)/myst $(O)/spec .PHONY: spec spec: $(O)/myst $(O)/spec ## Runs all specs - @$(call verbose_log,Running interpreter spec) + $(call info_log,Running interpreter spec) $(O)/spec - @$(call verbose_log,Running in-language spec) + $(call info_log,Running in-language spec) $(O)/myst $(MYST_IN_LANG_SPEC) myst-spec: $(O)/myst ## Runs just the in-language specs @@ -59,26 +62,28 @@ myst-spec_with_build: ## Runs the in-language specs with MYSTBUILD $(MYSTBUILD) $(MYST_IN_LANG_SPEC) $(O)/myst: $(SOURCE_FILES) - @$(call verbose_log,Building myst...) - @mkdir -p $(O) + $(call info_log,Building myst...) + mkdir -p $(O) crystal build -o $(O)/myst $(MYST_CLI) $(O)/spec: $(ALL_FILES) - @$(call verbose_log,Building specs...) - @mkdir -p $(O) + $(call info_log,Building specs...) + mkdir -p $(O) crystal build -o $(O)/spec $(MYST_INTERPRETER_SPEC) $(INSTALL_LOCATION): $(SOURCE_FILES) - @mkdir -p $(dir $(INSTALL_LOCATION)) + $(call info_log,Installing myst to $(INSTALL_LOCATION) ...) + mkdir -p $(dir $(INSTALL_LOCATION)) sudo crystal build --release -o $(INSTALL_LOCATION) $(MYST_CLI) .PHONY: clean clean: ## Cleans (deletes) docs and executables ifdef O - @[ -f $(O)/myst ] && rm $(O)/myst - @[ -f $(O)/spec ] && rm $(O)/spec + @[ -f $(O)/myst ] && rm -f $(O)/myst* + @[ -f $(O)/spec ] && rm -f $(O)/spec* endif @rm -rf docs + @ # Thanks https://stackoverflow.com/questions/4219255/how-do-you-get-the-list-of-targets-in-a-makefile/26339924#26339924 define TARGET_LIST = From 44fdd250ad9420e9d07911be462cfd3a2f69cc43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20L=2E=20Nedreg=C3=A5rd?= <32913789+Jens0512@users.noreply.github.com> Date: Tue, 13 Mar 2018 12:05:13 +0100 Subject: [PATCH 5/7] Grammar --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2aa71a7..46570d4 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ info ?= true info_log = $(if $(subst false,,$(info)),$(info $(1))) -# Make convention +# Makefile convention all: $(O)/myst $(O)/spec .PHONY: spec From d9254ebf1b4cbc09e136e6549e3ecdce5510234a Mon Sep 17 00:00:00 2001 From: Jens Date: Tue, 13 Mar 2018 15:26:17 +0100 Subject: [PATCH 6/7] Adressed requested changes - O changed to OUT - Tabs changed to spaces where possible (i.e. not targets) - Removed .SUFFIXES as it was useless - Fixed problem that made the .DEFAULT_GOAL example would not work --- Makefile | 55 ++++++++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 46570d4..fe0cf77 100644 --- a/Makefile +++ b/Makefile @@ -2,21 +2,13 @@ # some extremely weird shell SHELL = bash -# Parse makefiles named *.mk in the dir `local` -# for local extra makefile targets if wanted. -# It is smart to set MYSTBUILD to your myst dev-build there --include local/*.mk - # https://www.gnu.org/software/make/manual/html_node/One-Shell.html .ONESHELL: -# The docs says i should do this -.SUFFIXES: .cr .mt - MYST_CLI = src/myst_cli.cr MYST_INTERPRETER_SPEC = spec/all_spec.cr -MYST_IN_LANG_SPEC = spec/myst/spec.mt +MYST_IN_LANG_SPEC = spec/myst/spec.mt SOURCE_FILES := $(shell find src -type f -name '*.cr') SPEC_FILES := $(shell find spec -type f -name '*.cr' -o -name '*.mt') @@ -24,52 +16,57 @@ STDLIB_FILES := $(shell find stdlib -type f -name '*.mt') ALL_FILES := $(SPEC_FILES) $(STDLIB_FILES) $(SOURCE_FILES) INSTALL_LOCATION ?= /usr/local/bin/myst -MYSTBUILD ?= myst +MYSTBUILD ?= myst -O ?= bin +OUT ?= bin info ?= true -# If another default is intentionally wished for, +# If another default is wished for, # set it in local/*.mk, like this: # .DEFAULT_GOAL = goal # -.DEFAULT_GOAL ?= spec +.DEFAULT_GOAL = spec + +# Parse makefiles named *.mk in the dir `local` +# for local extra makefile targets if wanted. +# It is smart to set MYSTBUILD to your myst dev-build there +-include local/*.mk info_log = $(if $(subst false,,$(info)),$(info $(1))) # Makefile convention -all: $(O)/myst $(O)/spec +all: $(OUT)/myst $(OUT)/spec .PHONY: spec -spec: $(O)/myst $(O)/spec ## Runs all specs +spec: $(OUT)/myst $(OUT)/spec ## Runs all specs $(call info_log,Running interpreter spec) - $(O)/spec + $(OUT)/spec $(call info_log,Running in-language spec) - $(O)/myst $(MYST_IN_LANG_SPEC) + $(OUT)/myst $(MYST_IN_LANG_SPEC) -myst-spec: $(O)/myst ## Runs just the in-language specs - $(O)/myst $(MYST_IN_LANG_SPEC) +myst-spec: $(OUT)/myst ## Runs just the in-language specs + $(OUT)/myst $(MYST_IN_LANG_SPEC) .PHONY: install install: $(INSTALL_LOCATION) ## Install myst to INSTALL_LOCATION .PHONY: build -build: $(O)/myst ## Builds myst into an executable +build: $(OUT)/myst ## Builds myst into an executable .PHONY: myst-spec_with_build myst-spec_with_build: ## Runs the in-language specs with MYSTBUILD $(MYSTBUILD) $(MYST_IN_LANG_SPEC) -$(O)/myst: $(SOURCE_FILES) +$(OUT)/myst: $(SOURCE_FILES) $(call info_log,Building myst...) - mkdir -p $(O) - crystal build -o $(O)/myst $(MYST_CLI) + mkdir -p $(OUT) + crystal build -o $(OUT)/myst $(MYST_CLI) -$(O)/spec: $(ALL_FILES) +$(OUT)/spec: $(ALL_FILES) $(call info_log,Building specs...) - mkdir -p $(O) - crystal build -o $(O)/spec $(MYST_INTERPRETER_SPEC) + mkdir -p $(OUT) + crystal build -o $(OUT)/spec $(MYST_INTERPRETER_SPEC) $(INSTALL_LOCATION): $(SOURCE_FILES) $(call info_log,Installing myst to $(INSTALL_LOCATION) ...) @@ -78,9 +75,9 @@ $(INSTALL_LOCATION): $(SOURCE_FILES) .PHONY: clean clean: ## Cleans (deletes) docs and executables -ifdef O - @[ -f $(O)/myst ] && rm -f $(O)/myst* - @[ -f $(O)/spec ] && rm -f $(O)/spec* +ifdef OUT + @[ -f $(OUT)/myst ] && rm -f $(OUT)/myst* + @[ -f $(OUT)/spec ] && rm -f $(OUT)/spec* endif @rm -rf docs @ From 6fd1b5cf224856b801139830601c848892b74883 Mon Sep 17 00:00:00 2001 From: Jens Date: Tue, 13 Mar 2018 15:43:26 +0100 Subject: [PATCH 7/7] Added `itr-spec` goal --- Makefile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index fe0cf77..f40ff79 100644 --- a/Makefile +++ b/Makefile @@ -36,18 +36,22 @@ info ?= true info_log = $(if $(subst false,,$(info)),$(info $(1))) # Makefile convention +.PHONY: all all: $(OUT)/myst $(OUT)/spec .PHONY: spec -spec: $(OUT)/myst $(OUT)/spec ## Runs all specs - $(call info_log,Running interpreter spec) - $(OUT)/spec - $(call info_log,Running in-language spec) - $(OUT)/myst $(MYST_IN_LANG_SPEC) +spec: itr-spec myst-spec ## Runs all specs +.PHONY: myst-spec myst-spec: $(OUT)/myst ## Runs just the in-language specs + $(call info_log,Running in-language spec) $(OUT)/myst $(MYST_IN_LANG_SPEC) +.PHONY: itr-spec +itr-spec: $(OUT)/spec ## Runs just the interpreter specs + $(call info_log,Running interpreter spec) + $(OUT)/spec + .PHONY: install install: $(INSTALL_LOCATION) ## Install myst to INSTALL_LOCATION