import [filename] with task [filename] causes both to execute TWICE?
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- ruby
- Lĩnh vực
- build-system, cli
Hướng nghiên cứu
Tái hiện hành vi bằng các ví dụ Rakefile và foo.rb, sau đó lần theo entry point của việc import và đường đi của lệnh -T. Kiểm tra cách các tệp được import và các task cùng tên được lập lịch, bao gồm cả việc liệt kê task, rồi thêm hoặc cập nhật các bài kiểm thử để số lần thực thi dự kiến và hành vi của -T được thể hiện rõ ràng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I picked up Andrey Koleshko's Rake Task Management Essentials to start learning rake. The book covers the import statement in Chapter 1. After some tinkering, I think I figured out what he was trying to say, but noticed some differences between the behavior he describes in the book and what happens on my machine.
I've copied the relevant section below for reference, but I think the upshot is:
If you import a file, and also define a task with the same name as that file, then that task will be run before the file is imported. This feature is provided so that dependency files may be generated on-the-fly.
...The
importstatement may be used in any line of theRakefile, and this doesn't apply to the loading process at all. The imported files will be loaded after the wholeRakefileis loaded. Its usage looks similar to therequirestatement and is shown in the following line of code:import(filename)Here, you are able to pass more than one file.
There is one more feature of the
importmethod. If you pass the filenames to theimporttask, they are evaluated first, and this allows us to generate the dependent files on the fly. Look at the followingRakefile:task 'dep.rb' do sh %Q{echo "puts 'Hello, from the dep.rb'" > dep.rb} end task :hello => 'dep.rb' import 'dep.rb'This example generates the
dep.rbfile on thefiledue to theimport 'dep.rb'call that evaluates the'dep.rb'task. The result of thehellotask execution is shown as follows:$ rake hello echo "puts 'Hello, from the dep.rb'" > dep.rb Hello, from the dep.rb
The problem is that on my machine, the aforementioned pre-import task runs twice:
# Rakefile
import 'foo.rb'
task 'foo.rb' do
puts "I'm a little teacup,"
end
# foo.rb
puts "short and stout!"
$ rake foo.rb
I'm a little teacup,
short and stout!
I'm a little teacup,
short and stout!
At first, I thought this was happening because I was explicitly calling the foo.rb task, so maybe that was running once because I called it and again in response to the import statement — but then I tried running a different task altogether:
# Rakefile
import 'foo.rb'
task 'foo.rb' do
puts "I'm a little teacup,"
end
task :bar
and I get the same duplicated output as before:
$ rake bar
I'm a little teacup,
short and stout!
I'm a little teacup,
short and stout!
In fact, it doesn't just spit out the same input twice; it actually runs twice, from start to finish:
# Rakefile
import 'foo.rb'
task 'foo.rb' do
if !File.exist?('foo.rb')
puts 'Where is foo.rb?'
`echo "puts 'I\'m right here.'" > foo.rb`
else
puts 'Oh, I didn\'t see you there.'
`echo "puts 'Sorry, I got held up in traffic.'" > foo.rb`
end
end
$ rm foo.rb
$ rake foo.rb
Where is foo.rb?
I'm right here.
Oh, I didn't see you there.
Sorry, I got held up in traffic.
Is this the expected behavior, or does this constitute a bug in rake?
On a related note, the command-line flag -T is supposed to display a list of all the rake tasks that have descriptions, but when running rake -T against the above Rakefile, the import directive causes the corresponding task to run anyway:
$ rake -T
I'm a little teacup,
short and stout!
I'm a little teacup,
short and stout!
Is this the expected behavior, or does this constitute a bug in rake?
FWIW I'm on Ruby 2.4.0 / Rake 12.0.0
- Ngôn ngữ chính
- Ruby
- Star
- 2.5k
- Fork
- 650
- Merge trung bình
- 6 phút
- Pull request đã merge (30 ngày)
- 3
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ruby/rake
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 28/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 45/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
palladius/rails8-app-on-gcp#145 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
rubocop/rubocop-rspec#2236 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
riscv/riscv-unified-db#2624 · 1 reaction ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100