From f5c3ec505b83a20d272a66305bca565e9ff38b04 Mon Sep 17 00:00:00 2001 From: Christian Lohmaier Date: Fri, 26 Apr 2024 14:49:59 +0200 Subject: [PATCH] add --with-keep-awake switch to prevent going into sleep/suspend if used defaults to Awake for Windows and caffeinate for macOS Change-Id: I35f41bf1fb63af05ce2ec1a7f4d7b50b310536a3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166743 Reviewed-by: Christian Lohmaier Tested-by: Jenkins --- Makefile.in | 16 ++++++++-------- config_host.mk.in | 2 ++ configure.ac | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/Makefile.in b/Makefile.in index f55e92c94405..ac3e8aafb529 100644 --- a/Makefile.in +++ b/Makefile.in @@ -91,19 +91,19 @@ define gb_Top_GbuildModuleRules .PHONY: $(1).allbuild $(1).buildall $(1).allcheck $(1).checkall $(1): bootstrap fetch - cd $(SRCDIR)/$(2) && $$(MAKE) $(PARALLELISM_OPTION) $(GMAKE_OPTIONS) + $(KEEP_AWAKE_CMD) cd $(SRCDIR)/$(2) && $$(MAKE) $(PARALLELISM_OPTION) $(GMAKE_OPTIONS) $(1).build $(1).check $(1).coverage $(foreach target,$(gb_Top_MODULE_CHECK_TARGETS),$(1).$(target)): bootstrap fetch - cd $(SRCDIR)/$(2) && $$(MAKE) $(PARALLELISM_OPTION) $(GMAKE_OPTIONS) $$(patsubst $(1).%,%,$$@) + $(KEEP_AWAKE_CMD) cd $(SRCDIR)/$(2) && $$(MAKE) $(PARALLELISM_OPTION) $(GMAKE_OPTIONS) $$(patsubst $(1).%,%,$$@) $(1).clean $(1).showdeliverables: cd $(SRCDIR)/$(2) && $$(MAKE) $(PARALLELISM_OPTION) $(GMAKE_OPTIONS) $$(patsubst $(1).%,%,$$@) $(1).allbuild $(1).buildall: bootstrap fetch - $$(MAKE) $(PARALLELISM_OPTION) $(GMAKE_OPTIONS) -f $(SRCDIR)/Makefile.gbuild $(WORKDIR)/Module/$(1) + $(KEEP_AWAKE_CMD) $$(MAKE) $(PARALLELISM_OPTION) $(GMAKE_OPTIONS) -f $(SRCDIR)/Makefile.gbuild $(WORKDIR)/Module/$(1) $(1).allcheck $(1).checkall: bootstrap fetch - $$(MAKE) $(PARALLELISM_OPTION) $(GMAKE_OPTIONS) -f $(SRCDIR)/Makefile.gbuild $(WORKDIR)/Module/$(1) $(WORKDIR)/Module/check/$(1) $(WORKDIR)/Module/slowcheck/$(1) + $(KEEP_AWAKE_CMD) $$(MAKE) $(PARALLELISM_OPTION) $(GMAKE_OPTIONS) -f $(SRCDIR)/Makefile.gbuild $(WORKDIR)/Module/$(1) $(WORKDIR)/Module/check/$(1) $(WORKDIR)/Module/slowcheck/$(1) $(1).all: @echo "'make $(1).all' was renamed to 'make $(1).allcheck' (or use 'make $(1).allbuild' to build without unit tests)" @@ -170,10 +170,10 @@ gbuild_TARGETS := AllLangHelp \ # build a generic gbuild target $(foreach target,$(gbuild_TARGETS),$(target)_% $(foreach module,$(gbuild_modules),$(target)_$(module)/%)) UIConfig_modules/% %.genpatch: bootstrap fetch - $(MAKE) $(PARALLELISM_OPTION) $(GMAKE_OPTIONS) -f $(SRCDIR)/Makefile.gbuild $@ + $(KEEP_AWAKE_CMD) $(MAKE) $(PARALLELISM_OPTION) $(GMAKE_OPTIONS) -f $(SRCDIR)/Makefile.gbuild $@ $(gbuild_TARGETS): - $(MAKE) $(PARALLELISM_OPTION) $(GMAKE_OPTIONS) -f $(SRCDIR)/Makefile.gbuild $@ + $(KEEP_AWAKE_CMD) $(MAKE) $(PARALLELISM_OPTION) $(GMAKE_OPTIONS) -f $(SRCDIR)/Makefile.gbuild $@ # # Clean @@ -291,9 +291,9 @@ bootstrap: check-if-root compilerplugins # build: bootstrap fetch $(if $(CROSS_COMPILING),cross-toolset,install-gdb-printers) \ $(if $(filter check,$(MAKECMDGOALS)),$(if $(COMPILER_PLUGINS),$(if $(LODE_HOME),clang-format-check))) - $(MAKE) $(PARALLELISM_OPTION) $(IWYU_OPTION) $(GMAKE_OPTIONS) -f $(SRCDIR)/Makefile.gbuild $(build_goal) + $(KEEP_AWAKE_CMD) $(MAKE) $(PARALLELISM_OPTION) $(IWYU_OPTION) $(GMAKE_OPTIONS) -f $(SRCDIR)/Makefile.gbuild $(build_goal) ifeq ($(OS),iOS) - $(MAKE) $(PARALLELISM_OPTION) $(GMAKE_OPTIONS) ios + $(KEEP_AWAKE_CMD) $(MAKE) $(PARALLELISM_OPTION) $(GMAKE_OPTIONS) ios endif build-non-l10n-only build-l10n-only check debugrun translations packageinfo coverage $(gb_Top_MODULE_CHECK_TARGETS): build diff --git a/config_host.mk.in b/config_host.mk.in index 1d5480bacf61..70d73f0a32f5 100644 --- a/config_host.mk.in +++ b/config_host.mk.in @@ -790,6 +790,8 @@ include $(BUILDDIR)/config_$(gb_Side)_lang.mk # does use some of the variables defined above include @SRC_ROOT@/download.lst +KEEP_AWAKE_CMD=@KEEP_AWAKE_CMD@ + # prep for WSL-as-helper-builds where build runs from within git-bash/MSYS that would otherwise # messes with anything that looks like a path (starts with /) but it cannot resolve export MSYS_NO_PATHCONV=1 diff --git a/configure.ac b/configure.ac index 4263116f894b..1650686382ef 100644 --- a/configure.ac +++ b/configure.ac @@ -2810,6 +2810,13 @@ AC_ARG_WITH(gtk3-build, [(Windows-only) In order to build GtkTiledViewer on Windows, pass the path to a GTK3 build, like '--with-gtk3-build=C:/gtk-build/gtk/x64/release'.])) +AC_ARG_WITH(keep-awake, + AS_HELP_STRING([--with-keep-awake], + [command to prefix make with in order to prevent the system from going to sleep/suspend + while building. + If no command is specified, defaults to using Awake (from Microsoft PowerToys) on Windows + and caffeinate on macOS])) + dnl =================================================================== dnl Branding dnl =================================================================== @@ -15243,6 +15250,40 @@ AC_SUBST(SYSTEMD_ESCAPE) AC_SUBST(SYSTEMD_RUN) AC_SUBST(WITH_COREDUMPCTL) +dnl =================================================================== +dnl Checking whether to use a keep-awake helper +dnl =================================================================== +#" +AC_MSG_CHECKING([whether to keep the system awake/prevent it from going into sleep/standby]) +if test -z "$with_keep_awake" -o "$with_keep_awake" = "no"; then + AC_MSG_RESULT([no]) +elif test "$with_keep_awake" = "yes"; then + AC_MSG_RESULT([yes (autodetect)]) + AC_MSG_CHECKING([for a suitable keep-awake command]) + if test "$_os" = "WINNT"; then + PathFormat "$(perl.exe -e 'print $ENV{"PROGRAMFILES"}')" + if test -f "$formatted_path_unix/PowerToys/PowerToys.Awake.exe"; then + AC_MSG_RESULT([using "Awake"]) + # need to pass the windows-PID to awake, so get the PGID of the shell first to get + # make's PID and then use that to get the windows-PID. + # lots of quoting for both make ($$) as well as configure ('"'"') make that command + # much scarier looking than it actually is. Using make's shell instead of subshells in + # the recipe to keep the command that's echoed by make short. + KEEP_AWAKE_CMD=$formatted_path/PowerToys/PowerToys.Awake.exe' --display-on False --pid $(shell ps | awk '"'"'/^\s+'"'"'$$(ps | awk '"'"'/^\s+'"'"'$$$$'"'"'\s+/{print $$3}'"'"')'"'"'\s+/{print $$4}'"'"') &' + else + AC_MSG_ERROR(["Awake" not found - install Microsoft PowerToys or specify a custom command]) + fi + elif test "$_os" = "Darwin"; then + AC_MSG_RESULT([using "caffeinate"]) + KEEP_AWAKE_CMD="caffeinate" + else + AC_MSG_ERROR([no default available for $_os, please specify manually]) + fi +else + AC_MSG_RESULT([yes (custom command: $with_keep_awake)]) +fi +AC_SUBST(KEEP_AWAKE_CMD) + dnl =================================================================== dnl Setting up the environment. dnl ===================================================================