Skip to content

Commit

Permalink
Merge branch 'test/ceedling_0_32_rc' into test/refactor_loginator_and…
Browse files Browse the repository at this point in the history
…_batchinator
  • Loading branch information
mvandervoord committed Oct 14, 2024
2 parents c387969 + 2e94ec6 commit 61fb4a5
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 34 deletions.
9 changes: 8 additions & 1 deletion bin/app_cfg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def initialize()
# Blank initial value for completeness
:project_config => {},

# Default, blank value
# Default path (in build directory) to hold logs
:logging_path => '',

# If logging enabled, the filepath for Ceedling's log (may be explicitly set to be outside :logging_path)
:log_filepath => '',

# Only specified in project config (no command line or environment variable)
Expand Down Expand Up @@ -76,6 +79,10 @@ def set_project_config(config)
@app_cfg[:project_config] = config
end

def set_logging_path(path)
@app_cfg[:logging_path] = path
end

def set_log_filepath(filepath)
@app_cfg[:log_filepath] = filepath
end
Expand Down
35 changes: 33 additions & 2 deletions bin/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ module CeedlingTasks
specified YAML file. See documentation for complete details.
\x5> --mixin my_compiler --mixin my/path/mixin.yml"

# Intentionally disallowed Linux/Unix/Windows filename characters to avoid mistakenly filtering --logfile default
MISSING_LOGFILE_DEFAULT = "/<>\\||*"

class CLI < Thor
include Thor::Actions
extend PermissiveCLI
Expand Down Expand Up @@ -278,8 +281,10 @@ def upgrade(path)
method_option :project, :type => :string, :default => nil, :aliases => ['-p'], :desc => DOC_PROJECT_FLAG
method_option :mixin, :type => :string, :default => [], :repeatable => true, :aliases => ['-m'], :desc => DOC_MIXIN_FLAG
method_option :verbosity, :type => :string, :default => VERBOSITY_NORMAL, :aliases => ['-v'], :desc => "Sets logging level"
method_option :log, :type => :boolean, :default => false, :aliases => ['-l'], :desc => "Enable logging to default filepath in build directory"
method_option :logfile, :type => :string, :default => '', :desc => "Enable logging to given filepath"
# :default, :lazy_default & :check_default_type: allow us to encode 3 possible logfile scenarios (see special handling comments below)
method_option :logfile, :type => :string, :aliases => ['-l'],
:default => false, :lazy_default => MISSING_LOGFILE_DEFAULT, :check_default_type => false,
:desc => "Enables logging to <build path>/logs/#{DEFAULT_CEEDLING_LOGFILE} if blank or to specified filepath"
method_option :graceful_fail, :type => :boolean, :default => nil, :desc => "Force exit code of 0 for unit test failures"
method_option :test_case, :type => :string, :default => '', :desc => "Filter for individual unit test names"
method_option :exclude_test_case, :type => :string, :default => '', :desc => "Prevent matched unit test names from running"
Expand Down Expand Up @@ -313,6 +318,31 @@ def build(*tasks)
options[:mixin].each {|mixin| _options[:mixin] << mixin.dup() }
_options[:verbosity] = VERBOSITY_DEBUG if options[:debug]

# Set something to be reset below
_options[:logfile] = nil

# Handle the 3 logging option values:
# 1. No logging (default)
# 2. Enabling logging with default log filepath
# 3. Explicitly set log filepath
case options[:logfile]

# Match against Thor's :lazy_default for --logging flag with missing value
when MISSING_LOGFILE_DEFAULT
# Enable logging to default log filepath
_options[:logfile] = true

# Match against missing --logging flag
when false
# No logging
_options[:logfile] = false

# Copy in explicitly provided filepath from --logging=<filepath>
else
# Filepath to explicitly set log file
_options[:logfile] = options[:logfile].dup()
end

@handler.build( env:ENV, app_cfg:@app_cfg, options:_options, tasks:tasks )
end

Expand Down Expand Up @@ -382,6 +412,7 @@ def environment()
@handler.environment( ENV, @app_cfg, _options )
end


desc "examples", "List available example projects"
method_option :debug, :type => :boolean, :default => false, :hide => true
long_desc( CEEDLING_HANDOFF_OBJECTS[:loginator].sanitize(
Expand Down
13 changes: 11 additions & 2 deletions bin/cli_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ def upgrade_project(env, app_cfg, options, path)
def build(env:, app_cfg:, options:{}, tasks:)
@helper.set_verbosity( options[:verbosity] )

@path_validator.standardize_paths( options[:project], options[:logfile], *options[:mixin] )
@path_validator.standardize_paths( options[:project], *options[:mixin] )

@path_validator.standardize_paths( options[:logfile] ) if options[:logfile].class == String

_, config = @configinator.loadinate( builtin_mixins:BUILTIN_MIXINS, filepath:options[:project], mixins:options[:mixin], env:env )

Expand All @@ -174,10 +176,14 @@ def build(env:, app_cfg:, options:{}, tasks:)
default_tasks: default_tasks
)

log_filepath = @helper.process_logging( options[:log], options[:logfile] )
logging_path = @helper.process_logging_path( config )
log_filepath = @helper.process_log_filepath( logging_path, options[:logfile] )

@loginator.log( " > Logfile: #{log_filepath}" ) if !log_filepath.empty?

# Save references
app_cfg.set_project_config( config )
app_cfg.set_logging_path( logging_path )
app_cfg.set_log_filepath( log_filepath )
app_cfg.set_include_test_case( options[:test_case] )
app_cfg.set_exclude_test_case( options[:exclude_test_case] )
Expand Down Expand Up @@ -240,6 +246,7 @@ def dumpconfig(env, app_cfg, options, filepath, sections)

# Save references
app_cfg.set_project_config( config )
app_cfg.set_logging_path( @helper.process_logging_path( config ) )

_, path = @helper.which_ceedling?( env:env, config:config, app_cfg:app_cfg )

Expand Down Expand Up @@ -269,6 +276,7 @@ def environment(env, app_cfg, options)

# Save references
app_cfg.set_project_config( config )
app_cfg.set_logging_path( @helper.process_logging_path( config ) )

_, path = @helper.which_ceedling?( env:env, config:config, app_cfg:app_cfg )

Expand Down Expand Up @@ -446,6 +454,7 @@ def list_rake_tasks(env:, app_cfg:, filepath:nil, mixins:[], silent:false)

# Save reference to loaded configuration
app_cfg.set_project_config( config )
app_cfg.set_logging_path( @helper.process_logging_path( config ) )

_, path = @helper.which_ceedling?( env:env, config:config, app_cfg:app_cfg )

Expand Down
31 changes: 24 additions & 7 deletions bin/cli_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,35 @@ def process_graceful_fail(config:, cmdline_graceful_fail:, tasks:, default_tasks
end


def process_logging(enabled, filepath)
# No log file if neither enabled nor a specific filename/filepath
return '' if !enabled && (filepath.nil? || filepath.empty?())
def process_logging_path(config)
build_root, _ = @config_walkinator.fetch_value( :project, :build_root, hash:config )

# Default logfile name (to be placed in default location) if enabled but no filename/filepath
return DEFAULT_CEEDLING_LOGFILE if enabled && filepath.empty?()
return '' if build_root.nil?

return File.join( build_root, 'logs' )
end


def process_log_filepath(logging_path, filepath)
case filepath
# No logging
when false
return ''

# Default logfile path if no filename/filepath
when true
filepath = File.join( logging_path, DEFAULT_CEEDLING_LOGFILE )
filepath = File.expand_path( filepath )

# Otherwise, explcit filename/filepath provided that implicitly enables logging
else
filepath = File.expand_path( filepath )
end

# Otherwise, a filename/filepath was provided that implicitly enables logging
dir = File.dirname( filepath )

# Ensure logging directory path exists
if not dir.empty?
if !File.exist?( dir )
@file_wrapper.mkdir( dir )
end

Expand Down
4 changes: 2 additions & 2 deletions lib/ceedling/configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,10 @@ def validate_final(config, app_cfg)


# Create constants and accessors (attached to this object) from given hash
def build(ceedling_lib_path, config, *keys)
def build(ceedling_lib_path, logging_path, config, *keys)
flattened_config = @configurator_builder.flattenify( config )

@configurator_setup.build_project_config( ceedling_lib_path, flattened_config )
@configurator_setup.build_project_config( ceedling_lib_path, logging_path, flattened_config )

@configurator_setup.build_directory_structure( flattened_config )

Expand Down
4 changes: 2 additions & 2 deletions lib/ceedling/configurator_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def cleanup(in_hash)
end


def set_build_paths(in_hash)
def set_build_paths(in_hash, logging_path)
out_hash = {}

project_build_artifacts_root = File.join(in_hash[:project_build_root], 'artifacts')
Expand Down Expand Up @@ -139,7 +139,7 @@ def set_build_paths(in_hash)
[:project_release_build_output_path, File.join(project_build_release_root, 'out'), in_hash[:project_release_build] ],
[:project_release_dependencies_path, File.join(project_build_release_root, 'dependencies'), in_hash[:project_release_build] ],

[:project_log_path, File.join(in_hash[:project_build_root], 'logs'), true ],
[:project_log_path, logging_path, true ],

[:project_test_preprocess_includes_path, File.join(project_build_tests_root, 'preprocess/includes'), (in_hash[:project_use_test_preprocessor] != :none) ],
[:project_test_preprocess_files_path, File.join(project_build_tests_root, 'preprocess/files'), (in_hash[:project_use_test_preprocessor] != :none) ],
Expand Down
6 changes: 3 additions & 3 deletions lib/ceedling/configurator_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ def inspect
return this.class.name
end

def build_project_config(ceedling_lib_path, flattened_config)
def build_project_config(ceedling_lib_path, logging_path, flattened_config)
# Housekeeping
@configurator_builder.cleanup( flattened_config )

# Add to hash values we build up from configuration & file system contents
flattened_config.merge!( @configurator_builder.set_build_paths( flattened_config ) )
flattened_config.merge!( @configurator_builder.set_build_paths( flattened_config, logging_path ) )
flattened_config.merge!( @configurator_builder.set_rakefile_components( ceedling_lib_path, flattened_config ) )
flattened_config.merge!( @configurator_builder.set_release_target( flattened_config ) )
flattened_config.merge!( @configurator_builder.set_build_thread_counts( flattened_config ) )
Expand All @@ -53,7 +53,7 @@ def build_directory_structure(flattened_config)

flattened_config[:project_build_paths].each do |path|
if path.nil? or path.empty?
raise CeedlingException.new( "Blank internal project build path subdirectory value" )
raise CeedlingException.new( "An internal project build path subdirectory path is unexpectedly blank" )
end

@file_wrapper.mkdir( path )
Expand Down
17 changes: 2 additions & 15 deletions lib/ceedling/setupinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def do_setup( app_cfg )
@configurator.set_verbosity( config_hash )

# Logging configuration
@loginator.set_logfile( form_log_filepath( app_cfg[:log_filepath] ) )
@loginator.set_logfile( app_cfg[:log_filepath] )
@configurator.project_logging = @loginator.project_logging

log_step( 'Validating configuration contains minimum required sections', heading:false )
Expand Down Expand Up @@ -162,7 +162,7 @@ def do_setup( app_cfg )
# Skip logging this step as the end user doesn't care about this internal preparation

# Partially flatten config + build Configurator accessors and globals
@configurator.build( app_cfg[:ceedling_lib_path], config_hash, :environment )
@configurator.build( app_cfg[:ceedling_lib_path], app_cfg[:logging_path], config_hash, :environment )

##
## 8. Final plugins handling
Expand Down Expand Up @@ -192,19 +192,6 @@ def reset_defaults(config_hash)

private

def form_log_filepath( log_filepath )
# Bail out early if logging is disabled
return log_filepath if log_filepath.empty?()

# If there's no directory path, put named log file in default location
if File.dirname( log_filepath ).empty?()
return File.join( @configurator.project_log_path, log_filepath )
end

# Otherwise, log filepath includes a directory (that's already been created)
return log_filepath
end

# Neaten up a build step with progress message and some scope encapsulation
def log_step(msg, heading:true)
if heading
Expand Down

0 comments on commit 61fb4a5

Please sign in to comment.