Skip to content

Commit

Permalink
Don't run composer as root if unneeded
Browse files Browse the repository at this point in the history
We now track the autoload_runtime file and create it as
the normal user and because it exists we don't recreate it in the
install-domserver step as root (assuming it runs with `sudo`). It will
still create it if it doesn't exist, because domserver is a dependency for
install-domserver (and in that case `composer` would run as root again,
so prompting the user to accept this risk).

This also works for the inplace targets as those depend on `build`
which runs the `domserver` part.
  • Loading branch information
vmcj committed Jun 27, 2024
1 parent b09a88a commit b404383
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
14 changes: 4 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ endif
domserver: domserver-configure paths.mk config
judgehost: judgehost-configure paths.mk config
docs: paths.mk config
install-domserver: domserver composer-dump-autoload domserver-create-dirs
install-domserver: domserver domserver-create-dirs
install-judgehost: judgehost judgehost-create-dirs
install-docs: docs-create-dirs
dist: configure composer-dependencies
Expand Down Expand Up @@ -76,12 +76,6 @@ endif
composer-dependencies-dev:
composer $(subst 1,-q,$(QUIET)) install --prefer-dist --no-scripts --no-plugins

# Dump autoload dependencies (including plugins)
# This is needed since symfony/runtime is a Composer plugin that runs while dumping
# the autoload file
composer-dump-autoload:
composer $(subst 1,-q,$(QUIET)) dump-autoload -o -a

composer-dump-autoload-dev:
composer $(subst 1,-q,$(QUIET)) dump-autoload

Expand All @@ -101,7 +95,7 @@ build-scripts:

# List of SUBDIRS for recursive targets:
build: SUBDIRS= lib misc-tools
domserver: SUBDIRS=etc sql misc-tools webapp
domserver: SUBDIRS=etc lib sql misc-tools webapp
install-domserver: SUBDIRS=etc lib sql misc-tools webapp example_problems
judgehost: SUBDIRS=etc judge misc-tools
install-judgehost: SUBDIRS=etc lib judge misc-tools
Expand Down Expand Up @@ -222,7 +216,7 @@ webapp/.env.local:
# symlinks where necessary to let it work from the source tree.
# This stuff is a hack!
maintainer-install: inplace-install composer-dump-autoload-dev
inplace-install: build composer-dump-autoload domserver-create-dirs judgehost-create-dirs
inplace-install: build domserver-create-dirs judgehost-create-dirs
inplace-install-l:
# Replace libjudgedir with symlink to prevent lots of symlinks:
-rmdir $(judgehost_libjudgedir)
Expand Down Expand Up @@ -341,5 +335,5 @@ clean-autoconf:
$(addprefix inplace-,conf conf-common install uninstall) \
$(addprefix maintainer-,conf install) clean-autoconf config distdocs \
composer-dependencies composer-dependencies-dev \
composer-dump-autoload composer-dump-autoload-dev \
composer-dump-autoload-dev \
coverity-conf coverity-build
5 changes: 5 additions & 0 deletions lib/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
ifndef TOPDIR
TOPDIR=..
endif

REC_TARGETS = domserver

include $(TOPDIR)/Makefile.global

OBJECTS = $(addsuffix $(OBJEXT),lib.error lib.misc)
Expand Down Expand Up @@ -31,3 +34,5 @@ install-domserver:
install-judgehost:
$(INSTALL_DATA) -t $(DESTDIR)$(judgehost_libdir) *.php *.sh
$(INSTALL_PROG) -t $(DESTDIR)$(judgehost_libdir) alert

domserver: SUBDIRS=vendor
12 changes: 12 additions & 0 deletions lib/vendor/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ifndef TOPDIR
TOPDIR=../..
endif
include $(TOPDIR)/Makefile.global

clean-l:
rm -f autoload_runtime.php

autoload_runtime.php:
composer $(subst 1,-q,$(QUIET)) dump-autoload -o -a -d $(TOPDIR)

domserver: autoload_runtime.php

0 comments on commit b404383

Please sign in to comment.