Skip to content

Commit 87fc43d

Browse files
committed
Try to make bazel clean unnecessary when switching branches
Sometimes switching branches seems to cause an issue with cli compilation in bazel. This is an attempt to fix that.
1 parent 318d34a commit 87fc43d

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

deps/rabbitmq_cli/rabbitmqctl.bzl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,11 @@ export ERL_COMPILER_OPTIONS=deterministic
122122
"${{ABS_ELIXIR_HOME}}"/bin/mix local.hex --force
123123
"${{ABS_ELIXIR_HOME}}"/bin/mix local.rebar --force
124124
"${{ABS_ELIXIR_HOME}}"/bin/mix deps.get --only prod
125-
if [ ! -d _build/${{MIX_ENV}}/lib/rabbit_common ]; then
126-
cp -r ${{DEPS_DIR}}/* _build/${{MIX_ENV}}/lib
127-
fi
125+
for d in {precompiled_deps}; do
126+
mkdir _build/${{MIX_ENV}}/lib/$d
127+
ln -s ${{DEPS_DIR}}/$d/ebin _build/${{MIX_ENV}}/lib/$d
128+
ln -s ${{DEPS_DIR}}/$d/include _build/${{MIX_ENV}}/lib/$d
129+
done
128130
"${{ABS_ELIXIR_HOME}}"/bin/mix deps.compile
129131
"${{ABS_ELIXIR_HOME}}"/bin/mix compile
130132
"${{ABS_ELIXIR_HOME}}"/bin/mix escript.build
@@ -151,6 +153,10 @@ find . -type l -delete
151153
ebin_dir = ebin.path,
152154
consolidated_dir = consolidated.path,
153155
fetched_srcs = fetched_srcs.path,
156+
precompiled_deps = " ".join([
157+
dep[ErlangAppInfo].app_name
158+
for dep in ctx.attr.deps
159+
]),
154160
)
155161

156162
inputs = depset(

deps/rabbitmq_cli/rabbitmqctl_test.bzl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ def _impl(ctx):
5454
ctx.label.package,
5555
)
5656

57+
precompiled_deps = " ".join([
58+
dep[ErlangAppInfo].app_name
59+
for dep in ctx.attr.deps
60+
])
61+
5762
if not ctx.attr.is_windows:
5863
output = ctx.actions.declare_file(ctx.label.name)
5964
script = """set -euo pipefail
@@ -94,9 +99,11 @@ export ERL_COMPILER_OPTIONS=deterministic
9499
"${{ABS_ELIXIR_HOME}}"/bin/mix local.hex --force
95100
"${{ABS_ELIXIR_HOME}}"/bin/mix local.rebar --force
96101
"${{ABS_ELIXIR_HOME}}"/bin/mix deps.get
97-
if [ ! -d _build/${{MIX_ENV}}/lib/rabbit_common ]; then
98-
cp -r ${{DEPS_DIR}}/* _build/${{MIX_ENV}}/lib
99-
fi
102+
for d in {precompiled_deps}; do
103+
mkdir _build/${{MIX_ENV}}/lib/$d
104+
ln -s ${{DEPS_DIR}}/$d/ebin _build/${{MIX_ENV}}/lib/$d
105+
ln -s ${{DEPS_DIR}}/$d/include _build/${{MIX_ENV}}/lib/$d
106+
done
100107
"${{ABS_ELIXIR_HOME}}"/bin/mix deps.compile
101108
"${{ABS_ELIXIR_HOME}}"/bin/mix compile
102109
@@ -131,6 +138,7 @@ set -x
131138
elixir_home = elixir_home,
132139
package_dir = package_dir,
133140
deps_dir = deps_dir,
141+
precompiled_deps = precompiled_deps,
134142
rabbitmq_run_cmd = ctx.attr.rabbitmq_run[DefaultInfo].files_to_run.executable.short_path,
135143
)
136144
else:
@@ -162,6 +170,11 @@ set MIX_ENV=test
162170
echo y | "{elixir_home}\\bin\\mix" local.hex --force || goto :error
163171
echo y | "{elixir_home}\\bin\\mix" local.rebar --force || goto :error
164172
"{elixir_home}\\bin\\mix" deps.get || goto :error
173+
for %%d in ({precompiled_deps}) do (
174+
mkdir _build\\%MIX_ENV%\\lib\\%%d
175+
robocopy %DEPS_DIR%\\%%d\\ebin _build\\%MIX_ENV%\\lib\\%%d /E /NFL /NDL /NJH /NJS /nc /ns /np
176+
robocopy %DEPS_DIR%\\%%d\\include _build\\%MIX_ENV%\\lib\\%%d /E /NFL /NDL /NJH /NJS /nc /ns /np
177+
)
165178
"{elixir_home}\\bin\\mix" deps.compile || goto :error
166179
"{elixir_home}\\bin\\mix" compile || goto :error
167180
@@ -179,6 +192,7 @@ exit /b 1
179192
elixir_home = windows_path(elixir_home),
180193
package_dir = windows_path(ctx.label.package),
181194
deps_dir = deps_dir,
195+
precompiled_deps = precompiled_deps,
182196
rabbitmq_run_cmd = ctx.attr.rabbitmq_run[DefaultInfo].files_to_run.executable.short_path,
183197
)
184198

0 commit comments

Comments
 (0)