Class: FilePathUtils

Inherits:
Object show all
Defined in:
lib/ceedling/file_path_utils.rb

Constant Summary collapse

GLOB_MATCHER =
/[\*\?\{\}\[\]]/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_path?(path) ⇒ Boolean

return whether the given path is to be aggregated (no aggregation modifier defaults to same as +:)

Returns:

  • (Boolean)


60
61
62
# File 'lib/ceedling/file_path_utils.rb', line 60

def self.add_path?(path)
  return (path =~ /^-:/).nil?
end

.extract_path(path) ⇒ Object

extract directory path from between optional add/subtract aggregation modifiers and up to glob specifiers note: slightly different than File.dirname in that /files/foo remains /files/foo and does not become /files



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ceedling/file_path_utils.rb', line 39

def self.extract_path(path)
  path = path.sub(/^(\+|-):/, '')

  # find first occurrence of path separator followed by directory glob specifier: *, ?, {, }, [, ]
  find_index = (path =~ GLOB_MATCHER)

  # no changes needed (lop off final path separator)
  return path.chomp('/') if (find_index.nil?)

  # extract up to first glob specifier
  path = path[0..(find_index-1)]

  # lop off everything up to and including final path separator
  find_index = path.rindex('/')
  return path[0..(find_index-1)] if (not find_index.nil?)

  # return string up to first glob specifier if no path separator found
  return path
end

.extract_path_no_aggregation_operators(path) ⇒ Object

get path (and glob) lopping off optional +: / -: prefixed aggregation modifiers



65
66
67
# File 'lib/ceedling/file_path_utils.rb', line 65

def self.extract_path_no_aggregation_operators(path)
  return path.sub(/^(\+|-):/, '')
end

.os_executable_ext(executable) ⇒ Object



32
33
34
35
# File 'lib/ceedling/file_path_utils.rb', line 32

def self.os_executable_ext(executable)
  return executable.ext('.exe') if SystemWrapper.windows?
  return executable
end

.reform_glob(path) ⇒ Object

all the globs that may be in a path string work fine with one exception; to recurse through all subdirectories, the glob is dir// but our paths use convention of only dir/**



72
73
74
75
# File 'lib/ceedling/file_path_utils.rb', line 72

def self.reform_glob(path)
  return path if (path =~ /\/\*\*$/).nil?
  return path + '/**'
end

.standardize(path) ⇒ Object

standardize path to use ‘/’ path separator & have no trailing path separator



23
24
25
26
27
28
29
30
# File 'lib/ceedling/file_path_utils.rb', line 23

def self.standardize(path)
  if path.is_a? String
    path.strip!
    path.gsub!(/\\/, '/')
    path.chomp!('/')
  end
  return path
end

Instance Method Details

#form_fail_results_filepath(filepath) ⇒ Object



129
130
131
# File 'lib/ceedling/file_path_utils.rb', line 129

def form_fail_results_filepath(filepath)
  return File.join( @configurator.project_test_results_path, File.basename(filepath).ext(@configurator.extension_testfail) )
end

#form_mocks_source_filelist(mocks) ⇒ Object



186
187
188
189
190
# File 'lib/ceedling/file_path_utils.rb', line 186

def form_mocks_source_filelist(mocks)
  list = (@file_wrapper.instantiate_file_list(mocks))
  sources = list.map{|file| "#{@configurator.cmock_mock_path}/#{file}#{@configurator.extension_source}"}
  return sources
end

#form_pass_results_filelist(path, files) ⇒ Object



197
198
199
200
# File 'lib/ceedling/file_path_utils.rb', line 197

def form_pass_results_filelist(path, files)
  list = @file_wrapper.instantiate_file_list(files)
  return list.pathmap("#{path}/%n#{@configurator.extension_testpass}")
end

#form_pass_results_filepath(filepath) ⇒ Object



125
126
127
# File 'lib/ceedling/file_path_utils.rb', line 125

def form_pass_results_filepath(filepath)
  return File.join( @configurator.project_test_results_path, File.basename(filepath).ext(@configurator.extension_testpass) )
end

#form_preprocessed_file_filepath(filepath) ⇒ Object



165
166
167
# File 'lib/ceedling/file_path_utils.rb', line 165

def form_preprocessed_file_filepath(filepath)
  return File.join( @configurator.project_test_preprocess_files_path, File.basename(filepath) )
end

#form_preprocessed_includes_list_filepath(filepath) ⇒ Object



169
170
171
# File 'lib/ceedling/file_path_utils.rb', line 169

def form_preprocessed_includes_list_filepath(filepath)
  return File.join( @configurator.project_test_preprocess_includes_path, File.basename(filepath) )
end

#form_preprocessed_mockable_headers_filelist(mocks) ⇒ Object



177
178
179
180
181
182
183
184
# File 'lib/ceedling/file_path_utils.rb', line 177

def form_preprocessed_mockable_headers_filelist(mocks)
  list = @file_wrapper.instantiate_file_list(mocks)
  headers = list.map do |file|
    module_name = File.basename(file).sub(/^#{@configurator.cmock_mock_prefix}/, '').sub(/\.[a-zA-Z]+$/,'')
    "#{@configurator.project_test_preprocess_files_path}/#{module_name}#{@configurator.extension_header}"
  end
  return headers
end

#form_release_build_asm_object_filepath(filepath) ⇒ Object



96
97
98
# File 'lib/ceedling/file_path_utils.rb', line 96

def form_release_build_asm_object_filepath(filepath)
  return File.join( @configurator.project_release_build_output_asm_path, File.basename(filepath).ext(@configurator.extension_object) )
end

#form_release_build_asm_objects_filelist(files) ⇒ Object



104
105
106
# File 'lib/ceedling/file_path_utils.rb', line 104

def form_release_build_asm_objects_filelist(files)
  return (@file_wrapper.instantiate_file_list(files)).pathmap("#{@configurator.project_release_build_output_asm_path}/%n#{@configurator.extension_object}")
end

#form_release_build_c_list_filepath(filepath) ⇒ Object



108
109
110
# File 'lib/ceedling/file_path_utils.rb', line 108

def form_release_build_c_list_filepath(filepath)
  return File.join( @configurator.project_release_build_output_c_path, File.basename(filepath).ext(@configurator.extension_list) )
end

#form_release_build_c_object_filepath(filepath) ⇒ Object



92
93
94
# File 'lib/ceedling/file_path_utils.rb', line 92

def form_release_build_c_object_filepath(filepath)
  return File.join( @configurator.project_release_build_output_c_path, File.basename(filepath).ext(@configurator.extension_object) )
end

#form_release_build_c_objects_filelist(files) ⇒ Object



100
101
102
# File 'lib/ceedling/file_path_utils.rb', line 100

def form_release_build_c_objects_filelist(files)
  return (@file_wrapper.instantiate_file_list(files)).pathmap("#{@configurator.project_release_build_output_c_path}/%n#{@configurator.extension_object}")
end

#form_release_build_cache_path(filepath) ⇒ Object

release ###



84
85
86
# File 'lib/ceedling/file_path_utils.rb', line 84

def form_release_build_cache_path(filepath)
  return File.join( @configurator.project_release_build_cache_path, File.basename(filepath) )
end

#form_release_dependencies_filelist(files) ⇒ Object



112
113
114
# File 'lib/ceedling/file_path_utils.rb', line 112

def form_release_dependencies_filelist(files)
  return (@file_wrapper.instantiate_file_list(files)).pathmap("#{@configurator.project_release_dependencies_path}/%n#{@configurator.extension_dependencies}")
end

#form_release_dependencies_filepath(filepath) ⇒ Object



88
89
90
# File 'lib/ceedling/file_path_utils.rb', line 88

def form_release_dependencies_filepath(filepath)
  return File.join( @configurator.project_release_dependencies_path, File.basename(filepath).ext(@configurator.extension_dependencies) )
end

#form_runner_filepath_from_test(filepath) ⇒ Object



133
134
135
# File 'lib/ceedling/file_path_utils.rb', line 133

def form_runner_filepath_from_test(filepath)
  return File.join( @configurator.project_test_runners_path, File.basename(filepath, @configurator.extension_source)) + @configurator.test_runner_file_suffix + @configurator.extension_source
end

#form_runner_object_filepath_from_test(filepath) ⇒ Object



141
142
143
# File 'lib/ceedling/file_path_utils.rb', line 141

def form_runner_object_filepath_from_test(filepath)
  return (form_test_build_c_object_filepath(filepath)).sub(/(#{@configurator.extension_object})$/, "#{@configurator.test_runner_file_suffix}\\1")
end

#form_temp_path(filepath, prefix = '') ⇒ Object

instance methods ##########



79
80
81
# File 'lib/ceedling/file_path_utils.rb', line 79

def form_temp_path(filepath, prefix='')
  return File.join( @configurator.project_temp_path, prefix + File.basename(filepath) )
end

#form_test_build_asm_object_filepath(filepath) ⇒ Object



149
150
151
# File 'lib/ceedling/file_path_utils.rb', line 149

def form_test_build_asm_object_filepath(filepath)
  return File.join( @configurator.project_test_build_output_asm_path, File.basename(filepath).ext(@configurator.extension_object) )
end

#form_test_build_c_object_filepath(filepath) ⇒ Object



145
146
147
# File 'lib/ceedling/file_path_utils.rb', line 145

def form_test_build_c_object_filepath(filepath)
  return File.join( @configurator.project_test_build_output_c_path, File.basename(filepath).ext(@configurator.extension_object) )
end

#form_test_build_cache_path(filepath) ⇒ Object

tests ###



117
118
119
# File 'lib/ceedling/file_path_utils.rb', line 117

def form_test_build_cache_path(filepath)
  return File.join( @configurator.project_test_build_cache_path, File.basename(filepath) )
end

#form_test_build_list_filepath(filepath) ⇒ Object



161
162
163
# File 'lib/ceedling/file_path_utils.rb', line 161

def form_test_build_list_filepath(filepath)
  return File.join( @configurator.project_test_build_output_path, File.basename(filepath).ext(@configurator.extension_list) )
end

#form_test_build_map_filepath(filepath) ⇒ Object



157
158
159
# File 'lib/ceedling/file_path_utils.rb', line 157

def form_test_build_map_filepath(filepath)
  return File.join( @configurator.project_test_build_output_path, File.basename(filepath).ext(@configurator.extension_map) )
end

#form_test_build_objects_filelist(sources) ⇒ Object



173
174
175
# File 'lib/ceedling/file_path_utils.rb', line 173

def form_test_build_objects_filelist(sources)
  return (@file_wrapper.instantiate_file_list(sources)).pathmap("#{@configurator.project_test_build_output_c_path}/%n#{@configurator.extension_object}")
end

#form_test_dependencies_filelist(files) ⇒ Object



192
193
194
195
# File 'lib/ceedling/file_path_utils.rb', line 192

def form_test_dependencies_filelist(files)
  list = @file_wrapper.instantiate_file_list(files)
  return list.pathmap("#{@configurator.project_test_dependencies_path}/%n#{@configurator.extension_dependencies}")
end

#form_test_dependencies_filepath(filepath) ⇒ Object



121
122
123
# File 'lib/ceedling/file_path_utils.rb', line 121

def form_test_dependencies_filepath(filepath)
  return File.join( @configurator.project_test_dependencies_path, File.basename(filepath).ext(@configurator.extension_dependencies) )
end

#form_test_executable_filepath(filepath) ⇒ Object



153
154
155
# File 'lib/ceedling/file_path_utils.rb', line 153

def form_test_executable_filepath(filepath)
  return File.join( @configurator.project_test_build_output_path, File.basename(filepath).ext(@configurator.extension_executable) )
end

#form_test_filepath_from_runner(filepath) ⇒ Object



137
138
139
# File 'lib/ceedling/file_path_utils.rb', line 137

def form_test_filepath_from_runner(filepath)
  return filepath.sub(/#{TEST_RUNNER_FILE_SUFFIX}/, '')
end