Skip to content
This repository has been archived by the owner on Nov 9, 2018. It is now read-only.

Commit

Permalink
Add RuboCop
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Jan 4, 2018
1 parent 5c25459 commit fb8bfb6
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 58 deletions.
45 changes: 45 additions & 0 deletions .rubocop.yml
@@ -0,0 +1,45 @@
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
3 changes: 2 additions & 1 deletion Gemfile
Expand Up @@ -8,5 +8,6 @@ group :development, :test do
gem "rake", ">= 10"
gem "rake-compiler", "~> 1.0"
gem "rake-compiler-dock", "~> 0.6"
gem "rspec", "~> 3"
gem "rspec", "~> 3.7"
gem "rubocop", "0.52.1"
end
35 changes: 17 additions & 18 deletions Rakefile
@@ -1,37 +1,38 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require 'rake/extensiontask'
require "rake/extensiontask"

RSpec::Core::RakeTask.new

task default: :spec
require "rubocop/rake_task"
RuboCop::RakeTask.new

MAKE = ENV['MAKE'] || ENV['make'] || "make"
RUBY_CC_VERSION = ENV['RUBY_CC_VERSION'] || '2.3.0'
task default: %w[spec rubocop]

MAKE = ENV["MAKE"] || ENV["make"] || "make"
RUBY_CC_VERSION = ENV["RUBY_CC_VERSION"] || "2.3.0"

desc "Build Windows binary packages"
task 'gem:windows' do
require 'rake_compiler_dock'
if File.exist? "vendor/libsodium/Makefile"
RakeCompilerDock.sh "cd vendor/libsodium && #{MAKE} clean"
end
sh "bundle package" # Avoid repeated downloads of gems by using gem files from the host.
task "gem:windows" do
require "rake_compiler_dock"
RakeCompilerDock.sh "cd vendor/libsodium && #{MAKE} clean" if File.exist? "vendor/libsodium/Makefile"
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"
end

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|
ext.ext_dir = 'ext/rbnacl'
ext.ext_dir = "ext/rbnacl"
ext.cross_compile = true
ext.cross_platform = PLATFORMS
ext.cross_config_options << {
'x86-mingw32' => '--with-host=i686-w64-mingw32',
'x64-mingw32' => '--with-host=x86_64-w64-mingw32'
"x86-mingw32" => "--with-host=i686-w64-mingw32",
"x64-mingw32" => "--with-host=x86_64-w64-mingw32"
}
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"
gem_spec.files += Dir["#{stage_path}/vendor/libsodium/dist/**/*"].map do |stage|
gem_path = stage.sub(stage_path + "/", "")
Expand All @@ -46,7 +47,5 @@ end

PLATFORMS.each do |platf|
copy_task = "copy:fake_ext:#{platf}:#{RUBY_CC_VERSION}"
if Rake::Task.task_defined?(copy_task)
Rake::Task[copy_task].clear_actions
end
Rake::Task[copy_task].clear_actions if Rake::Task.task_defined?(copy_task)
end
33 changes: 16 additions & 17 deletions ext/rbnacl/extconf.rb
@@ -1,10 +1,11 @@
require 'mkmf'
# frozen_string_literal: true

require "mkmf"

def sys(cmd)
puts " -- #{cmd}"
unless ret = system(cmd)
raise "ERROR: '#{cmd}' failed"
end
ret = system(cmd)
raise "ERROR: '#{cmd}' failed" unless ret
ret
end

Expand All @@ -17,20 +18,18 @@ def sys(cmd)
MAKEFILE

HOST = arg_config("--host")
OPTIONS = []
if HOST
OPTIONS << "--host=#{HOST}"
end
OPTIONS = [].freeze
OPTIONS << "--host=#{HOST}" if HOST

CWD = File.expand_path(File.dirname(__FILE__))
LIBSODIUM_DIR = File.expand_path(File.join(CWD, '..', '..', 'vendor', 'libsodium'))
MAKE = ENV['MAKE'] || ENV['make'] || "make"
if HOST
# install to the stage directory for rake-compiler
DIST = File.expand_path(File.join(CWD, '..', '..', 'tmp', RUBY_PLATFORM, 'stage', 'vendor', 'libsodium', 'dist'))
else
DIST = "#{LIBSODIUM_DIR}/dist"
end
CWD = __dir__
LIBSODIUM_DIR = File.expand_path(File.join(CWD, "..", "..", "vendor", "libsodium"))
MAKE = ENV["MAKE"] || ENV["make"] || "make"
DIST = if HOST
# install to the stage directory for rake-compiler
File.expand_path(File.join(CWD, "..", "..", "tmp", RUBY_PLATFORM, "stage", "vendor", "libsodium", "dist"))
else
"#{LIBSODIUM_DIR}/dist".freeze
end

Dir.chdir(LIBSODIUM_DIR) do
# sh is required to run configure on Windows
Expand Down
17 changes: 9 additions & 8 deletions lib/rbnacl/libsodium.rb
@@ -1,20 +1,21 @@
require 'rbnacl/libsodium/version'
require "rbnacl/libsodium/version"

module RbNaCl
# Installer for the libsodium native library
module Libsodium
class << self
def sodiumlib_dir
sodiumlib32_dir = File.expand_path('../../../vendor/libsodium/dist/lib/', __FILE__)
sodiumlib64_dir = File.expand_path('../../../vendor/libsodium/dist/lib64/', __FILE__)
sodiumlib32_dir = File.expand_path("../../../vendor/libsodium/dist/lib/", __FILE__)
sodiumlib64_dir = File.expand_path("../../../vendor/libsodium/dist/lib64/", __FILE__)
[sodiumlib32_dir, sodiumlib64_dir].select { |dir| Dir.exist?(dir) }.first
end

def sodiumlib_glob
case RUBY_DESCRIPTION
when /darwin/ then 'libsodium*.dylib'
when /Windows|(win|mingw)32/ then '../bin/libsodium*.dll'
when /openbsd/ then 'libsodium*.so.*'
else 'libsodium*.so'
when /darwin/ then "libsodium*.dylib"
when /Windows|(win|mingw)32/ then "../bin/libsodium*.dll"
when /openbsd/ then "libsodium*.so.*"
else "libsodium*.so"
end
end
end
Expand All @@ -23,4 +24,4 @@ def sodiumlib_glob
end
end

require 'rbnacl'
require "rbnacl"
4 changes: 3 additions & 1 deletion lib/rbnacl/libsodium/version.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true

module RbNaCl
module Libsodium
VERSION = '1.0.16'
VERSION = "1.0.16".freeze
end
end
22 changes: 9 additions & 13 deletions rbnacl-libsodium.gemspec
@@ -1,26 +1,22 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
# frozen_string_literal: true

lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'rbnacl/libsodium/version'
require "rbnacl/libsodium/version"

Gem::Specification.new do |spec|
spec.name = "rbnacl-libsodium"
spec.version = RbNaCl::Libsodium::VERSION
spec.authors = ["Artiom Di", "Tony Arcieri"]
spec.date = Time.now.strftime('%Y-%m-%d')
spec.email = ["kron82@gmail.com", "bascule@gmail.com"]
spec.summary = %q{rbnacl with bundled libsodium}
spec.homepage = "https://github.com/crypto-rb/rbnacl-libsodium"
spec.summary = "rbnacl with bundled libsodium"
spec.homepage = "https://github.com/cryptosphere/rbnacl-libsodium"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0")
spec.files += Dir.glob("vendor/libsodium/**/*")
spec.files = `git ls-files -z`.split("\x0") + Dir.glob("vendor/libsodium/**/*")
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.required_ruby_version = '>= 2.2.6'

spec.add_development_dependency "bundler", "~> 1.16"
end
7 changes: 7 additions & 0 deletions spec/rbnacl/libsodium_spec.rb
@@ -0,0 +1,7 @@
# 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
16 changes: 16 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,16 @@
# 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

0 comments on commit fb8bfb6

Please sign in to comment.