Remove dependency on base64 - close #177
This commit is contained in:
parent
1a280a8994
commit
18a2a075c1
@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2013-2022 Josh Holtrop
|
Copyright (c) 2013-2025 Josh Holtrop
|
||||||
|
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
|
|||||||
@ -32,11 +32,12 @@ end
|
|||||||
# useful for coverage information.
|
# useful for coverage information.
|
||||||
desc "Dist Specs"
|
desc "Dist Specs"
|
||||||
task :dspec, [:example_string] => :build_dist do |task, args|
|
task :dspec, [:example_string] => :build_dist do |task, args|
|
||||||
|
FileUtils.rm_rf("test")
|
||||||
FileUtils.mkdir_p("test")
|
FileUtils.mkdir_p("test")
|
||||||
FileUtils.cp("dist/rscons", "test/rscons.rb")
|
FileUtils.cp("dist/rscons", "test/rscons.rb")
|
||||||
ENV["dist_specs"] = "1"
|
ENV["rscons_dist_specs"] = "1"
|
||||||
Rake::Task["spec"].execute(args)
|
Rake::Task["spec"].execute(args)
|
||||||
ENV.delete("dist_specs")
|
ENV.delete("rscons_dist_specs")
|
||||||
FileUtils.rm_f(Dir.glob(".rscons-*"))
|
FileUtils.rm_f(Dir.glob(".rscons-*"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
require "fileutils"
|
require "base64"
|
||||||
require "digest/md5"
|
require "digest/md5"
|
||||||
|
require "fileutils"
|
||||||
|
require "stringio"
|
||||||
|
require "zlib"
|
||||||
|
|
||||||
if File.read("lib/rscons/version.rb") =~ /VERSION = "(.+)"/
|
if File.read("lib/rscons/version.rb") =~ /VERSION = "(.+)"/
|
||||||
VERSION = $1
|
VERSION = $1
|
||||||
@ -68,11 +71,15 @@ license = File.read("LICENSE.txt").gsub(/^(.*?)$/) do |line|
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require "zlib"
|
|
||||||
require "base64"
|
|
||||||
compressed_script = Zlib::Deflate.deflate(stripped.join)
|
compressed_script = Zlib::Deflate.deflate(stripped.join)
|
||||||
|
hash = Digest::MD5.hexdigest(compressed_script)
|
||||||
encoded_compressed_script = Base64.encode64(compressed_script).gsub("\n", "")
|
encoded_compressed_script = Base64.encode64(compressed_script).gsub("\n", "")
|
||||||
hash = Digest::MD5.hexdigest(encoded_compressed_script)
|
encoded_compressed_script_io = StringIO.new(encoded_compressed_script)
|
||||||
|
commented_encoded_compressed_script = ""
|
||||||
|
until encoded_compressed_script_io.eof?
|
||||||
|
line = encoded_compressed_script_io.read(64)
|
||||||
|
commented_encoded_compressed_script += "##{line}\n"
|
||||||
|
end
|
||||||
|
|
||||||
FileUtils.rm_rf(DIST)
|
FileUtils.rm_rf(DIST)
|
||||||
FileUtils.mkdir_p(DIST)
|
FileUtils.mkdir_p(DIST)
|
||||||
@ -82,25 +89,53 @@ File.open("#{DIST}/#{PROG_NAME}", "wb", 0755) do |fh|
|
|||||||
|
|
||||||
#{license}
|
#{license}
|
||||||
|
|
||||||
|
BASE64CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||||
|
|
||||||
|
def base64_decode(s)
|
||||||
|
out = ""
|
||||||
|
v = 0
|
||||||
|
bits = 0
|
||||||
|
s.each_char do |c|
|
||||||
|
if cv = BASE64CHARS.index(c)
|
||||||
|
v = (v << 6) | cv
|
||||||
|
bits += 6
|
||||||
|
elsif c == "="
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if bits >= 8
|
||||||
|
out += (v >> (bits - 8)).chr
|
||||||
|
v &= 0xFFFFFFFF >> (32 - (bits - 8))
|
||||||
|
bits -= 8
|
||||||
|
end
|
||||||
|
end
|
||||||
|
out
|
||||||
|
end
|
||||||
|
|
||||||
script = File.join(File.dirname(__FILE__), ".rscons-#{VERSION}-#{hash}.rb")
|
script = File.join(File.dirname(__FILE__), ".rscons-#{VERSION}-#{hash}.rb")
|
||||||
unless File.exist?(script)
|
unless File.exist?(script)
|
||||||
if File.read(__FILE__, mode: "rb") =~ /^#==>(.*)/
|
if File.read(__FILE__, mode: "rb") =~ /^#==>(.*)/m
|
||||||
require "zlib"
|
require "zlib"
|
||||||
require "base64"
|
|
||||||
encoded_compressed = $1
|
encoded_compressed = $1
|
||||||
unescaped_compressed = Base64.decode64(encoded_compressed)
|
compressed = base64_decode(encoded_compressed)
|
||||||
inflated = Zlib::Inflate.inflate(unescaped_compressed)
|
if ENV["rscons_dist_specs"]
|
||||||
|
require "digest/md5"
|
||||||
|
if Digest::MD5.hexdigest(compressed) != "#{hash}"
|
||||||
|
raise "Hash mismatch when decompressing rscons executable"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
inflated = Zlib::Inflate.inflate(compressed)
|
||||||
File.open(script, "wb") do |fh|
|
File.open(script, "wb") do |fh|
|
||||||
fh.write(inflated)
|
fh.write(inflated)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise "Could not decompress."
|
raise "Error expanding rscons executable"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
load script
|
load script
|
||||||
if __FILE__ == $0
|
if __FILE__ == $0
|
||||||
Rscons::Cli.new.run(ARGV)
|
Rscons::Cli.new.run(ARGV)
|
||||||
end
|
end
|
||||||
#==>#{encoded_compressed_script}
|
#==>
|
||||||
|
#{commented_encoded_compressed_script}
|
||||||
EOF
|
EOF
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
if ENV["dist_specs"]
|
if ENV["rscons_dist_specs"]
|
||||||
require_relative "../test/rscons"
|
require_relative "../test/rscons"
|
||||||
else
|
else
|
||||||
require "simplecov"
|
require "simplecov"
|
||||||
@ -11,12 +11,7 @@ else
|
|||||||
else
|
else
|
||||||
command_name "RSpec"
|
command_name "RSpec"
|
||||||
end
|
end
|
||||||
if ENV["dist_specs"]
|
add_filter "test/rscons.rb"
|
||||||
add_filter "/bin/"
|
|
||||||
add_filter "/lib/"
|
|
||||||
else
|
|
||||||
add_filter "test/rscons.rb"
|
|
||||||
end
|
|
||||||
project_name "Rscons"
|
project_name "Rscons"
|
||||||
merge_timeout 3600
|
merge_timeout 3600
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user