Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Distribute Esy along with Reason-CLI #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 70 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,92 @@
ESY_VERSION = $(shell esy version)

ifeq ($(TYPE), bin)
RELEASE_TAG = "bin-$(shell uname | tr A-Z a-z)"
else
RELEASE_TAG = $(TYPE)
endif

RELEASE_DIR = _release/$(RELEASE_TAG)

clean:
@rm -rf _release

build-release:
ifndef NO_UNSTAGED_CHECK
@# Program "fails" if unstaged changes.
@git diff --exit-code || (echo "" && echo "!!You have unstaged changes. Please clean up first." && exit 1)
@git diff --cached --exit-code || (echo "" && echo "!!You have staged changes. Please reset them or commit them first." && exit 1);
endif
@esy release $(TYPE)
@cp ./Makefile $(RELEASE_DIR)/Makefile
@cp ./bin/esy $(RELEASE_DIR)/.bin/esy
@make \
TYPE="$(TYPE)" \
-C "$(RELEASE_DIR)" \
_build-release

_build-release:
@echo "*** Adding esy as a bundled dependency..."
@npm install --global --prefix _esyInstallation "esy@$(ESY_VERSION)"
@tar -czf _esyInstallation.tar.gz _esyInstallation
@rm -rf _esyInstallation
@echo "$$POSTINSTALL_EXTRA" >> ./postinstall.sh
@node -e "$$ADD_ESY_BIN_SCRIPT"

# Releases to Github
release: build-release
@cp ./Makefile _release/$(RELEASE_TAG)/
@make \
RELEASE_TAG="$(RELEASE_TAG)" \
ORIGIN=`git remote get-url origin` \
VERSION=`node -p "require('./package.json').version"` \
-C _release/$(RELEASE_TAG) \
_release_continue
-C "$(RELEASE_DIR)" \
_release

# This should only be called by `release` target
_release:
@echo "$$WELCOME_MSG"
@git init .
@git checkout -b branch-$(VERSION)-$(RELEASE_TAG)
@git add .
@git remote add origin $(ORIGIN)
@git fetch --tags --depth=1
@git commit -m "Preparing release $(VERSION)-$(RELEASE_TAG)"
@# Return code is inverted to receive boolean return value',
@(git tag --delete "$(VERSION)-$(RELEASE_TAG)" &> /dev/null) \
|| echo "Tag $(VERSION)-$(RELEASE_TAG) doesn't yet exist, creating it now."
@git tag -a "$(VERSION)-$(RELEASE_TAG)" -m "$(VERSION)-$(RELEASE_TAG)"
@echo "$$ALMOST_DONE_MSG"


define ADD_ESY_BIN_SCRIPT
var fs = require('fs');
var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
pkg.bin.esy = './.bin/esy'
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2));
endef
export ADD_ESY_BIN_SCRIPT

define POSTINSTALL_EXTRA

#
# Unpack esy installation
#

gunzip "_esyInstallation.tar.gz"
if hash bsdtar 2>/dev/null; then
bsdtar -xf "_esyInstallation.tar"
else
if hash tar 2>/dev/null; then
# Supply --warning=no-unknown-keyword to supresses warnings when packed on OSX
tar --warning=no-unknown-keyword -xf "_esyInstallation.tar"
else
echo >&2 "Installation requires either bsdtar or tar - neither is found. Aborting.";
fi
fi
rm -rf "_esyInstallation.tar"

endef
export POSTINSTALL_EXTRA

define WELCOME_MSG

Expand All @@ -38,10 +103,10 @@ define ALMOST_DONE_MSG
-- Almost Done. Complete the following two steps
----------------------------------------------------

Directory _release/$(RELEASE_TAG) contains a git repository ready
Directory $(RELEASE_DIR) contains a git repository ready
to be pushed under a tag to remote.

1. [REQUIRED] cd _release/$(RELEASE_TAG)
1. [REQUIRED] cd $(RELEASE_DIR)

2. git show HEAD
Make sure you approve of what will be pushed to tag $(VERSION)-$(RELEASE_TAG)
Expand All @@ -60,17 +125,3 @@ You can test install the release by running:

endef
export ALMOST_DONE_MSG

_release_continue:
@echo "$$WELCOME_MSG"
@git init .
@git checkout -b branch-$(VERSION)-$(RELEASE_TAG)
@git add .
@git remote add origin $(ORIGIN)
@git fetch --tags --depth=1
@git commit -m "Preparing release $(VERSION)-$(RELEASE_TAG)"
@# Return code is inverted to receive boolean return value',
@(git tag --delete "$(VERSION)-$(RELEASE_TAG)" &> /dev/null) \
|| echo "Tag $(VERSION)-$(RELEASE_TAG) doesn't yet exist, creating it now."
@git tag -a "$(VERSION)-$(RELEASE_TAG)" -m "$(VERSION)-$(RELEASE_TAG)"
@echo "$$ALMOST_DONE_MSG"
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ in your path:
- `ocamlrun`
- `ocamlc`/`ocamlopt`
- `ocamlfind`
- `esy`

#### Inlcuded Binaries: `esy`

reason-cli distribution comes with a tool called [esy][], a package.json
workflow for compiled languages.Refer to its [documentation][esy] for the usage
instructions.

[Esy]: https://github.com/esy-ocaml/esy-core

## Advanced

Expand All @@ -71,7 +80,7 @@ There are also two other types of releases, `dev` and `pack`.

### Releasing

You need `[email protected].16` (at least) installed globally:
You need `[email protected].21` (at least) installed globally:

```sh
npm install -g esy
Expand Down
43 changes: 43 additions & 0 deletions bin/esy
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

set -e

#
# Define $SCRIPTDIR
#

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
SCRIPTDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$SCRIPTDIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SCRIPTDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

PACKAGE_ROOT="$(dirname $SCRIPTDIR)"
ESY_COMMAND="$PACKAGE_ROOT/_esyInstallation/bin/esy"

REL_ESY__PREFIX="$PACKAGE_ROOT/rel"
DST_ESY__PREFIX="$HOME/.esy"

if [ ! -d "$DST_ESY__PREFIX" ]; then

ESY_EJECT__ROOT="$REL_ESY__PREFIX/_esyEjectRoot"

REL_ESY__STORE=$(ESY__PREFIX="$REL_ESY__PREFIX" $ESY_COMMAND config get store-path)
DST_ESY__STORE=$(ESY__PREFIX="$DST_ESY__PREFIX" $ESY_COMMAND config get store-path)

TMP_ESY__PREFIX=$(mktemp -d)
TMP_ESY__STORE="$TMP_ESY__PREFIX/s"

cp -rf $REL_ESY__STORE $TMP_ESY__STORE

find $TMP_ESY__STORE -type f -print0 \
| xargs -0 -I '{}' -P 30 $ESY_EJECT__ROOT/bin/fastreplacestring.exe "{}" "$REL_ESY__STORE" "$DST_ESY__STORE"

mkdir "$DST_ESY__PREFIX"
mv "$TMP_ESY__STORE" "$DST_ESY__STORE"
rm -rf "$TMP_ESY__PREFIX"
fi

exec "$ESY_COMMAND" "$@"