Skip to content

Commit

Permalink
Makefile: inprovements for bundle
Browse files Browse the repository at this point in the history
1. Decide whether to use `bundle` or `jekyll` based on the presence of
   `Gemfile` or `Gemfile.lock`

2. Use `$(SHELL)` to call `bin/knit_lessons.sh`: this let's us avoid relying
   on `/usr/bin/env` to find `bash`.

3. New `bundle` target for building `.vendor/bundle` directory with
   required gems:

   a. This is an alias for `.vendor/bundle` target which depends on
   Gemfile and Gemfile.lock
   b. It installs/updates bundled gems only if necessary

4. Empty Gemfile and Gemfile.lock targets for lessons that don't use
   them.

5. `clean` target: remove `.vendor` directory
  • Loading branch information
maxim-belkin committed Aug 17, 2020
1 parent bcb686d commit 881170a
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@

# Settings
MAKEFILES=Makefile $(wildcard *.mk)
JEKYLL=bundle config --local set path .vendor/bundle && bundle install && bundle update && bundle exec jekyll
PARSER=bin/markdown_ast.rb
DST=_site

ifneq (, $(wildcard Gemfile*))
JEKYLL := bundle exec jekyll
else
JEKYLL := jekyll
endif

# Check Python 3 is installed and determine if it's called via python3 or python
# (https://stackoverflow.com/a/4933395)
PYTHON3_EXE := $(shell which python3 2>/dev/null)
Expand All @@ -32,7 +37,7 @@ endif


# Controls
.PHONY : commands clean files install-rmd-deps
.PHONY : clean

# Default target
.DEFAULT_GOAL := commands
Expand Down Expand Up @@ -68,6 +73,7 @@ clean :
@rm -rf ${DST}
@rm -rf .sass-cache
@rm -rf bin/__pycache__
@rm -rf .vendor
@find . -name .DS_Store -exec rm {} \;
@find . -name '*~' -exec rm {} \;
@find . -name '*.pyc' -exec rm {} \;
Expand All @@ -93,7 +99,7 @@ workshop-check :
## III. Commands specific to lesson websites
## =================================================

.PHONY : lesson-check lesson-md lesson-files lesson-fixme
.PHONY : lesson-check lesson-md lesson-files lesson-fixme install-rmd-deps

# RMarkdown files
RMD_SRC = $(wildcard _episodes_rmd/??-*.Rmd)
Expand Down Expand Up @@ -128,7 +134,7 @@ lesson-md : ${RMD_DST}

_episodes/%.md: _episodes_rmd/%.Rmd install-rmd-dependencies
@mkdir -p _episodes
@bin/knit_lessons.sh $< $@
@$(SHELL) bin/knit_lessons.sh $< $@

## * lesson-check : validate lesson Markdown
lesson-check : lesson-fixme
Expand Down Expand Up @@ -157,6 +163,27 @@ lesson-fixme :
## IV. Auxililary (plumbing) commands
## =================================================

## * commands : show all commands.
.PHONY : commands bundle

## * commands : show all commands
commands :
@sed -n -e '/^##/s|^##[[:space:]]*||p' $(MAKEFILE_LIST)

## * bundle : install Ruby gems specified in Gemfile / Gemfile.lock
bundle : .vendor/bundle

.vendor/bundle: Gemfile Gemfile.lock
ifneq (, $(wildcard Gemfile*))
@bundle config --local set path '.vendor/bundle'
@bundle install
@bundle update
@touch .vendor/bundle
else
@echo Can not create bundle: neither Gemfile nor Gemfile.lock found.
endif

# Gemfile and Gemfile.lock targets below do nothing. This is intentional.
Gemfile:

Gemfile.lock:

0 comments on commit 881170a

Please sign in to comment.