diff --git a/bin/ceedling b/bin/ceedling index 13eebf07..0e43d4d3 100755 --- a/bin/ceedling +++ b/bin/ceedling @@ -76,6 +76,21 @@ begin objects = {} # Empty initial hash to be redefined (fingers crossed) objects = DIY::Context.from_yaml( File.read( bin_objects_filepath ) ) objects.build_everything() + + # Extract objects shared between bootloader and application + # This prevents double instantiation and preserves object state in handoff + handoff_objects = {} + handoff = [ + :loginator, + :file_wrapper, + :yaml_wrapper, + :config_walkinator, + :stream_wrapper, + :system_wrapper, + :verbosinator + ] + CEEDLING_HANDOFF_OBJECTS = handoff_objects + handoff.each {|name| handoff_objects[name] = objects[name] } # Remove all load paths we've relied on (main application will set up load paths again) $LOAD_PATH.delete( ceedling_bin_path ) diff --git a/bin/objects.yml b/bin/objects.yml index 4cecf178..2365864a 100644 --- a/bin/objects.yml +++ b/bin/objects.yml @@ -5,7 +5,11 @@ # SPDX-License-Identifier: MIT # ========================================================================= -# Loaded from ceedling/lib +# +# Loaded from lib/ +# ---------------- +# + file_wrapper: yaml_wrapper: @@ -25,7 +29,10 @@ loginator: - system_wrapper - stream_wrapper -# Loaded from bin (here) +# +# Loaded from bin/ +# ---------------- +# actions_wrapper: diff --git a/lib/ceedling/rakefile.rb b/lib/ceedling/rakefile.rb index d289cb73..e97a55e5 100644 --- a/lib/ceedling/rakefile.rb +++ b/lib/ceedling/rakefile.rb @@ -46,9 +46,18 @@ def log_runtime(run, start_time_s, end_time_s, enabled) # 3. Remove full path from $LOAD_PATH $LOAD_PATH.unshift( CEEDLING_APPCFG[:ceedling_lib_path] ) objects_filepath = File.join( CEEDLING_APPCFG[:ceedling_lib_path], 'objects.yml' ) + + # Create object hash and dependency injection context @ceedling = {} # Empty hash to be redefined if all goes well @ceedling = DIY::Context.from_yaml( File.read( objects_filepath ) ) + + # Inject objects already insatantiated from bin/ bootloader before building the rest + CEEDLING_HANDOFF_OBJECTS.each_pair {|name,obj| @ceedling.set_object( name.to_s, obj )} + + # Build Ceedling application's objects @ceedling.build_everything() + + # Simplify load path after construction $LOAD_PATH.delete( CEEDLING_APPCFG[:ceedling_lib_path] ) # One-stop shopping for all our setup and such after construction