mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 23:07:28 +08:00
DEV: support symlinked plugins in bin/rake autospec
Previously autospec would not pick up save if you saved a plugin in a symlinked path, this broke quite a few workflows We now maintain a reverse map so we can correctly re-run specs in plugins
This commit is contained in:
@ -18,15 +18,18 @@ fi
|
|||||||
# 2. Add VIM_AUTOSPEC=1 to your environment
|
# 2. Add VIM_AUTOSPEC=1 to your environment
|
||||||
# 3. Add the following to your .vimrc
|
# 3. Add the following to your .vimrc
|
||||||
#
|
#
|
||||||
# function s:notify_file_change()
|
|
||||||
# let root = rails#app().path()
|
# function! s:notify_file_change_discourse()
|
||||||
# let notify = root . "/bin/notify_file_change"
|
# let notify = getcwd() . "/bin/notify_file_change"
|
||||||
|
# if ! executable(notify)
|
||||||
|
# let root = rails#app().path()
|
||||||
|
# notify = root . "/bin/notify_file_change"
|
||||||
|
# end
|
||||||
# if executable(notify)
|
# if executable(notify)
|
||||||
# if executable('socat')
|
# if executable('socat')
|
||||||
# execute "!" . notify . ' ' . expand("%:p") . " " . line(".")
|
# execute "!" . notify . ' ' . expand("%:p") . " " . line(".")
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
# " redraw!
|
|
||||||
# endfunction
|
# endfunction
|
||||||
|
|
||||||
# autocmd BufWritePost * silent! call s:notify_file_change()
|
# autocmd BufWritePost * silent! call s:notify_file_change()
|
||||||
|
@ -170,6 +170,35 @@ class Autospec::Manager
|
|||||||
@queue.unshift ["focus", failed_specs.join(" "), runner] if failed_specs.length > 0
|
@queue.unshift ["focus", failed_specs.join(" "), runner] if failed_specs.length > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def root_path
|
||||||
|
root_path ||= File.expand_path(File.dirname(__FILE__) + "../../..")
|
||||||
|
end
|
||||||
|
|
||||||
|
def reverse_symlink_map
|
||||||
|
map = {}
|
||||||
|
Dir[root_path + "/plugins/*"].each do |f|
|
||||||
|
next if !File.directory? f
|
||||||
|
resolved = File.realpath(f)
|
||||||
|
if resolved != f
|
||||||
|
map[resolved] = f
|
||||||
|
end
|
||||||
|
end
|
||||||
|
map
|
||||||
|
end
|
||||||
|
|
||||||
|
# plugins can be symlinked, try to figure out which plugin this is
|
||||||
|
def reverse_symlink(file)
|
||||||
|
resolved = file
|
||||||
|
@reverse_map ||= reverse_symlink_map
|
||||||
|
@reverse_map.each do |location, discourse_location|
|
||||||
|
if file.start_with?(location)
|
||||||
|
resolved = discourse_location + file[location.length..-1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
resolved
|
||||||
|
end
|
||||||
|
|
||||||
def listen_for_changes
|
def listen_for_changes
|
||||||
puts "@@@@@@@@@@@@ listen_for_changes" if @debug
|
puts "@@@@@@@@@@@@ listen_for_changes" if @debug
|
||||||
|
|
||||||
@ -182,7 +211,7 @@ class Autospec::Manager
|
|||||||
options[:latency] = @opts[:latency] || 3
|
options[:latency] = @opts[:latency] || 3
|
||||||
end
|
end
|
||||||
|
|
||||||
path = File.expand_path(File.dirname(__FILE__) + "../../..")
|
path = root_path
|
||||||
|
|
||||||
if ENV['VIM_AUTOSPEC']
|
if ENV['VIM_AUTOSPEC']
|
||||||
STDERR.puts "Using VIM file listener"
|
STDERR.puts "Using VIM file listener"
|
||||||
@ -192,6 +221,7 @@ class Autospec::Manager
|
|||||||
server = SocketServer.new(socket_path)
|
server = SocketServer.new(socket_path)
|
||||||
server.start do |line|
|
server.start do |line|
|
||||||
file, line = line.split(' ')
|
file, line = line.split(' ')
|
||||||
|
file = reverse_symlink(file)
|
||||||
file = file.sub(Rails.root.to_s << "/", "")
|
file = file.sub(Rails.root.to_s << "/", "")
|
||||||
# process_change can aquire a mutex and block
|
# process_change can aquire a mutex and block
|
||||||
# the acceptor
|
# the acceptor
|
||||||
@ -216,7 +246,10 @@ class Autospec::Manager
|
|||||||
listener = Listen.to("#{path}/#{watch}", options) do |modified, added, _|
|
listener = Listen.to("#{path}/#{watch}", options) do |modified, added, _|
|
||||||
paths = [modified, added].flatten
|
paths = [modified, added].flatten
|
||||||
paths.compact!
|
paths.compact!
|
||||||
paths.map! { |long| long[(path.length + 1)..-1] }
|
paths.map! do |long|
|
||||||
|
long = reverse_symlink(long)
|
||||||
|
long[(path.length + 1)..-1]
|
||||||
|
end
|
||||||
process_change(paths)
|
process_change(paths)
|
||||||
end
|
end
|
||||||
listener.start
|
listener.start
|
||||||
|
Reference in New Issue
Block a user