Commit fb8bfb6f authored by Tony Arcieri's avatar Tony Arcieri

Add RuboCop

parent 5c254595
AllCops:
TargetRubyVersion: 2.2
DisplayCopNames: true
#
# Layout
#
Layout/IndentHeredoc:
Enabled: false
#
# Metrics
#
Metrics/AbcSize:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Metrics/BlockLength:
Max: 100
Metrics/ClassLength:
Max: 100
Metrics/LineLength:
Max: 128
Metrics/MethodLength:
Max: 25
#
# Style
#
Style/FrozenStringLiteralComment:
Enabled: true
Style/StringLiterals:
EnforcedStyle: double_quotes
...@@ -8,5 +8,6 @@ group :development, :test do ...@@ -8,5 +8,6 @@ group :development, :test do
gem "rake", ">= 10" gem "rake", ">= 10"
gem "rake-compiler", "~> 1.0" gem "rake-compiler", "~> 1.0"
gem "rake-compiler-dock", "~> 0.6" gem "rake-compiler-dock", "~> 0.6"
gem "rspec", "~> 3" gem "rspec", "~> 3.7"
gem "rubocop", "0.52.1"
end end
require "bundler/gem_tasks" require "bundler/gem_tasks"
require "rspec/core/rake_task" require "rspec/core/rake_task"
require 'rake/extensiontask' require "rake/extensiontask"
RSpec::Core::RakeTask.new RSpec::Core::RakeTask.new
task default: :spec require "rubocop/rake_task"
RuboCop::RakeTask.new
MAKE = ENV['MAKE'] || ENV['make'] || "make" task default: %w[spec rubocop]
RUBY_CC_VERSION = ENV['RUBY_CC_VERSION'] || '2.3.0'
MAKE = ENV["MAKE"] || ENV["make"] || "make"
RUBY_CC_VERSION = ENV["RUBY_CC_VERSION"] || "2.3.0"
desc "Build Windows binary packages" desc "Build Windows binary packages"
task 'gem:windows' do task "gem:windows" do
require 'rake_compiler_dock' require "rake_compiler_dock"
if File.exist? "vendor/libsodium/Makefile" RakeCompilerDock.sh "cd vendor/libsodium && #{MAKE} clean" if File.exist? "vendor/libsodium/Makefile"
RakeCompilerDock.sh "cd vendor/libsodium && #{MAKE} clean" sh "bundle package" # Avoid repeated downloads of gems by using gem files from the host.
end
sh "bundle package" # Avoid repeated downloads of gems by using gem files from the host.
RakeCompilerDock.sh "bundle --local && RUBY_CC_VERSION=#{RUBY_CC_VERSION} rake cross native gem" RakeCompilerDock.sh "bundle --local && RUBY_CC_VERSION=#{RUBY_CC_VERSION} rake cross native gem"
end end
spec = Gem::Specification.load("rbnacl-libsodium.gemspec") spec = Gem::Specification.load("rbnacl-libsodium.gemspec")
PLATFORMS = ['x86-mingw32', 'x64-mingw32'] PLATFORMS = ["x86-mingw32", "x64-mingw32"].freeze
Rake::ExtensionTask.new("fake_ext", spec) do |ext| Rake::ExtensionTask.new("fake_ext", spec) do |ext|
ext.ext_dir = 'ext/rbnacl' ext.ext_dir = "ext/rbnacl"
ext.cross_compile = true ext.cross_compile = true
ext.cross_platform = PLATFORMS ext.cross_platform = PLATFORMS
ext.cross_config_options << { ext.cross_config_options << {
'x86-mingw32' => '--with-host=i686-w64-mingw32', "x86-mingw32" => "--with-host=i686-w64-mingw32",
'x64-mingw32' => '--with-host=x86_64-w64-mingw32' "x64-mingw32" => "--with-host=x86_64-w64-mingw32"
} }
ext.cross_compiling do |gem_spec| ext.cross_compiling do |gem_spec|
gem_spec.files.reject! { |f| /lib\/fake_ext\.so\Z/ =~ f } gem_spec.files.reject! { |f| %r{lib\/fake_ext\.so\Z} =~ f }
stage_path = "#{ext.tmp_dir}/#{gem_spec.platform}/stage" stage_path = "#{ext.tmp_dir}/#{gem_spec.platform}/stage"
gem_spec.files += Dir["#{stage_path}/vendor/libsodium/dist/**/*"].map do |stage| gem_spec.files += Dir["#{stage_path}/vendor/libsodium/dist/**/*"].map do |stage|
gem_path = stage.sub(stage_path + "/", "") gem_path = stage.sub(stage_path + "/", "")
...@@ -46,7 +47,5 @@ end ...@@ -46,7 +47,5 @@ end
PLATFORMS.each do |platf| PLATFORMS.each do |platf|
copy_task = "copy:fake_ext:#{platf}:#{RUBY_CC_VERSION}" copy_task = "copy:fake_ext:#{platf}:#{RUBY_CC_VERSION}"
if Rake::Task.task_defined?(copy_task) Rake::Task[copy_task].clear_actions if Rake::Task.task_defined?(copy_task)
Rake::Task[copy_task].clear_actions
end
end end
require 'mkmf' # frozen_string_literal: true
require "mkmf"
def sys(cmd) def sys(cmd)
puts " -- #{cmd}" puts " -- #{cmd}"
unless ret = system(cmd) ret = system(cmd)
raise "ERROR: '#{cmd}' failed" raise "ERROR: '#{cmd}' failed" unless ret
end
ret ret
end end
...@@ -17,20 +18,18 @@ clean: ...@@ -17,20 +18,18 @@ clean:
MAKEFILE MAKEFILE
HOST = arg_config("--host") HOST = arg_config("--host")
OPTIONS = [] OPTIONS = [].freeze
if HOST OPTIONS << "--host=#{HOST}" if HOST
OPTIONS << "--host=#{HOST}"
end
CWD = File.expand_path(File.dirname(__FILE__)) CWD = __dir__
LIBSODIUM_DIR = File.expand_path(File.join(CWD, '..', '..', 'vendor', 'libsodium')) LIBSODIUM_DIR = File.expand_path(File.join(CWD, "..", "..", "vendor", "libsodium"))
MAKE = ENV['MAKE'] || ENV['make'] || "make" MAKE = ENV["MAKE"] || ENV["make"] || "make"
if HOST DIST = if HOST
# install to the stage directory for rake-compiler # install to the stage directory for rake-compiler
DIST = File.expand_path(File.join(CWD, '..', '..', 'tmp', RUBY_PLATFORM, 'stage', 'vendor', 'libsodium', 'dist')) File.expand_path(File.join(CWD, "..", "..", "tmp", RUBY_PLATFORM, "stage", "vendor", "libsodium", "dist"))
else else
DIST = "#{LIBSODIUM_DIR}/dist" "#{LIBSODIUM_DIR}/dist".freeze
end end
Dir.chdir(LIBSODIUM_DIR) do Dir.chdir(LIBSODIUM_DIR) do
# sh is required to run configure on Windows # sh is required to run configure on Windows
......
require 'rbnacl/libsodium/version' require "rbnacl/libsodium/version"
module RbNaCl module RbNaCl
# Installer for the libsodium native library
module Libsodium module Libsodium
class << self class << self
def sodiumlib_dir def sodiumlib_dir
sodiumlib32_dir = File.expand_path('../../../vendor/libsodium/dist/lib/', __FILE__) sodiumlib32_dir = File.expand_path("../../../vendor/libsodium/dist/lib/", __FILE__)
sodiumlib64_dir = File.expand_path('../../../vendor/libsodium/dist/lib64/', __FILE__) sodiumlib64_dir = File.expand_path("../../../vendor/libsodium/dist/lib64/", __FILE__)
[sodiumlib32_dir, sodiumlib64_dir].select { |dir| Dir.exist?(dir) }.first [sodiumlib32_dir, sodiumlib64_dir].select { |dir| Dir.exist?(dir) }.first
end end
def sodiumlib_glob def sodiumlib_glob
case RUBY_DESCRIPTION case RUBY_DESCRIPTION
when /darwin/ then 'libsodium*.dylib' when /darwin/ then "libsodium*.dylib"
when /Windows|(win|mingw)32/ then '../bin/libsodium*.dll' when /Windows|(win|mingw)32/ then "../bin/libsodium*.dll"
when /openbsd/ then 'libsodium*.so.*' when /openbsd/ then "libsodium*.so.*"
else 'libsodium*.so' else "libsodium*.so"
end end
end end
end end
...@@ -23,4 +24,4 @@ module RbNaCl ...@@ -23,4 +24,4 @@ module RbNaCl
end end
end end
require 'rbnacl' require "rbnacl"
# frozen_string_literal: true
module RbNaCl module RbNaCl
module Libsodium module Libsodium
VERSION = '1.0.16' VERSION = "1.0.16".freeze
end end
end end
# coding: utf-8 # frozen_string_literal: true
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'rbnacl/libsodium/version' require "rbnacl/libsodium/version"
Gem::Specification.new do |spec| Gem::Specification.new do |spec|
spec.name = "rbnacl-libsodium" spec.name = "rbnacl-libsodium"
spec.version = RbNaCl::Libsodium::VERSION spec.version = RbNaCl::Libsodium::VERSION
spec.authors = ["Artiom Di", "Tony Arcieri"] spec.authors = ["Artiom Di", "Tony Arcieri"]
spec.date = Time.now.strftime('%Y-%m-%d')
spec.email = ["kron82@gmail.com", "bascule@gmail.com"] spec.email = ["kron82@gmail.com", "bascule@gmail.com"]
spec.summary = %q{rbnacl with bundled libsodium} spec.summary = "rbnacl with bundled libsodium"
spec.homepage = "https://github.com/crypto-rb/rbnacl-libsodium" spec.homepage = "https://github.com/cryptosphere/rbnacl-libsodium"
spec.license = "MIT" spec.license = "MIT"
spec.files = `git ls-files -z`.split("\x0") + Dir.glob("vendor/libsodium/**/*")
spec.files = `git ls-files -z`.split("\x0")
spec.files += Dir.glob("vendor/libsodium/**/*")
spec.require_paths = ["lib"] spec.require_paths = ["lib"]
spec.extensions = ["ext/rbnacl/extconf.rb"]
spec.extensions = ['ext/rbnacl/extconf.rb'] spec.required_ruby_version = ">= 2.2.6"
spec.add_runtime_dependency "rbnacl", ">= 5.0.0" spec.add_runtime_dependency "rbnacl", ">= 5.0.0"
spec.required_ruby_version = '>= 2.2.6'
spec.add_development_dependency "bundler", "~> 1.16" spec.add_development_dependency "bundler", "~> 1.16"
end end
# frozen_string_literal: true
RSpec.describe RbNaCl::Libsodium do
it "has a version number" do
expect(RbNaCl::Libsodium::VERSION).to be_a(String)
end
end
# frozen_string_literal: true
require "bundler/setup"
require "rbnacl/libsodium"
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
config.expect_with :rspec do |c|
c.syntax = :expect
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment