class Ecic::SourceFileInfo
Class that can provide various info about what do to with a source file.
Constants
- STANDARD_LIBRARY_FOLDERS_LIST
Attributes
absolute_path[R]
library[R]
Public Class Methods
new(project, file_name, library=nil)
click to toggle source
# File lib/ecic/source_file_info.rb, line 11 def initialize(project, file_name, library=nil) @project = project @absolute_path = Pathname.new(File.expand_path(file_name)) @relative_path_from_project = @absolute_path.relative_path_from(Pathname.new("#{@project.root}")) @library = library || get_library_from_file_path end
Public Instance Methods
find_sources_file_dir(dir = @relative_path_from_project.dirname)
click to toggle source
Function that looks for a sources.rb file within the project
# File lib/ecic/source_file_info.rb, line 56 def find_sources_file_dir(dir = @relative_path_from_project.dirname) return nil if is_outside_project? file = File.join(@project.root, dir, "sources.rb") if dir.root? or dir.to_s == "." return nil elsif File.exists?(file) return dir else return find_sources_file_dir(dir.parent) end end
get_default_library_dir_from_file_path()
click to toggle source
Function that returns the name of the directory that is placed just under src/design or src/testbench:
# File lib/ecic/source_file_info.rb, line 69 def get_default_library_dir_from_file_path #Get the first directory name after src/design or src/testbench: rel_design_path_list = @relative_path_from_project.to_s.split('/') return nil if rel_design_path_list.length < 3 return nil unless STANDARD_LIBRARY_FOLDERS_LIST.include? [rel_design_path_list.first(2)].join('/') Pathname.new([rel_design_path_list.first(3)].join('/')) end
get_library_from_file_path()
click to toggle source
TBA: Make sure this function works for libraries under src/testbench as well and make sure it returns nil, if the library name cannot be determined. TBA: Update this function to first look for any sources.rb files within the project folder structure.
# File lib/ecic/source_file_info.rb, line 22 def get_library_from_file_path return nil if is_outside_project? sources_file_dir = find_sources_file_dir if sources_file_dir #A sources.rb file was found." #Check if an existing library is already mapped to that folder. If so, return that library #and otherwise return a new library that is named according to the folder already_mapped_lib = @project.library_mapped_to(sources_file_dir.to_s) return already_mapped_lib if already_mapped_lib #Use the name of the folder as the library name:" lib_dir = sources_file_dir else # puts " #Could not find an existing sources.rb file for the given source file" lib_dir = get_default_library_dir_from_file_path end unless lib_dir.nil? lib_name = lib_dir.basename.to_s Ecic::Library.new(@project, lib_name, get_library_type_from_file_path, :path => lib_dir) end end
get_library_type_from_file_path()
click to toggle source
Function that returns the type of library that
# File lib/ecic/source_file_info.rb, line 78 def get_library_type_from_file_path #Get the first directory name after src/design or src/testbench: rel_design_path_list = @relative_path_from_project.to_s.split('/') return nil if rel_design_path_list.length < 2 case [rel_design_path_list.first(2)].join('/') when "src/testbench" return :testbench when "src/design" return :design else return :design end end
is_outside_project?()
click to toggle source
# File lib/ecic/source_file_info.rb, line 43 def is_outside_project? # @relative_path_from_project.to_s.split('/')[0] == ".." /\A\.\./.match(@relative_path_from_project.to_s) end
sources_file_path()
click to toggle source
# File lib/ecic/source_file_info.rb, line 92 def sources_file_path return nil if @library.nil? # puts "#{@library.path}/sources.rb" Pathname.new("#{@library.path}/sources.rb") end