add build_dist.rb to create dist/rscons as a standalone script

This commit is contained in:
Josh Holtrop 2018-09-01 17:00:04 -04:00
parent 5cf77f1f58
commit bcd33fe098
3 changed files with 44 additions and 0 deletions

1
.gitignore vendored
View File

@ -3,5 +3,6 @@
/_yardoc/ /_yardoc/
/build_test_run/ /build_test_run/
/coverage/ /coverage/
/dist/
/doc/ /doc/
/pkg/ /pkg/

View File

@ -13,6 +13,10 @@ require "rake/clean"
CLEAN.include %w[build_test_run .yardoc doc coverage] CLEAN.include %w[build_test_run .yardoc doc coverage]
CLOBBER.include %w[pkg] CLOBBER.include %w[pkg]
task :build_dist do
sh "ruby build_dist.rb"
end
RSpec::Core::RakeTask.new(:spec, :example_string) do |task, args| RSpec::Core::RakeTask.new(:spec, :example_string) do |task, args|
if args.example_string if args.example_string
ENV["partial_specs"] = "1" ENV["partial_specs"] = "1"

39
build_dist.rb Executable file
View File

@ -0,0 +1,39 @@
#!/usr/bin/env ruby
require "fileutils"
PROG_NAME = "rscons"
START_FILE = "bin/#{PROG_NAME}"
LIB_DIR = "lib"
DIST = "dist"
files_processed = {}
process_file = lambda do |file, fh|
File.read(file, mode: "rb").each_line do |line|
if line =~ /^\s*require(?:_relative)?\s*"(.*)"$/
require_name = $1
if require_name =~ %r{^#{PROG_NAME}(?:/.*)?$}
path = "#{LIB_DIR}/#{require_name}.rb"
if File.exists?(path)
unless files_processed[path]
files_processed[path] = true
process_file[path, fh]
end
else
raise "require path #{path.inspect} not found"
end
else
fh.write(line)
end
else
fh.write(line)
end
end
end
FileUtils.mkdir_p(DIST)
File.open("#{DIST}/#{PROG_NAME}", "wb", 0755) do |fh|
process_file[START_FILE, fh]
end