Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow prefix to be set as an absolute path in configure #1151

Open
wants to merge 7 commits into
base: main
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
18 changes: 17 additions & 1 deletion foreign_cc/configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,19 @@ def _create_configure_script(configureParameters):
configure_prefix = "{} ".format(expand_locations_and_make_variables(ctx, ctx.attr.configure_prefix, "configure_prefix", data)) if ctx.attr.configure_prefix else ""
configure_options = [expand_locations_and_make_variables(ctx, option, "configure_option", data) for option in ctx.attr.configure_options] if ctx.attr.configure_options else []

if ctx.attr.experimental_absolute_install_prefix:
destdir_arg = 'DESTDIR="$$BUILD_TMPDIR$$/" '
else:
destdir_arg = ""

for target in ctx.attr.targets:
# Configure will have generated sources into `$BUILD_TMPDIR` so make sure we `cd` there
make_commands.append("{prefix}{make} {target} {args}".format(
prefix = prefix,
make = attrs.make_path,
args = args,
# https://www.gnu.org/prep/standards/html_node/DESTDIR.html
# DESTDIR only applies to INSTALL or UNINSTALL targets
args = destdir_arg + args if target.startswith("install") or target.startswith("uninstall") else args,
target = target,
))

Expand All @@ -100,6 +107,7 @@ def _create_configure_script(configureParameters):
env_vars = user_env,
configure_in_place = ctx.attr.configure_in_place,
prefix_flag = ctx.attr.prefix_flag,
absolute_prefix = ctx.attr.experimental_absolute_install_prefix,
autoconf = ctx.attr.autoconf,
autoconf_options = ctx.attr.autoconf_options,
autoreconf = ctx.attr.autoreconf,
Expand Down Expand Up @@ -187,6 +195,14 @@ def _attrs():
"configure_prefix": attr.string(
doc = "A prefix for the call to the `configure_command`.",
),
"experimental_absolute_install_prefix": attr.bool(
doc = (
"Allows the install_prefix to be an absolute path, and relies on DESTDIR to place" +
"the installation files into the correct output directory when calling `make install`"
),
mandatory = False,
default = False,
),
"install_prefix": attr.string(
doc = (
"Install prefix, i.e. relative path to where to install the result of the build. " +
Expand Down
4 changes: 3 additions & 1 deletion foreign_cc/private/configure_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def create_configure_script(
env_vars,
configure_in_place,
prefix_flag,
absolute_prefix,
autoconf,
autoconf_options,
autoreconf,
Expand Down Expand Up @@ -69,11 +70,12 @@ def create_configure_script(
).lstrip())

script.append("##mkdirs## $$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$")
script.append("{env_vars} {prefix}\"{configure}\" {prefix_flag}$$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$ {user_options}".format(
script.append("{env_vars} {prefix}\"{configure}\" {prefix_flag}{prefix_dir} {user_options}".format(
env_vars = get_make_env_vars(workspace_name, tools, flags, env_vars, deps, inputs),
prefix = configure_prefix,
configure = configure_path,
prefix_flag = prefix_flag,
prefix_dir = "$$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$" if not absolute_prefix else "$$INSTALL_PREFIX$$",
user_options = " ".join(user_options),
))

Expand Down