Last active
December 25, 2022 03:11
-
-
Save mattconnolly/5875987 to your computer and use it in GitHub Desktop.
Gem Spec support for git submodules inside a gem.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gem::Specification.new do |s| | |
# normal spec stuff above | |
s.files = `git ls-files`.split("\n") | |
# get an array of submodule dirs by executing 'pwd' inside each submodule | |
gem_dir = File.expand_path(File.dirname(__FILE__)) + "/" | |
`git submodule --quiet foreach pwd`.split($\).each do |submodule_path| | |
Dir.chdir(submodule_path) do | |
submodule_relative_path = submodule_path.sub gem_dir, "" | |
# issue git ls-files in submodule's directory and | |
# prepend the submodule path to create absolute file paths | |
`git ls-files`.split($\).each do |filename| | |
s.files << "#{submodule_relative_path}/#{filename}" | |
end | |
end | |
end | |
end |
I updated the post.
Using Pathname:
`git submodule --quiet foreach pwd`.split($\).each do |submodule_path|
Dir.chdir(submodule_path) do
relative = Pathname.new(submodule_path).relative_path_from(__dir__)
`git ls-files`.split($\).each do |filename|
spec.files << relative.join(filename).to_s
end
end
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, thanks for your optimizations. I will update the post with a link to this gist.