Buildr integration is broken when reading the lock_jar data from the global_lockjar_dsl variable
bigsur0 opened this issue · comments
@mguymon this issue is blocking us from updating some of our dependencies. It looks like the bug was introduced here:
40bf494#diff-4557cafd10bd227f714d502e29c4bc7eR21
It might also be nice to include some specs for the buildr integration so that regressions can be detected automatically.
lib/lock_jar/buildr.rb
16 require 'lock_jar'
17 require 'lock_jar/domain/dsl'
18
19 #
20 module Buildr
21 attr_reader :global_lockjar_dsl
22
23 class << self
24 def project_to_lockfile(project)
25 "#{project.name.tr(':', '-')}.lock"
26 end
27 end
28
29 def lock_jar(&blk)
30 @global_lockjar_dsl = ::LockJar::Domain::Dsl.create(&blk)
31 end
Notice that this idiom doesn't work for modules:
$ cat /tmp/foo.rb
module Foo
attr_reader :bar
def init_bar
@bar = 'bar'
end
end
$ irb
>> require '/tmp/foo.rb'
=> true
>> include Foo
=> Object
>> init_bar
=> "bar"
>> Foo.bar
=> nil
I'm not exactly sure what level of visibility you require during initialization, but this might work. But, it might also expose you to mutability, which may not be desirable:
$ cat /tmp/foo.rb
module Foo
class << self
attr_accessor :bar
end
def init_bar
Foo.bar = 'bar'
end
end
$ irb
>> require '/tmp/foo.rb'
=> true
>> Foo.bar
=> nil
>> include Foo
=> Object
>> init_bar
=> "bar"
>> Foo.bar
=> "bar"
The Builder support has been neglected really. I was not sure it was actively being used. The original plan was to spin it out to its own gem, but there was not much interest so I kept it in the main gem.
Anyhow, I will get a quick fix out for this. What is the buildr version you are targeting?
Does reverting back to @@global_lockjar_dsl
fix the issue for you? If so can rollback to that version for now while I spin up the new gem.
1.4.25 is the pending release of buildr that we are using. It isn't officially released yet but will be very soon so we are using buildr from master. I can point you to the staged gem version 1.4.25 if you need that.
Here's the BUILDR issue tracking the need for 1.4.25, in case you need more backstory:
I don't think reverting to @@global_lockjar_dsl will work, here because:
$ cat /tmp/foo.rb
module Foo
attr_reader :bar
def init_bar
@@bar = 'bar'
end
end
$ irb
>> require '/tmp/foo.rb'
=> true
>> include Foo
=> Object
>> init_bar
=> "bar"
>> Foo.bar
=> nil
Changes on lines 30, 37, and 38 worked for me here, but this is totally a temporary hack.
20 module Buildr
21 attr_reader :global_lockjar_dsl
22
23 class << self
24 def project_to_lockfile(project)
25 "#{project.name.tr(':', '-')}.lock"
26 end
27 end
28
29 def lock_jar(&blk)
30 Buildr.class_eval { @global_lockjar_dsl = ::LockJar::Domain::Dsl.create(&blk) }
31 end
32
33 namespace 'lock_jar' do
34 desc 'Lock dependencies for each project'
35 task('lock') do
36 projects.each do |project|
37 lockjar_dsl = project.lockjar_dsl || @global_lockjar_dsl
38 next if lockjar_dsl.nil?
39
40 # add buildr repos
41 repositories.remote.each do |repo|
42 lockjar_dsl.repository repo
43 end
44 ::LockJar.lock(lockjar_dsl, lockfile: Buildr.project_to_lockfile(project))
45 end
46 end
47 end
The simple fix is as you stated already, scope the global_lockjar_dsl
to the Buildr
module 8863118
Home for the Buildr support for Lock Jar gem - https://github.com/mguymon/lock_jar-buildr
Released gem lock_jar-0.15.1.gem
with buildr fix