3939import os
4040import stat
4141import sys
42- import tempfile
4342import traceback
4443
4544# IMPORTANT this has to be the first easybuild import as it customises the logging
4645# expect missing log output when this not the case!
47- from easybuild .tools .build_log import EasyBuildError , init_logging , print_error , print_msg , print_warning , stop_logging
46+ from easybuild .tools .build_log import EasyBuildError , print_error , print_msg , stop_logging
4847
49- import easybuild .tools .config as config
50- import easybuild .tools .options as eboptions
51- from easybuild .framework .easyblock import EasyBlock , build_and_install_one , inject_checksums
48+ from easybuild .framework .easyblock import build_and_install_one , inject_checksums
5249from easybuild .framework .easyconfig import EASYCONFIGS_PKG_SUBDIR
5350from easybuild .framework .easyconfig .easyconfig import verify_easyconfig_filename
5451from easybuild .framework .easyconfig .style import cmdline_easyconfigs_style_check
55- from easybuild .framework .easyconfig .tools import alt_easyconfig_paths , categorize_files_by_type , dep_graph
52+ from easybuild .framework .easyconfig .tools import categorize_files_by_type , dep_graph
5653from easybuild .framework .easyconfig .tools import det_easyconfig_paths , dump_env_script , get_paths_for
5754from easybuild .framework .easyconfig .tools import parse_easyconfigs , review_pr , run_contrib_checks , skip_available
5855from easybuild .framework .easyconfig .tweak import obtain_ec_for , tweak
6461from easybuild .tools .github import new_pr , merge_pr , update_pr
6562from easybuild .tools .hooks import START , END , load_hooks , run_hook
6663from easybuild .tools .modules import modules_tool
67- from easybuild .tools .options import parse_external_modules_metadata , process_software_build_specs , use_color
68- from easybuild .tools .robot import check_conflicts , det_robot_path , dry_run , resolve_dependencies , search_easyconfigs
64+ from easybuild .tools .options import set_up_configuration , use_color
65+ from easybuild .tools .robot import check_conflicts , dry_run , resolve_dependencies , search_easyconfigs
6966from easybuild .tools .package .utilities import check_pkg_support
7067from easybuild .tools .parallelbuild import submit_jobs
7168from easybuild .tools .repository .repository import init_repository
7269from easybuild .tools .testing import create_test_report , overall_test_report , regtest , session_state
73- from easybuild .tools .version import this_is_easybuild
7470
7571_log = None
7672
7773
78- def log_start (eb_command_line , eb_tmpdir ):
79- """Log startup info."""
80- _log .info (this_is_easybuild ())
81-
82- # log used command line
83- _log .info ("Command line: %s" % (' ' .join (eb_command_line )))
84-
85- _log .info ("Using %s as temporary directory" % eb_tmpdir )
86-
87-
8874def find_easyconfigs_by_specs (build_specs , robot_path , try_to_generate , testing = False ):
8975 """Find easyconfigs by build specifications."""
9076 generated , ec_file = obtain_ec_for (build_specs , robot_path , None )
@@ -187,23 +173,6 @@ def run_contrib_style_checks(ecs, check_contrib, check_style):
187173 return check_contrib or check_style
188174
189175
190- def check_root_usage (allow_use_as_root = False ):
191- """
192- Check whether we are running as root, and act accordingly
193-
194- :param allow_use_as_root: allow use of EasyBuild as root (but do print a warning when doing so)
195- """
196- if os .getuid () == 0 :
197- if allow_use_as_root :
198- msg = "Using EasyBuild as root is NOT recommended, please proceed with care!\n "
199- msg += "(this is only allowed because EasyBuild was configured with "
200- msg += "--allow-use-as-root-and-accept-consequences)"
201- print_warning (msg )
202- else :
203- raise EasyBuildError ("You seem to be running EasyBuild with root privileges which is not wise, "
204- "so let's end this here." )
205-
206-
207176def clean_exit (logfile , tmpdir , testing , silent = False ):
208177 """Small utility function to perform a clean exit."""
209178 cleanup (logfile , tmpdir , testing , silent = silent )
@@ -221,63 +190,11 @@ def main(args=None, logfile=None, do_build=None, testing=False, modtool=None):
221190 # purposely session state very early, to avoid modules loaded by EasyBuild meddling in
222191 init_session_state = session_state ()
223192
224- # initialise options
225- eb_go = eboptions .parse_options (args = args )
226- options = eb_go .options
227- orig_paths = eb_go .args
228-
229- # set umask (as early as possible)
230- if options .umask is not None :
231- new_umask = int (options .umask , 8 )
232- old_umask = os .umask (new_umask )
193+ eb_go , cfg_settings = set_up_configuration (args = args , logfile = logfile , testing = testing )
194+ options , orig_paths = eb_go .options , eb_go .args
233195
234- # set by option parsers via set_tmpdir
235- eb_tmpdir = tempfile .gettempdir ()
236-
237- search_query = options .search or options .search_filename or options .search_short
238-
239- # initialise logging for main
240196 global _log
241- _log , logfile = init_logging (logfile , logtostdout = options .logtostdout ,
242- silent = (testing or options .terse or search_query ), colorize = options .color )
243-
244- # disallow running EasyBuild as root (by default)
245- check_root_usage (allow_use_as_root = options .allow_use_as_root_and_accept_consequences )
246-
247- # log startup info
248- eb_cmd_line = eb_go .generate_cmd_line () + eb_go .args
249- log_start (eb_cmd_line , eb_tmpdir )
250-
251- if options .umask is not None :
252- _log .info ("umask set to '%s' (used to be '%s')" % (oct (new_umask ), oct (old_umask )))
253-
254- # process software build specifications (if any), i.e.
255- # software name/version, toolchain name/version, extra patches, ...
256- (try_to_generate , build_specs ) = process_software_build_specs (options )
257-
258- # determine robot path
259- # --try-X, --dep-graph, --search use robot path for searching, so enable it with path of installed easyconfigs
260- tweaked_ecs = try_to_generate and build_specs
261- tweaked_ecs_paths , pr_path = alt_easyconfig_paths (eb_tmpdir , tweaked_ecs = tweaked_ecs , from_pr = options .from_pr )
262- auto_robot = try_to_generate or options .check_conflicts or options .dep_graph or search_query
263- robot_path = det_robot_path (options .robot_paths , tweaked_ecs_paths , pr_path , auto_robot = auto_robot )
264- _log .debug ("Full robot path: %s" % robot_path )
265-
266- # configure & initialize build options
267- config_options_dict = eb_go .get_options_by_section ('config' )
268- build_options = {
269- 'build_specs' : build_specs ,
270- 'command_line' : eb_cmd_line ,
271- 'external_modules_metadata' : parse_external_modules_metadata (options .external_modules_metadata ),
272- 'pr_path' : pr_path ,
273- 'robot_path' : robot_path ,
274- 'silent' : testing ,
275- 'try_to_generate' : try_to_generate ,
276- 'valid_stops' : [x [0 ] for x in EasyBlock .get_steps ()],
277- }
278- # initialise the EasyBuild configuration & build options
279- config .init (options , config_options_dict )
280- config .init_build_options (build_options = build_options , cmdline_options = options )
197+ (build_specs , _log , logfile , robot_path , search_query , eb_tmpdir , try_to_generate , tweaked_ecs_paths ) = cfg_settings
281198
282199 # load hook implementations (if any)
283200 hooks = load_hooks (options .hooks )
0 commit comments