Skip to content

Commit

Permalink
Remove TITLE level (that was a dumb idea).
Browse files Browse the repository at this point in the history
Continue to centralize all streaming through a single handler.
  • Loading branch information
mvandervoord committed Apr 15, 2024
1 parent 1ae8eb6 commit 9fe906f
Show file tree
Hide file tree
Showing 46 changed files with 257 additions and 276 deletions.
72 changes: 70 additions & 2 deletions bin/ceedling
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,73 @@ CEEDLING_VENDOR = File.join( CEEDLING_ROOT, 'vendor' )
# Add load path for `require 'ceedling/*'` statements and bin/ code
$LOAD_PATH.unshift( CEEDLING_BIN, CEEDLING_LIB_BASE )

# Load "bootloader" / command line handling in bin/
require 'main'
require 'cli' # Located alongside this file in CEEDLING_BIN
require 'constructor' # Assumed installed via Ceedling gem dependencies
require 'app_cfg' # Located alongside this file in CEEDLING_BIN

CEEDLING_APPCFG = get_app_cfg()

# Entry point
begin
# Construct all bootloader objects
# 1. Add full path to $LOAD_PATH to simplify objects.yml
# 2. Add vendored DIY to $LOAD_PATH so we can use it
# 3. Require DIY (used by Ceedling application too)
# 4. Perform object construction + dependency injection from bin/objects.yml
# 5. Remove unneeded / potentially problematic paths from $LOAD_PATH
$LOAD_PATH.unshift( CEEDLING_LIB )
$LOAD_PATH.unshift( File.join(CEEDLING_VENDOR, 'diy/lib') )

require 'diy'
objects = DIY::Context.from_yaml( File.read( File.join( CEEDLING_BIN, 'objects.yml' ) ) )
objects.build_everything()

$LOAD_PATH.delete( CEEDLING_BIN ) # Loaded in top-level `ceedling` script
$LOAD_PATH.delete( CEEDLING_LIB )

# Keep a copy of the command line for edge case CLI hacking (Thor consumes ARGV)
_ARGV = ARGV.clone

#
# NOTE: See comment block in cli.rb to understand CLI handling
# ------------------------------------------------------------
#

# Backwards compatibility command line hack to silently preserve Rake `-T` CLI handling
if (ARGV.size() == 1 and ARGV[0] == '-T')
# Call Rake task listing handler w/ default handling of project file and mixins
objects[:cli_handler].rake_help( env:ENV, app_cfg:CEEDLING_APPCFG )

# Run command line args through Thor (including "naked" Rake tasks)
else
CeedlingTasks::CLI.start( ARGV,
{
:app_cfg => CEEDLING_APPCFG,
:objects => objects,
}
)
end

# Handle case of Thor application CLI failing to handle command line arguments.
rescue Thor::UndefinedCommandError
# Marrying Thor & Rake command line handling creates a gap (see comments in CLI handling).
# If a user enters only Rake build tasks at the command line followed by Thor flags,
# our Thor configuration doesn't see those flags.
# We catch the exception of unrecognized Thor commands here (i.e. any "naked" Rake tasks),
# and try again by forcing the Thor `build` command at the beginning of the command line.
# This way, our Thor handling will process option flags and properly pass the Rake tasks
# along as well.
CeedlingTasks::CLI.start( _ARGV.unshift( 'build' ),
{
:app_cfg => CEEDLING_APPCFG,
:objects => objects,
}
)

# Bootloader boom handling (ideally this never runs... we failed to build much if we're here)
rescue StandardError => e
$stderr.puts( "\nERROR: #{e.message}" )
$stderr.puts( e.backtrace ) if ( defined?( PROJECT_DEBUG ) and PROJECT_DEBUG )
exit(1)
end

22 changes: 11 additions & 11 deletions bin/cli_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ def app_help(env, app_cfg, options, command, &thor_help)
# If help requested for a command, show it and skip listing build tasks
if !command.nil?
# Block handler
@streaminator.stdout_puts( 'Application ', Verbosity::TITLE )
@streaminator.stream_puts( 'Ceedling Application ' )
thor_help.call( command ) if block_given?
return
end

# Display Thor-generated help listing
@streaminator.stdout_puts( 'Application ', Verbosity::TITLE )
@streaminator.stream_puts( 'Ceedling Application ' )
thor_help.call( command ) if block_given?

# If it was help for a specific command, we're done
Expand Down Expand Up @@ -90,7 +90,7 @@ def new_project(ceedling_root, options, name, dest)
@actions._touch_file( File.join(dest, 'test/support', '.gitkeep') )
end

@streaminator.stdout_puts( "\nNew project '#{name}' created at #{dest}/\n", Verbosity::TITLE )
@streaminator.stream_puts( "\nNew project '#{name}' created at #{dest}/\n" )
end


Expand Down Expand Up @@ -124,7 +124,7 @@ def upgrade_project(ceedling_root, options, path)
@helper.copy_docs( ceedling_root, path )
end

@streaminator.stdout_puts( "\nUpgraded project at #{path}/\n", Verbosity::TITLE )
@streaminator.stream_puts( "\nUpgraded project at #{path}/\n" )
end


Expand Down Expand Up @@ -210,11 +210,11 @@ def dumpconfig(env, app_cfg, options, filepath, sections)
default_tasks: default_tasks
)
else
@streaminator.stdout_puts( " > Skipped loading Ceedling application", Verbosity::OBNOXIOUS )
@streaminator.stream_puts( " > Skipped loading Ceedling application", Verbosity::OBNOXIOUS )
end
ensure
@helper.dump_yaml( config, filepath, sections )
@streaminator.stdout_puts( "\nDumped project configuration to #{filepath}\n", Verbosity::TITLE )
@streaminator.stream_puts( "\nDumped project configuration to #{filepath}\n" )
end
end

Expand Down Expand Up @@ -258,7 +258,7 @@ def environment(env, app_cfg, options)
output << " • #{line}\n"
end

@streaminator.stdout_puts( output + "\n" )
@streaminator.stream_puts( output + "\n" )
end


Expand All @@ -271,7 +271,7 @@ def list_examples(examples_path)

examples.each {|example| output << " • #{example}\n" }

@streaminator.stdout_puts( output + "\n" )
@streaminator.stream_puts( output + "\n" )
end


Expand Down Expand Up @@ -304,7 +304,7 @@ def create_example(ceedling_root, examples_path, options, name, dest)
# Copy in documentation
@helper.copy_docs( ceedling_root, dest ) if options[:docs]

@streaminator.stdout_puts( "\nExample project '#{name}' created at #{dest}/\n", Verbosity::TITLE )
@streaminator.stream_puts( "\nExample project '#{name}' created at #{dest}/\n" )
end


Expand All @@ -316,7 +316,7 @@ def version()
Unity => #{Ceedling::Version::UNITY}
CException => #{Ceedling::Version::CEXCEPTION}
VERSION
@streaminator.stdout_puts( version )
@streaminator.stream_puts( version )
end


Expand All @@ -335,7 +335,7 @@ def list_rake_tasks(env:, app_cfg:, filepath:nil, mixins:[])
# Save reference to loaded configuration
app_cfg[:project_config] = config

@streaminator.stdout_puts( "Build & Plugin Tasks:\n(Parameterized tasks tend to require enclosing quotes and/or escape sequences in most shells)", Verbosity::TITLE )
@streaminator.stream_puts( "Ceedling Build & Plugin Tasks:\n(Parameterized tasks tend to require enclosing quotes and/or escape sequences in most shells)" )

@helper.load_ceedling(
project_filepath: project_filepath,
Expand Down
2 changes: 1 addition & 1 deletion bin/cli_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def load_ceedling(project_filepath:, config:, which:, default_tasks:[])
end

require( File.join( ceedling_path, '/lib/ceedling.rb' ) )
@streaminator.stdout_puts( " > Running Ceedling from #{ceedling_path}/", Verbosity::OBNOXIOUS )
@streaminator.stream_puts( " > Running Ceedling from #{ceedling_path}/", Verbosity::OBNOXIOUS )
end

# Set default tasks
Expand Down
70 changes: 0 additions & 70 deletions bin/main.rb

This file was deleted.

2 changes: 1 addition & 1 deletion bin/mixinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def merge(config:, mixins:)
config.deep_merge( _mixin )

# Log what filepath we used for this mixin
@streaminator.stdout_puts( " + Merged #{'(empty) ' if _mixin.empty?}#{source} mixin using #{filepath}", Verbosity::DEBUG )
@streaminator.stream_puts( " + Merged #{'(empty) ' if _mixin.empty?}#{source} mixin using #{filepath}", Verbosity::DEBUG )
end

# Validate final configuration
Expand Down
6 changes: 3 additions & 3 deletions bin/path_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ def validate(paths:, source:, type: :filepath)
# Error out on empty paths
if path.empty?
validated = false
@streaminator.stderr_puts( "ERROR: #{source} contains an empty path", Verbosity::ERRORS )
@streaminator.stream_puts( "ERROR: #{source} contains an empty path", Verbosity::ERRORS )
next
end

# Error out if path is not a directory / does not exist
if (type == :directory) and !@file_wrapper.directory?( path )
validated = false
@streaminator.stderr_puts( "ERROR: #{source} '#{path}' does not exist as a directory in the filesystem", Verbosity::ERRORS )
@streaminator.stream_puts( "ERROR: #{source} '#{path}' does not exist as a directory in the filesystem", Verbosity::ERRORS )
end

# Error out if filepath does not exist
if (type == :filepath) and !@file_wrapper.exist?( path )
validated = false
@streaminator.stderr_puts( "ERROR: #{source} '#{path}' does not exist in the filesystem", Verbosity::ERRORS )
@streaminator.stream_puts( "ERROR: #{source} '#{path}' does not exist in the filesystem", Verbosity::ERRORS )
end
end

Expand Down
6 changes: 3 additions & 3 deletions bin/projectinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def validate_mixins(mixins:, load_paths:, source:, yaml_extension:)
# Validate mixin filepaths
if !File.extname( mixin ).empty? or mixin.include?( File::SEPARATOR )
if !@file_wrapper.exist?( mixin )
@streaminator.stderr_puts( "ERROR: Cannot find mixin at #{mixin}" )
@streaminator.stream_puts( "ERROR: Cannot find mixin at #{mixin}" )
validated = false
end

Expand All @@ -142,7 +142,7 @@ def validate_mixins(mixins:, load_paths:, source:, yaml_extension:)
end

if !found
@streaminator.stderr_puts( "ERROR: #{source} '#{mixin}' cannot be found in the mixin load paths as '#{mixin + yaml_extension}'", Verbosity::ERRORS )
@streaminator.stream_puts( "ERROR: #{source} '#{mixin}' cannot be found in the mixin load paths as '#{mixin + yaml_extension}'", Verbosity::ERRORS )
validated = false
end
end
Expand Down Expand Up @@ -192,7 +192,7 @@ def load_filepath(filepath, method)
config = {} if config.nil?

# Log what the heck we loaded
@streaminator.stderr_puts( "Loaded #{'(empty) ' if config.empty?}project configuration #{method} using #{filepath}", Verbosity::DEBUG )
@streaminator.stream_puts( "Loaded #{'(empty) ' if config.empty?}project configuration #{method} using #{filepath}", Verbosity::DEBUG )

return config
rescue Errno::ENOENT
Expand Down
2 changes: 1 addition & 1 deletion lib/ceedling/build_batchinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def build_step(msg, heading: true, &block)
msg = "\n" + @reportinator.generate_progress(msg)
end

@streaminator.stdout_puts(msg, Verbosity::NORMAL)
@streaminator.stream_puts(msg, Verbosity::NORMAL)

yield # Execute build step block
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ceedling/config_matchinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def matches?(hash:, filepath:, section:, context:, operation:nil)
matched_notice(section:section, context:context, operation:operation, matcher:_matcher, filepath:filepath)
else # No match
path = generate_matcher_path(section, context, operation)
@streaminator.stderr_puts("#{path} -> `#{matcher}` did not match #{filepath}", Verbosity::DEBUG)
@streaminator.stream_puts("#{path} -> `#{matcher}` did not match #{filepath}", Verbosity::DEBUG)
end
end

Expand All @@ -159,7 +159,7 @@ def matches?(hash:, filepath:, section:, context:, operation:nil)

def matched_notice(section:, context:, operation:, matcher:, filepath:)
path = generate_matcher_path(section, context, operation)
@streaminator.stdout_puts("#{path} -> #{matcher} matched #{filepath}", Verbosity::OBNOXIOUS)
@streaminator.stream_puts("#{path} -> #{matcher} matched #{filepath}", Verbosity::OBNOXIOUS)
end

def generate_matcher_path(*keys)
Expand Down
14 changes: 7 additions & 7 deletions lib/ceedling/configurator_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,32 +169,32 @@ def validate_threads(config)
case compile_threads
when Integer
if compile_threads < 1
@streaminator.stderr_puts("ERROR: [:project][:compile_threads] must be greater than 0", Verbosity::ERRORS)
@streaminator.stream_puts("ERROR: [:project][:compile_threads] must be greater than 0", Verbosity::ERRORS)
valid = false
end
when Symbol
if compile_threads != :auto
@streaminator.stderr_puts("ERROR: [:project][:compile_threads] is neither an integer nor :auto", Verbosity::ERRORS)
@streaminator.stream_puts("ERROR: [:project][:compile_threads] is neither an integer nor :auto", Verbosity::ERRORS)
valid = false
end
else
@streaminator.stderr_puts("ERROR: [:project][:compile_threads] is neither an integer nor :auto", Verbosity::ERRORS)
@streaminator.stream_puts("ERROR: [:project][:compile_threads] is neither an integer nor :auto", Verbosity::ERRORS)
valid = false
end

case test_threads
when Integer
if test_threads < 1
@streaminator.stderr_puts("ERROR: [:project][:test_threads] must be greater than 0", Verbosity::ERRORS)
@streaminator.stream_puts("ERROR: [:project][:test_threads] must be greater than 0", Verbosity::ERRORS)
valid = false
end
when Symbol
if test_threads != :auto
@streaminator.stderr_puts("ERROR: [:project][:test_threads] is neither an integer nor :auto", Verbosity::ERRORS)
@streaminator.stream_puts("ERROR: [:project][:test_threads] is neither an integer nor :auto", Verbosity::ERRORS)
valid = false
end
else
@streaminator.stderr_puts("ERROR: [:project][:test_threads] is neither an integer nor :auto", Verbosity::ERRORS)
@streaminator.stream_puts("ERROR: [:project][:test_threads] is neither an integer nor :auto", Verbosity::ERRORS)
valid = false
end

Expand All @@ -208,7 +208,7 @@ def validate_plugins(config)
Set.new( @configurator_plugins.programmatic_plugins )

missing_plugins.each do |plugin|
@streaminator.stderr_puts("ERROR: Plugin '#{plugin}' not found in built-in or project Ruby load paths. Check load paths and plugin naming and path conventions.", Verbosity::ERRORS)
@streaminator.stream_puts("ERROR: Plugin '#{plugin}' not found in built-in or project Ruby load paths. Check load paths and plugin naming and path conventions.", Verbosity::ERRORS)
end

return ( (missing_plugins.size > 0) ? false : true )
Expand Down
Loading

0 comments on commit 9fe906f

Please sign in to comment.