lib/ecic/project.rb in ecic-0.5.0 vs lib/ecic/project.rb in ecic-0.6.0
- old
+ new
@@ -18,43 +18,64 @@
#Function that returns the root directory of a ECIC project
#This is used by some generators to check if a command is called
#from within an ECIC project folder
def self.root(path = Pathname.new(Dir.pwd))
if File.exists?(File.join(path, SCRIPT_ECIC))
- return path
+ return File.expand_path(path)
elsif path.root?
return nil
end
return root(path.parent)
end
-
+
def load_libraries
lib_file = File.join(@root, LIBRARIES_CFG_SCRIPT)
if File.exists?(lib_file)
begin
eval File.read(lib_file)
rescue Exception => exc
raise "Syntax error occurred while reading #{lib_file}: #{exc.message}"
- end
+ end
# else
# raise "Could not read library definitions from #{lib_file}"
end
end
+ def has_library?(library)
+ libraries.any? {|l| l.name.eql? library.name}
+ end
- def has_library?(lib_name)
- libraries.any? {|l| l.name == lib_name }
+ def library_mapped_to(path)
+ matching_libraries = libraries.select {|l| l.path.eql? path }
+ raise "Found multiple libraries mapped to '#{path}'" if matching_libraries.length > 1
+ matching_libraries.first
end
+
+ def get_library(lib_name)
+ matching_libraries = libraries.select {|l| l.name.eql? lib_name }
+ raise "Found multiple libraries called '#{lib_name}'" if matching_libraries.length > 1
+ matching_libraries.first
+ end
-# def add_libray(name)
-# @libraries << Library.new(self, name)
-# end
+ def add_library(lib)
+ raise "A library called '#{lib.name}' already exists" if has_library?(lib)
+ raise "A library is already mapped to '#{lib.path}'" if library_mapped_to(lib.path)
+ @libraries << lib
+ return true
+ end
- #Function used by 'library.create' method used in src/confic/libraries.rb
- def library
- new_lib = Library.new(self)
- libraries << new_lib
- new_lib
+ #Function used in src/confic/libraries.rb
+ def design_library(name, options={})
+ lib = Library.new(self, name, :design, options)
+ lib.save
+ lib
+ end
+
+ #Function used in src/confic/libraries.rb
+ def testbench_library(name, options={})
+ lib = Library.new(self, name, :testbench, options)
+ lib.save
+ lib
end
def load_sources
libraries.each { |lib| lib.load_sources }
end
\ No newline at end of file