Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for explicitly specifying some artifacts to add #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/rubygems/commands/compile_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ def initialize
options[:include_shared_dir] = value
end

add_option "--artifact PATH", "Additional artifact to package (relative to the gem dir)" do |value, options|
(options[:artifacts] ||= []) << value
add_option "--include GLOB", "Additional artifact to package (relative to the gem dir)" do |value, options|
(options[:artifacts] ||= []) << [true, value]
end

add_option "--exclude GLOB", "Additional artifact to package (relative to the gem dir)" do |value, options|
(options[:artifacts] ||= []) << [false, value]
end

add_option "--prune", "Clean non-existing files during re-packaging" do |value, options|
Expand Down
17 changes: 8 additions & 9 deletions lib/rubygems/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ def compile

build_extensions

artifacts = (@options[:artifacts] || []).map do |rel_path|
full_path = File.join(target_dir, rel_path)
if File.file?(full_path)
full_path
artifacts = collect_artifacts

(@options[:artifacts] || []).map do |include, glob|
resolved = Dir.glob("#{target_dir}/#{glob}")
if include
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I recommend any word other than include?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Missed that one. to_include ? to_be_included ? Or I could make it a mode variable that is either :include or :exclude. What do you think ?

artifacts.concat(resolved)
else
Find.enum_for(:find, full_path)
.find_all { |p| File.file?(p) }
.to_a
artifacts -= resolved
end
end.flatten
end

artifacts.concat collect_artifacts

if shared_dir = options[:include_shared_dir]
shared_libs = collect_shared(shared_dir)
Expand Down
46 changes: 42 additions & 4 deletions test/rubygems/test_gem_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_compile_bundle_artifacts
assert_includes spec.files, "lib/#{artifact}"
end

def test_compile_bundle_additional_artifacts
def test_compile_bundle_include
util_reset_arch

artifact = "foo.some_ext"
Expand All @@ -184,7 +184,7 @@ def test_compile_bundle_additional_artifacts

compiler = Gem::Compiler.new(
gem_file, :output => @output_dir,
:artifacts => ['lib/foo.some_ext']
:artifacts => [[true, 'lib/*.some_ext']]
)
output_gem = nil

Expand All @@ -198,7 +198,45 @@ def test_compile_bundle_additional_artifacts
assert_includes spec.files, "lib/#{artifact}"
end

def test_compile_bundle_additional_directory_artifacts
def test_compile_bundle_exclude_then_include
util_reset_arch

script = <<-EO_MKRF
File.open("Rakefile", "w") do |f|
f.puts <<-EOF
task :default do
lib_dir = ENV["RUBYARCHDIR"] || ENV["RUBYLIBDIR"]
FileUtils.mkdir_p File.join(lib_dir, 'baz', 'file1.rb')
FileUtils.mkdir_p File.join(lib_dir, 'baz', 'file2.rb')
FileUtils.mkdir_p File.join(lib_dir, 'foo', 'bar')
touch File.join(lib_dir, 'foo', 'bar', 'somefile.txt')
end
EOF
end
EO_MKRF

gem_file = util_bake_gem("foo") { |s|
util_fake_extension s, "foo", script
}

compiler = Gem::Compiler.new(
gem_file,
output: @output_dir,
artifacts: [[false, '**/foo.rb'], [true, 'lib/foo/**/*']]
)
output_gem = nil

use_ui @ui do
output_gem = compiler.compile
end

assert_path_exists File.join(@output_dir, output_gem)
spec = util_read_spec File.join(@output_dir, output_gem)

assert_includes spec.files, "lib/foo/bar/somefile.txt"
end

def test_compile_bundle_include_then_exclude
util_reset_arch

script = <<-EO_MKRF
Expand All @@ -220,7 +258,7 @@ def test_compile_bundle_additional_directory_artifacts

compiler = Gem::Compiler.new(
gem_file, :output => @output_dir,
:artifacts => ['lib/foo']
:artifacts => [[true, 'lib/**/*'], [false, 'lib/baz/*']]
)
output_gem = nil

Expand Down