Module: Origen::Generator::Comparator

Included in:
Compiler, Pattern
Defined in:
lib/origen/generator/comparator.rb

Instance Method Summary collapse

Instance Method Details

#check_for_changes(new, old, options = {}) ⇒ Object

Will check if the supplied file has changed from the last time it was generated Returns true if it is a new file, or if a change has been detected



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/origen/generator/comparator.rb', line 6

def check_for_changes(new, old, options = {})
  options = {
    comment_char:   Origen.app.tester ? Origen.app.tester.comment_char : nil,
    quiet:          false,
    compile_job:    false,
    suspend_string: 'STOPDIFF',
    resume_string:  'STARTDIFF'
  }.merge(options)

  if File.exist?(old)
    if Utility::Diff.new(file_a: new, file_b: old, ignore_blank_lines: true,
                         comment_char: options[:comment_char],
                         suspend_string: options[:suspend_string],
                         resume_string: options[:resume_string]).diffs?

      unless options[:quiet]
        cmd = "*** CHANGE DETECTED *** To update the reference:  #{Origen.config.copy_command} #{relative_path_to(new)} #{relative_path_to(old)}"
        cmd += ' /Y' if Origen.running_on_windows?
        Origen.log.info cmd
        Origen.log.info "#{Origen.config.diff_command} #{relative_path_to(old)} #{relative_path_to(new)} &"
        Origen.log.info '**********************************************************************'
      end
      if options[:compile_job]
        stats.changed_files += 1
      else
        stats.changed_patterns += 1
      end
      true
    end
  else
    unless options[:quiet]
      Origen.log.info "*** NEW FILE *** To save it:  #{Origen.config.copy_command} #{relative_path_to(new)} #{relative_path_to(old)}"
      Origen.log.info '**********************************************************************'
    end
    if options[:compile_job]
      stats.new_files += 1
    else
      stats.new_patterns += 1
    end
    true
  end
end

#relative_path_to(file) ⇒ Object



53
54
55
56
57
58
# File 'lib/origen/generator/comparator.rb', line 53

def relative_path_to(file)
  file = Pathname.new(file) unless file.is_a?(Pathname)
  p = file.expand_path.relative_path_from(Pathname.pwd).to_s
  p.gsub!('/', '\\') if Origen.running_on_windows?
  p
end

#statsObject



49
50
51
# File 'lib/origen/generator/comparator.rb', line 49

def stats
  Origen.app.stats
end