Skip to content

Commit

Permalink
3.x: Add rebar3 and erlfmt install commands to configure.ps1 #3873
Browse files Browse the repository at this point in the history
  • Loading branch information
Will authored and janl committed Mar 12, 2022
1 parent 20495df commit ab9bd07
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
23 changes: 13 additions & 10 deletions Makefile.win
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
include version.mk

SHELL=cmd.exe
REBAR=bin\rebar.cmd
ERLFMT=bin\erlfmt
REBAR?=$(CURDIR)\bin\rebar.cmd
PYTHON=python.exe
ERLFMT?=$(CURDIR)\bin\erlfmt.cmd
MAKE=make -f Makefile.win
# REBAR?=$(shell where rebar.cmd)

Expand Down Expand Up @@ -77,7 +78,7 @@ DESTDIR=

# Rebar options
apps=
skip_deps=folsom,meck,mochiweb,triq,proper,snappy,bcrypt,hyper
skip_deps=folsom,meck,mochiweb,triq,proper,snappy,bcrypt,hyper,ibrowse,local
suites=
tests=

Expand Down Expand Up @@ -172,29 +173,31 @@ just-eunit: export ERL_AFLAGS = "-config $(shell echo %cd%)/rel/files/eunit.conf
just-eunit:
@$(REBAR) -r eunit $(EUNIT_OPTS)

erlfmt-check: export ERLFMT_PATH := $(ERLFMT)
erlfmt-check:
ERLFMT_PATH=bin\erlfmt python3 dev\format_check.py
@$(PYTHON) dev\format_check.py

erlfmt-format: export ERLFMT_PATH := $(ERLFMT)
erlfmt-format:
ERLFMT_PATH=bin\erlfmt python3 dev\format_all.py
@$(PYTHON) dev\format_all.py

.venv/bin/black:
@python.exe -m venv .venv
@$(PYTHON) -m venv .venv
@.venv\Scripts\pip3.exe install black || copy /b .venv\Scripts\black.exe +,,

# Python code formatter - only runs if we're on Python 3.6 or greater
python-black: .venv/bin/black
@python.exe -c "import sys; exit(1 if sys.version_info < (3,6) else 0)" || \
@$(PYTHON) -c "import sys; exit(1 if sys.version_info < (3,6) else 0)" || \
echo 'Python formatter not supported on Python < 3.6; check results on a newer platform'
@python.exe -c "import sys; exit(1 if sys.version_info >= (3,6) else 0)" || \
@$(PYTHON) -c "import sys; exit(1 if sys.version_info >= (3,6) else 0)" || \
.venv\Scripts\black.exe --check \
--exclude="build/|buck-out/|dist/|_build/|\.git/|\.hg/|\.mypy_cache/|\.nox/|\.tox/|\.venv/|src/erlfmt|src/rebar/pr2relnotes.py|src/fauxton" \
build-aux dev\run dev\format_*.py src\mango\test src\docs\src\conf.py src\docs\ext .

python-black-update: .venv/bin/black
@python.exe -c "import sys; exit(1 if sys.version_info < (3,6) else 0)" || \
@$(PYTHON) -c "import sys; exit(1 if sys.version_info < (3,6) else 0)" || \
echo 'Python formatter not supported on Python < 3.6; check results on a newer platform'
@python.exe -c "import sys; exit(1 if sys.version_info >= (3,6) else 0)" || \
@$(PYTHON) -c "import sys; exit(1 if sys.version_info >= (3,6) else 0)" || \
.venv\Scripts\black.exe \
--exclude="build/|buck-out/|dist/|_build/|\.git/|\.hg/|\.mypy_cache/|\.nox/|\.tox/|\.venv/|src/erlfmt|src/rebar/pr2relnotes.py|src/fauxton" \
build-aux dev\run dev\format_*.py src\mango\test src\docs\src\conf.py src\docs\ext .
Expand Down
40 changes: 39 additions & 1 deletion configure.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ $ConfigERL = @"
"@
$ConfigERL | Out-File "$rootdir\config.erl" -encoding ascii

if (((Get-Command "rebar.cmd" -ErrorAction SilentlyContinue) -eq $null) -or
((Get-Command "rebar3.cmd" -ErrorAction SilentlyContinue) -eq $null) -or
((Get-Command "erlfmt.cmd" -ErrorAction SilentlyContinue) -eq $null)) {
$env:Path += ";$rootdir\bin"
}

# check for rebar; if not found, build it and add it to our path
if ((Get-Command "rebar.cmd" -ErrorAction SilentlyContinue) -eq $null)
{
Expand All @@ -198,7 +204,39 @@ if ((Get-Command "rebar.cmd" -ErrorAction SilentlyContinue) -eq $null)
cp $rootdir\src\rebar\rebar $rootdir\bin\rebar
cp $rootdir\src\rebar\rebar.cmd $rootdir\bin\rebar.cmd
make -C $rootdir\src\rebar clean
$env:Path += ";$rootdir\bin"
}

# check for rebar3; if not found, build it and add it to our path
if ((Get-Command "rebar3.cmd" -ErrorAction SilentlyContinue) -eq $null)
{
Write-Verbose "==> rebar3.cmd not found; bootstrapping..."
if (-Not (Test-Path "src\rebar3"))
{
git clone --depth 1 https://github.com/erlang/rebar3.git $rootdir\src\rebar3
}
cd src\rebar3
.\bootstrap.ps1
cp $rootdir\src\rebar3\rebar3 $rootdir\bin\rebar3
cp $rootdir\src\rebar3\rebar3.cmd $rootdir\bin\rebar3.cmd
cp $rootdir\src\rebar3\rebar3.ps1 $rootdir\bin\rebar3.ps1
make -C $rootdir\src\rebar3 clean
cd ..\..
}

# check for erlfmt; if not found, build it and add it to our path
if ((Get-Command "erlfmt.cmd" -ErrorAction SilentlyContinue) -eq $null)
{
Write-Verbose "==> erlfmt.cmd not found; bootstrapping..."
if (-Not (Test-Path "src\erlfmt"))
{
git clone --depth 1 https://github.com/WhatsApp/erlfmt.git $rootdir\src\erlfmt
}
cd src\erlfmt
rebar3 as release escriptize
cp $rootdir\src\erlfmt\_build\release\bin\erlfmt $rootdir\bin\erlfmt
cp $rootdir\src\erlfmt\_build\release\bin\erlfmt.cmd $rootdir\bin\erlfmt.cmd
make -C $rootdir\src\erlfmt clean
cd ..\..
}

# only update dependencies, when we are not in a release tarball
Expand Down

0 comments on commit ab9bd07

Please sign in to comment.