Last active
September 2, 2018 06:33
-
-
Save monkstone/c10626bc51787a5e8319f2c568f28eb2 to your computer and use it in GitHub Desktop.
Add arm folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: false | |
require 'yaml' | |
VERSION = '3.4'.freeze # processing version | |
HOME = ENV['HOME'] | |
# Abstract Installer class | |
class Installer | |
attr_reader :os, :sketch, :gem_root, :confd | |
def initialize(root, os) | |
@os = os | |
@gem_root = root | |
@sketch = "#{HOME}/sketchbook" if os == :linux | |
@sketch = "#{HOME}/My Documents/Processing" if os == :windows | |
@sketch = "#{HOME}/Documents/Processing" if os == :mac | |
@confd = "#{HOME}/.jruby_art" | |
end | |
# Optimistically set processing root | |
def set_processing_root | |
folder = "#{HOME}/.jruby_art" | |
Dir.mkdir(folder) unless File.exist? folder | |
path = File.join(folder, 'config.yml') | |
proot = "#{HOME}/processing-#{VERSION}" | |
proot = "/usr/local/lib/processing-#{VERSION}" if os == :arm | |
proot = "/Java/Processing-#{VERSION}" if os == :windows | |
proot = '/Applications/Processing.app/Contents/Java' if os == :mac | |
jruby = true | |
jruby = false if os == :arm | |
settings = %w[ | |
PROCESSING_ROOT JRUBY sketchbook_path template MAX_WATCH sketch_title width height | |
] | |
values = [ | |
proot, true, sketch, 'bare', 32, 'JRubyArt Static Sketch', 600, 600 | |
] | |
data = settings.zip(values).to_h | |
open(path, 'w:UTF-8') { |file| file.write(data.to_yaml) } | |
warn 'PROCESSING_ROOT set optimistically, run check to confirm' | |
end | |
def root_exist? | |
Core.check?(config['PROCESSING_ROOT']) | |
end | |
def config | |
k9config = File.join(confd, 'config.yml') | |
return '' unless File.exist? k9config | |
YAML.load_file(k9config) | |
end | |
# in place of default installer class | |
def install | |
puts 'Usage: k9 [--check | --install | --help]' | |
end | |
# Display the current version of JRubyArt. | |
def show_version | |
puts format('JRubyArt version %s', JRubyArt::VERSION) | |
puts format('Expected Processing version %s', VERSION) | |
end | |
end | |
# Configuration checker | |
class Check < Installer | |
require_relative './core' | |
def install | |
show_version | |
return super unless config | |
installed = File.exist? File.join(gem_root, 'lib/ruby/jruby-complete.jar') | |
proot = ' PROCESSING_ROOT = Not Set Correctly!!!' unless root_exist? | |
proot ||= " PROCESSING_ROOT = #{config['PROCESSING_ROOT']}" | |
sketchbook = " sketchbook_path = #{config['sketchbook_path']}" | |
template = " template = #{config['template']}" | |
java_args = " java_args = #{config['java_args']}" | |
max_watch = " MAX_WATCH = #{config['MAX_WATCH']}" | |
jruby = config.fetch('JRUBY', true) | |
puts proot | |
puts " JRUBY = #{jruby}" unless jruby.nil? | |
puts " jruby-complete installed = #{installed}" | |
puts sketchbook | |
puts template | |
puts java_args | |
puts max_watch | |
end | |
end | |
# Examples Installer | |
class UnpackSamples < Installer | |
def install | |
system "cd #{gem_root}/vendors && rake unpack_samples" | |
end | |
end | |
# JRuby-Complete installer | |
class JRubyCompleteInstall < Installer | |
def install | |
set_processing_root unless File.exist? File.join(confd, 'config.yml') | |
system "cd #{gem_root}/vendors && rake" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rbconfig' | |
# Utility to load native binaries on Java CLASSPATH | |
# HACK until jruby returns a more specific 'host_os' than 'linux' | |
class NativeFolder | |
attr_reader :os, :bit | |
LINUX_FORMAT = 'linux%s'.freeze | |
ARM32 = '-armv6hf'.freeze | |
# ARM64 = '-aarch64'.freeze | |
WIN_FORMAT = 'windows%d'.freeze | |
WIN_PATTERNS = [ | |
/bccwin/i, | |
/cygwin/i, | |
/djgpp/i, | |
/ming/i, | |
/mswin/i, | |
/wince/i | |
].freeze | |
def initialize | |
@os = RbConfig::CONFIG['host_os'].downcase | |
@bit = java.lang.System.get_property('os.arch') | |
end | |
def name | |
return 'macosx' if /darwin|mac/.match?(os) | |
if /linux/.match?(os) | |
return format(LINUX_FORMAT, '64') if /amd64/.match?(bit) | |
return format(LINUX_FORMAT, ARM32) if /arm/.match?(bit) | |
end | |
if WIN_PATTERNS.any? { |pat| pat.match?(os) } | |
return format(WINDOWS_FORMAT, '64') if /64/.match?(bit) | |
return format(WINDOWS_FORMAT, '32') if /32/.match?(bit) | |
end | |
raise 'Unsupported Architecture' | |
end | |
def extension | |
return '*.so' if /linux/.match?(os) | |
return '*.dll' if WIN_PATTERNS.any? { |pat| pat.match?(os) } | |
'*.dylib' # MacOS | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment