Class: Bake::Blocks::Library
- Defined in:
- lib/blocks/library.rb
Instance Attribute Summary collapse
-
#archive_name ⇒ Object
readonly
Returns the value of attribute archive_name.
-
#compileBlock ⇒ Object
readonly
Returns the value of attribute compileBlock.
Attributes inherited from BlockBase
Instance Method Summary collapse
- #calcArtifactName ⇒ Object
- #calcCmdlineFile ⇒ Object
- #clean ⇒ Object
- #execute ⇒ Object
- #ignore? ⇒ Boolean
-
#initialize(block, config, referencedConfigs, compileBlock) ⇒ Library
constructor
A new instance of Library.
- #needed? ⇒ Boolean
Methods inherited from BlockBase
#calcFileCmd, #check_config_file, #cleanProjectDir, #config_changed?, #defaultToolchainTime, isCmdLineEqual?, prepareOutput, #printCmd, #process_console_output, #process_result, writeCmdLineFile
Constructor Details
#initialize(block, config, referencedConfigs, compileBlock) ⇒ Library
Returns a new instance of Library.
11 12 13 14 15 16 17 18 |
# File 'lib/blocks/library.rb', line 11 def initialize(block, config, referencedConfigs, compileBlock) super(block,config, referencedConfigs) @compileBlock = compileBlock block.set_library(self) calcArtifactName end |
Instance Attribute Details
#archive_name ⇒ Object (readonly)
Returns the value of attribute archive_name.
9 10 11 |
# File 'lib/blocks/library.rb', line 9 def archive_name @archive_name end |
#compileBlock ⇒ Object (readonly)
Returns the value of attribute compileBlock.
9 10 11 |
# File 'lib/blocks/library.rb', line 9 def compileBlock @compileBlock end |
Instance Method Details
#calcArtifactName ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/blocks/library.rb', line 20 def calcArtifactName archiver = @block.tcs[:ARCHIVER] fileEnding = archiver[:ARCHIVE_FILE_ENDING] if not @config.artifactName.nil? and @config.artifactName.name != "" baseFilename = @config.artifactName.name else baseFilename = "lib#{@projectName}#{fileEnding}" end if !@config.artifactExtension.nil? && @config.artifactExtension.name != "default" extension = ".#{@config.artifactExtension.name}" if baseFilename.include?(".") baseFilename = baseFilename.split(".")[0...-1].join(".") end baseFilename += ".#{@config.artifactExtension.name}" end @archive_name ||= File.join([@block.output_dir, baseFilename]) if Bake..abs_path_in @archive_name = File.(@archive_name, @projectDir) end return @archive_name end |
#calcCmdlineFile ⇒ Object
43 44 45 |
# File 'lib/blocks/library.rb', line 43 def calcCmdlineFile() File.(@archive_name + ".cmdline", @projectDir) end |
#clean ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/blocks/library.rb', line 152 def clean if @block.prebuild Dir.chdir(@projectDir) do @objects = [] [:CPP, :C, :ASM].map do |t| @block.tcs[:COMPILER][t][:OBJECT_FILE_ENDING] end.uniq.each do |e| @objects.concat(Dir.glob_dir("#{@block.output_dir}/**/*#{e}", @projectDir)) end if !@objects.empty? && File.exist?(@archive_name) puts "Deleting file #{@archive_name}" if Bake..verbose >= 2 if !Bake..dry FileUtils.rm_rf(@archive_name) end end end return true else return cleanProjectDir() end end |
#execute ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/blocks/library.rb', line 69 def execute #Dir.chdir(@projectDir) do if !@block.prebuild @objects = @compileBlock.objects if @objects.empty? SyncOut.mutex.synchronize do puts "No source files, library won't be created" if Bake..verbose >= 2 end return true end else @objects = [] [:CPP, :C, :ASM].map do |t| @block.tcs[:COMPILER][t][:OBJECT_FILE_ENDING] end.uniq.each do |e| @objects.concat(Dir.glob_dir("#{@block.output_dir}/**/*#{e}", @projectDir)) end if @objects.empty? if !File.exist?(File.(@archive_name, @projectDir)) SyncOut.mutex.synchronize do puts "No object files, library won't be created" if Bake..verbose >= 2 end end return true end end cmdLineCheck = false cmdLineFile = calcCmdlineFile() return true if ignore? reason = needed? if not reason cmdLineCheck = true reason = config_changed?(cmdLineFile) end archiver = @block.tcs[:ARCHIVER] cmd = Utils.flagSplit(archiver[:PREFIX], true) cmd += Utils.flagSplit(archiver[:COMMAND], true) # ar onlyCmd = cmd 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 += @objects if cmdLineCheck and BlockBase.isCmdLineEqual?(cmd, cmdLineFile) success = true else SyncOut.startStream() begin success = true BlockBase.prepareOutput(File.(@archive_name, @projectDir), @block) BlockBase.writeCmdLineFile(cmd, cmdLineFile) consoleOutput = "" realCmd = Bake..fileCmd ? calcFileCmd(cmd, onlyCmd, @archive_name, archiver) : cmd printCmd(realCmd, "Creating #{@projectName} (#{@config.name}): #{@archive_name}", reason, false) SyncOut.flushOutput() success, consoleOutput = ProcessHelper.run(realCmd, false, false, nil, [0], @projectDir) if !Bake..dry process_result(realCmd, consoleOutput, archiver[:ERROR_PARSER], nil, reason, success) check_config_file() ensure SyncOut.stopStream() end end return success #end end |
#ignore? ⇒ Boolean
47 48 49 |
# File 'lib/blocks/library.rb', line 47 def ignore? Bake..linkOnly or Bake..prepro end |
#needed? ⇒ Boolean
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/blocks/library.rb', line 51 def needed? Dir.mutex.synchronize do Dir.chdir(@projectDir) do # lib return "because library does not exist" if not File.exist?(@archive_name) aTime = File.mtime(@archive_name) # sources @objects.each do |obj| return "because object #{obj} does not exist" if not File.exist?(obj) return "because object #{obj} is newer than executable" if aTime < File.mtime(obj) end end end return false end |