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

Refactor: Split add_standard_build_actions introducing add_pre_build_commands #1077

Merged
Merged
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
13 changes: 10 additions & 3 deletions src/rez/build_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,7 @@ def add_standard_build_actions(cls, executor, context, variant, build_type,

This includes:
- Setting a standard list on env-vars;
- Executing pre_build_commands(), if the package has one.
"""
from rez.utils.data_utils import RO_AttrDictWrapper

# set env vars
env_vars = cls.get_standard_vars(
context=context,
Expand All @@ -301,6 +298,16 @@ def add_standard_build_actions(cls, executor, context, variant, build_type,
for var, value in env_vars.items():
executor.env[var] = value

@classmethod
def add_pre_build_commands(cls, executor, variant, build_type,
install, build_path, install_path=None):
"""Perform build commands common to every build system.

This includes:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docstring is wrong, it describes what add_standard_build_actions used to do.

- Executing pre_build_commands(), if the package has one.
"""
from rez.utils.data_utils import RO_AttrDictWrapper

# bind build-related values into a 'build' namespace
build_ns = {
"build_type": build_type.name,
Expand Down
19 changes: 14 additions & 5 deletions src/rezplugins/build_system/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _pr(s):
build_path = os.path.join(self.working_dir, build_path)
build_path = os.path.realpath(build_path)

callback = functools.partial(self._add_build_actions,
actions_callback = functools.partial(self._add_build_actions,
context=context,
package=self.package,
variant=variant,
Expand All @@ -162,11 +162,19 @@ def _pr(s):
build_path=build_path,
install_path=install_path)

post_actions_callback = functools.partial(self.add_pre_build_commands,
variant=variant,
build_type=build_type,
install=install,
build_path=build_path,
install_path=install_path)

# run the build command and capture/print stderr at the same time
retcode, _, _ = context.execute_shell(command=cmd,
block=True,
cwd=build_path,
post_actions_callback=callback)
actions_callback=actions_callback,
post_actions_callback=post_actions_callback)
ret = {}
if retcode:
ret["success"] = False
Expand Down Expand Up @@ -214,7 +222,8 @@ def _pr(s):
retcode, _, _ = context.execute_shell(command=cmd,
block=True,
cwd=build_path,
post_actions_callback=callback)
actions_callback=actions_callback,
post_actions_callback=post_actions_callback)

if not retcode and install and "install" not in cmd:
cmd.append("install")
Expand All @@ -224,7 +233,8 @@ def _pr(s):
retcode, _, _ = context.execute_shell(command=cmd,
block=True,
cwd=build_path,
post_actions_callback=callback)
actions_callback=actions_callback,
post_actions_callback=post_actions_callback)

ret["success"] = (not retcode)
return ret
Expand All @@ -250,7 +260,6 @@ def _add_build_actions(cls, executor, context, package, variant,
executor.env.REZ_BUILD_DOXYFILE = os.path.join(template_path, 'Doxyfile')
executor.env.REZ_BUILD_INSTALL_PYC = '1' if settings.install_pyc else '0'


def _FWD__spawn_build_shell(working_dir, build_path, variant_index, install,
install_path=None):
# This spawns a shell that the user can run 'make' in directly
Expand Down
13 changes: 10 additions & 3 deletions src/rezplugins/build_system/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def _add_build_actions(cls, executor, context, package, variant,
install_path=install_path
)


def _FWD__spawn_build_shell(working_dir, build_path, variant_index, install,
install_path=None):
# This spawns a shell that the user can run the build command in directly
Expand All @@ -216,7 +215,7 @@ def _FWD__spawn_build_shell(working_dir, build_path, variant_index, install,
variant = package.get_variant(variant_index)
config.override("prompt", "BUILD>")

callback = functools.partial(CustomBuildSystem._add_build_actions,
actions_callback = functools.partial(CustomBuildSystem._add_build_actions,
context=context,
package=package,
variant=variant,
Expand All @@ -225,8 +224,16 @@ def _FWD__spawn_build_shell(working_dir, build_path, variant_index, install,
build_path=build_path,
install_path=install_path)

post_actions_callback = functools.partial(CustomBuildSystem.add_pre_build_commands,
variant=variant,
build_type=BuildType.local,
install=install,
build_path=build_path,
install_path=install_path)

retcode, _, _ = context.execute_shell(block=True, cwd=build_path,
post_actions_callback=callback)
actions_callback=actions_callback,
post_actions_callback=post_actions_callback)
sys.exit(retcode)


Expand Down