Class: Bake::Blocks::Library

Inherits:
BlockBase show all
Defined in:
lib/blocks/library.rb

Instance Attribute Summary collapse

Attributes inherited from BlockBase

#tcs

Instance Method Summary collapse

Methods inherited from BlockBase

#calcOutputDir, #check_config_file, #config_changed?, #defaultToolchainTime, isCmdLineEqual?, prepareOutput, #printCmd, #process_console_output, #process_result, writeCmdLineFile

Constructor Details

#initialize(block, config, referencedConfigs, tcs, compileBlock) ⇒ Library

Returns a new instance of Library.



11
12
13
14
15
16
# File 'lib/blocks/library.rb', line 11

def initialize(block, config, referencedConfigs, tcs, compileBlock)
  super(block,config, referencedConfigs, tcs)
  @compileBlock = compileBlock
  
  block.set_library(self)
end

Instance Attribute Details

#compileBlockObject (readonly)

Returns the value of attribute compileBlock.



9
10
11
# File 'lib/blocks/library.rb', line 9

def compileBlock
  @compileBlock
end

Instance Method Details

#archive_nameObject



18
19
20
# File 'lib/blocks/library.rb', line 18

def archive_name()
  @archive_name ||= File.join([@output_dir, "lib#{@projectName}.a"])
end

#calcCmdlineFileObject



22
23
24
# File 'lib/blocks/library.rb', line 22

def calcCmdlineFile()
  archive_name + ".cmdline"
end

#cleanObject



90
91
92
93
94
95
96
97
98
# File 'lib/blocks/library.rb', line 90

def clean
  Dir.chdir(@projectDir) do 
    if File.exist?@output_dir 
      puts "Deleting folder #{@output_dir}" if Bake.options.verbose >= 2
      FileUtils.rm_rf(@output_dir)
    end
  end unless Bake.options.filename
  return true
end

#executeObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/blocks/library.rb', line 45

def execute

  Dir.chdir(@projectDir) do
    if @compileBlock.objects.empty?
      puts "No source files, library won't be created" if Bake.options.verbose >= 2
      return true 
    end
    
    cmdLineCheck = false
    cmdLineFile = calcCmdlineFile()
    
    return true if ignore?
    reason = needed?
    if not reason
      cmdLineCheck = true
      reason = config_changed?(cmdLineFile)
    end
    return true unless reason
    archiver = @tcs[:ARCHIVER]
 
    cmd = Utils.flagSplit(archiver[:COMMAND], false) # ar

    cmd += Bake::Utils::flagSplit(archiver[:FLAGS],true) # --all_load

    cmd += archiver[:ARCHIVE_FLAGS].split(" ")
      
    if archiver[:ARCHIVE_FLAGS_SPACE]
      cmd << archive_name
    else
      cmd[cmd.length-1] += archive_name
    end
    
    cmd += @compileBlock.objects
  
    return true if cmdLineCheck and BlockBase.isCmdLineEqual?(cmd, cmdLineFile)
  
    BlockBase.prepareOutput(archive_name)
    
    BlockBase.writeCmdLineFile(cmd, cmdLineFile)
    success, consoleOutput = ProcessHelper.run(cmd, false, false)
    process_result(cmd, consoleOutput, archiver[:ERROR_PARSER], "Creating #{archive_name}", reason, success)
   
    check_config_file()
    return success
  end
end

#ignore?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/blocks/library.rb', line 26

def ignore?
  Bake.options.linkOnly or Bake.options.prepro
end

#needed?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/blocks/library.rb', line 30

def needed?
  # lib

  return "because library does not exist" if not File.exists?(archive_name)

  aTime = File.mtime(archive_name)
          
  # sources

  @compileBlock.objects.each do |obj|
    return "because object #{obj} does not exist" if not File.exists?(obj)
    return "because object #{obj} is newer than executable" if aTime < File.mtime(obj)
  end
  
  false
end