Class: Daedalus::SourceFile
- Inherits:
-
Path
- Object
- Path
- Daedalus::SourceFile
show all
- Defined in:
- lib/daedalus.rb
Instance Attribute Summary
Attributes inherited from Path
#data, #path
Instance Method Summary
collapse
Methods inherited from Path
#artifacts_path, #basename, #data_path, #save!
Constructor Details
Returns a new instance of SourceFile.
316
317
318
319
320
|
# File 'lib/daedalus.rb', line 316
def initialize(path)
super
@static_deps = []
@autogen_builder = nil
end
|
Instance Method Details
#autogenerate(&builder) ⇒ Object
326
327
328
|
# File 'lib/daedalus.rb', line 326
def autogenerate(&builder)
@autogen_builder = builder
end
|
#build(ctx) ⇒ Object
403
404
405
406
407
408
409
410
411
412
413
414
|
# File 'lib/daedalus.rb', line 403
def build(ctx)
ctx.log.inc!
if @autogen_builder
ctx.log.show "GN", @path
@autogen_builder.call(ctx.log)
end
@data[:sha1] = sha1(ctx)
ctx.compile path, object_path
save!
end
|
#clean ⇒ Object
416
417
418
419
420
421
|
# File 'lib/daedalus.rb', line 416
def clean
File.unlink object_path if File.exists?(object_path)
File.unlink data_path if File.exists?(data_path)
Dir.rmdir artifacts_path if Dir.entries(artifacts_path).empty?
end
|
#consider(ctx, tasks) ⇒ Object
399
400
401
|
# File 'lib/daedalus.rb', line 399
def consider(ctx, tasks)
tasks << self if out_of_date?(ctx)
end
|
#dependencies(ctx) ⇒ Object
334
335
336
337
338
339
340
341
342
|
# File 'lib/daedalus.rb', line 334
def dependencies(ctx)
deps = @data[:deps]
if ctx.sha1(@path) != @data[:dep_sha1] or !deps
deps = recalc_depedencies(ctx)
end
return deps + @static_deps
end
|
#depends_on(static_deps) ⇒ Object
322
323
324
|
# File 'lib/daedalus.rb', line 322
def depends_on(static_deps)
@static_deps = static_deps
end
|
#describe(ctx) ⇒ Object
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
# File 'lib/daedalus.rb', line 423
def describe(ctx)
if !File.exists?(object_path)
puts "#{@path}: unbuilt"
else
if @data[:sha1] != sha1(ctx)
puts "#{@path}: out-of-date"
end
deps = newer_dependencies(ctx)
unless deps.empty?
puts "#{@path}: dependencies changed"
deps.each do |d|
puts " - #{d}"
end
end
end
end
|
#info(ctx) ⇒ Object
442
443
444
445
446
447
448
449
450
451
452
|
# File 'lib/daedalus.rb', line 442
def info(ctx)
puts @path
puts " object: #{object_path}"
puts " last hash: #{@data[:sha1]}"
puts " curr hash: #{sha1(ctx)}"
puts " dependencies:"
dependencies(ctx).each do |x|
puts " #{x}"
end
end
|
#newer_dependencies(ctx) ⇒ Object
379
380
381
382
383
|
# File 'lib/daedalus.rb', line 379
def newer_dependencies(ctx)
dependencies(ctx).find_all do |x|
ctx.mtime(x) > ctx.mtime(object_path)
end
end
|
#object_path ⇒ Object
330
331
332
|
# File 'lib/daedalus.rb', line 330
def object_path
File.join artifacts_path, "#{basename}.o"
end
|
#out_of_date?(ctx) ⇒ Boolean
385
386
387
388
389
390
391
392
393
394
395
396
397
|
# File 'lib/daedalus.rb', line 385
def out_of_date?(ctx)
unless File.exists?(@path)
return true if @autogen_builder
raise Errno::ENOENT, "Missing #{@path}"
end
return true unless File.exists?(object_path)
return true if ctx.mtime_only and ctx.mtime(@path) > ctx.mtime(object_path)
return true unless @data[:sha1] == sha1(ctx)
return false
end
|
#recalc_depedencies(ctx) ⇒ Object
344
345
346
347
348
349
350
351
|
# File 'lib/daedalus.rb', line 344
def recalc_depedencies(ctx)
deps = ctx.calculate_deps(@path)
@data[:dep_sha1] = ctx.sha1(@path)
@data[:deps] = deps
return deps
end
|
#sha1(ctx) ⇒ Object
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
# File 'lib/daedalus.rb', line 353
def sha1(ctx)
sha1 = Digest::SHA1.new
sha1 << ctx.sha1(@path)
begin
dependencies(ctx).each do |d|
sha1 << ctx.sha1(d)
end
rescue StandardError
recalc_depedencies(ctx)
sha1 = Digest::SHA1.new
sha1 << ctx.sha1(@path)
dependencies(ctx).each do |d|
begin
sha1 << ctx.sha1(d)
rescue StandardError
raise "Unable to find dependency '#{d}' from #{@path}"
end
end
end
sha1.hexdigest
end
|