Skip to content
Permalink
Browse files

Prefer *-java gems on JRuby

  • Loading branch information...
matthewd committed Oct 12, 2019
1 parent 29b3965 commit 99ef5986a3ff1148a6739fe0e3bf8d1c9281caab
@@ -27,5 +27,5 @@ steps:
- <<: *rake
name: "JRuby"
env:
RUBY_IMAGE: "jruby:latest"
RUBY_IMAGE: "jruby:9.2.7.0" # https://github.com/jruby/jruby/issues/5863
soft_fail: true
@@ -32,6 +32,7 @@ GEM
hashdiff

PLATFORMS
java
ruby

DEPENDENCIES
@@ -25,6 +25,7 @@ FIXTURE_GEMS = [
["rack-test", "0.6.3"],
["fast_blank", "1.0.0"],
["atomic", "1.1.16"],
["atomic", "1.1.16-java"],
["rainbow", "2.2.2"],
["rake", "12.3.2"],
["pub_grub", "0.5.0"],
@@ -41,10 +42,16 @@ FIXTURE_GEMS = [
MIMED_GEMS = [
"pub_grub",

"activerecord-jdbcpostgresql-adapter",
"activerecord-jdbcsqlite3-adapter",
"foreman",
"gruff",
"pg",
"quiet_assets",
"rails",
"rspec-rails",
"sqlite3",
"tzinfo-data",
]

task :fixtures do
@@ -26,8 +26,8 @@ def usage
end

# `gel install`
loader = Gel::LockLoader.new(Gel::ResolvedGemSet.load("Gemfile.lock"))
loader.activate(nil, Gel::Environment.store.inner, install: true, output: $stderr)
loader = Gel::LockLoader.new(Gel::ResolvedGemSet.load("Gemfile.lock"), Gel::GemfileParser.parse(File.read("Gemfile"), "Gemfile", 1))
loader.activate(Gel::Environment, Gel::Environment.store.inner, install: true, output: $stderr)

else
usage
@@ -11,6 +11,7 @@
module Gem
Version = Gel::Support::GemVersion
Requirement = Gel::Support::GemRequirement
Platform = Gel::Support::GemPlatform

class Dependency
attr_reader :name
@@ -27,6 +28,10 @@ def initialize(name, requirement, type)
LoadError = Class.new(::LoadError)

class Specification
class << self
include Enumerable
end

def self.find_by_name(name, *requirements)
if g = Gel::Environment.find_gem(name, *requirements)
new(g)
@@ -96,6 +101,10 @@ def self.ruby
RbConfig.ruby
end

def self.platforms
Gel::Support::GemPlatform.platforms
end

def self.win_platform?
false
end
@@ -146,8 +155,8 @@ def self.activate_bin_path(gem_name, bin_name, version = nil)

if g = Gel::Environment.activated_gems[gem_name]
Gel::Environment.gem g.name, version if version
elsif g = Gel::Environment.find_gem(gem_name, *version) do |g|
g.executables.include?(bin_name)
elsif g = Gel::Environment.find_gem(gem_name, *version) do |gg|
gg.executables.include?(bin_name)
end

Gel::Environment.gem g.name, g.version
@@ -12,11 +12,17 @@ class << self
end
self.gemfile = nil
@active_lockfile = false
@architectures = ["ruby"].freeze
@architectures = [defined?(org.jruby.Ruby) ? "java" : nil, "ruby"].compact.freeze

GEMFILE_PLATFORMS = begin
v = RbConfig::CONFIG["ruby_version"].split(".")[0..1].inject(:+)
["ruby", "ruby_#{v}", "mri", "mri_#{v}"]

# FIXME: This isn't the right condition
if defined?(org.jruby.Ruby)
["jruby", "jruby_#{v}", "java", "java_#{v}"]
else
["ruby", "ruby_#{v}", "mri", "mri_#{v}"]
end
end

def self.platform?(platform)
@@ -137,16 +143,19 @@ def self.auto_install_pub_grub!
end
end

def self.solve_for_gemfile(store: store(), output: nil, gemfile: Gel::Environment.load_gemfile, lockfile: Gel::Environment.lockfile_name, catalog_options: {}, solve: true, preference_strategy: nil)
def self.solve_for_gemfile(store: store(), output: nil, gemfile: Gel::Environment.load_gemfile, lockfile: Gel::Environment.lockfile_name, catalog_options: {}, solve: true, preference_strategy: nil, platforms: nil)
output = nil if $DEBUG

target_platforms = Array(platforms)

if lockfile && File.exist?(lockfile)
require_relative "resolved_gem_set"
gem_set = Gel::ResolvedGemSet.load(lockfile)
target_platforms = gem_set.platforms
target_platforms |= gem_set.platforms if gem_set.platforms
end

target_platforms ||= ["ruby"]
# Should we just _always_ include our own architecture, maybe?
target_platforms |= [architectures.first] if target_platforms.empty?

require_relative "catalog"
all_sources = (gemfile.sources | gemfile.gems.flat_map { |_, _, o| o[:source] }).compact
@@ -88,6 +88,13 @@ def ruby(*versions, engine: nil, engine_version: nil)
end

def gem(name, *requirements, **options)
aliases = GemfileContent::OPTION_ALIASES
options.keys.each do |key|
if original = aliases[key]
raise "Duplicate key #{key.inspect} == #{original.inspect}" if options.key?(original)
options[original] = options.delete(key)
end
end
options = @result.flatten(options, @stack)
@result.add_gem(name, requirements, options)
end
@@ -104,8 +111,8 @@ def gemspec(name: nil, path: ".", development_group: :development)
else
spec = gemspecs[0]
gem spec.name, path: path
spec.development_dependencies.each do |name, constraints|
gem name, constraints, group: development_group
spec.development_dependencies.each do |dep_name, constraints|
gem dep_name, constraints, group: development_group
end
end
end
@@ -133,6 +140,10 @@ def platforms(*names)
end

class GemfileContent
OPTION_ALIASES = {
platform: :platforms,
}

attr_reader :filename

attr_reader :sources
@@ -61,7 +61,12 @@ def self.parse(content, filename, lineno = 1, root: File.dirname(filename), isol
in_read, in_write = IO.pipe
out_read, out_write = IO.pipe

pid = spawn({ "RUBYLIB" => Gel::Environment.modified_rubylib, "GEL_GEMFILE" => "", "GEL_LOCKFILE" => "" },
pid = spawn({
"RUBYLIB" => Gel::Environment.modified_rubylib,
"GEL_GEMFILE" => "",
"GEL_LOCKFILE" => "",
"GEL_DISABLED" => "1", # https://github.com/jruby/jruby/pull/5907
},
RbConfig.ruby,
"-r", File.expand_path("compatibility", __dir__),
"-r", File.expand_path("gemspec_parser", __dir__),
@@ -2,6 +2,8 @@

require_relative "resolved_gem_set"

require_relative "support/gem_platform"

class Gel::LockLoader
attr_reader :gemfile

@@ -41,19 +43,28 @@ def activate(env, base_store, install: false, output: nil)
end
end

# For each gem name, we now decide which of the known variants we
# will attempt to use *if* we end up trying to load this gem. This
# *will* encounter gems that have no supported variant, but we
# assume those will never be requested.
platform_gems = {}
local_platform = Gel::Support::GemPlatform.local
@gem_set.gems.each do |name, resolved_gems|
resolved_gems.each do |resolved_gem|
next if env && !env.platform?(resolved_gem.platform)
fallback = resolved_gems.find { |rg| rg.platform.nil? }
best_choice = resolved_gems.find { |rg| local_platform =~ rg.platform } || fallback

installer.known_dependencies name => resolved_gem.deps.map(&:first) if installer
if best_choice
platform_gems[name] = best_choice
installer.known_dependencies name => best_choice.deps.map(&:first) if installer
end
end

walk = lambda do |name|
filtered_gems[name] = true

@gem_set.gems[name]&.each do |resolved_gem|
if resolved_gem = platform_gems[name]
next if env && !env.platform?(resolved_gem.platform)

filtered_gems[name] = true

resolved_gem.deps.map(&:first).each do |dep_name|
walk[dep_name] unless filtered_gems[dep_name]
end
@@ -68,38 +79,34 @@ def activate(env, base_store, install: false, output: nil)
Gel::WorkPool.new(8) do |work_pool|
git_depot = Gel::GitDepot.new(base_store)

@gem_set.gems.each do |name, resolved_gems|
platform_gems.each do |name, resolved_gem|
next unless filtered_gems[name]

resolved_gems.each do |resolved_gem|
next if env && !env.platform?(resolved_gem.platform)
if resolved_gem.type == :gem
if installer && !base_store.gem?(name, resolved_gem.version, resolved_gem.platform)
require_relative "catalog"
catalogs = @gem_set.server_catalogs || resolved_gem.body["remote"].map { |r| Gel::Catalog.new(r, work_pool: work_pool) }
installer.install_gem(catalogs, name, resolved_gem.platform ? "#{resolved_gem.version}-#{resolved_gem.platform}" : resolved_gem.version)
end

if resolved_gem.type == :gem
if installer && !base_store.gem?(name, resolved_gem.version, resolved_gem.platform)
require_relative "catalog"
catalogs = @gem_set.server_catalogs || resolved_gem.body["remote"].map { |r| Gel::Catalog.new(r, work_pool: work_pool) }
installer.install_gem(catalogs, name, resolved_gem.platform ? "#{resolved_gem.version}-#{resolved_gem.platform}" : resolved_gem.version)
end
locks[name] = resolved_gem.version.to_s
else
if resolved_gem.type == :git
remote = resolved_gem.body["remote"].first
revision = resolved_gem.body["revision"].first

locks[name] = resolved_gem.version.to_s
else
if resolved_gem.type == :git
remote = resolved_gem.body["remote"].first
revision = resolved_gem.body["revision"].first

dir = git_depot.git_path(remote, revision)
if installer && !Dir.exist?(dir)
installer.load_git_gem(remote, revision, name)

locks[name] = -> { Gel::DirectGem.new(dir, name, resolved_gem.version) }
next
end
else
dir = File.expand_path(resolved_gem.body["remote"].first, File.dirname(@gem_set.filename))
end
dir = git_depot.git_path(remote, revision)
if installer && !Dir.exist?(dir)
installer.load_git_gem(remote, revision, name)

locks[name] = Gel::DirectGem.new(dir, name, resolved_gem.version)
locks[name] = -> { Gel::DirectGem.new(dir, name, resolved_gem.version) }
next
end
else
dir = File.expand_path(resolved_gem.body["remote"].first, File.dirname(@gem_set.filename))
end

locks[name] = Gel::DirectGem.new(dir, name, resolved_gem.version)
end
end

@@ -10,12 +10,21 @@ class Gel::MultiStore
attr_reader :monitor

def initialize(root, stores)
@root = File.realpath(File.expand_path(root)) if root
@root = root && File.realpath(File.expand_path(root))
@stores = stores

@monitor = Monitor.new
end

def marshal_dump
[@root, @stores]
end

def marshal_load(v)
@root, @stores = v
@monitor = Monitor.new
end

def stub_set
@stub_set ||= Gel::StubSet.new(@root)
end
@@ -8,8 +8,6 @@ def initialize(gemfile:, catalog_set:, platforms:)
@catalog_set = catalog_set
@platforms = platforms

raise "NullSolver can't process multiple platforms" if platforms.size > 1

@platform = @platforms.first

@packages = Hash.new { |h, k| h[k] = NullPackage.new(k, @platform) }
@@ -24,6 +24,10 @@ def architecture
@inner.architecture
end

def platform
@inner.platform
end

def bindir
@inner.bindir
end
@@ -91,7 +95,7 @@ def find(klass)
end

class Gem_Specification
attr_accessor :architecture, :bindir, :executables, :name, :require_paths, :specification_version, :version, :dependencies, :extensions
attr_accessor :architecture, :bindir, :executables, :name, :platform, :require_paths, :specification_version, :version, :dependencies, :extensions
end
class Gem_Dependency
attr_accessor :name, :requirement, :type, :version_requirements
@@ -30,7 +30,13 @@ def initialize(spec, store)
@root_store = store

if store.is_a?(Gel::MultiStore)
store = store[spec.architecture, spec.extensions.any?]
platform_parts = []
platform_parts << spec.platform if spec.platform && spec.platform != "ruby"
platform_parts << spec.architecture if spec.architecture

platform_dir = platform_parts.join("-") unless platform_parts.empty?

store = store[platform_dir, spec.extensions.any?]
end
@store = store

@@ -170,7 +170,7 @@ def dump

if platforms && !platforms.empty?
lock_content << "PLATFORMS"
platforms.each do |platform|
platforms.sort.each do |platform|
lock_content << " #{platform}"
end
lock_content << ""
@@ -22,6 +22,6 @@

Gel::Environment.open(Gel::LockedStore.new(store))

if ENV["GEL_LOCKFILE"] && ENV["GEL_LOCKFILE"] != ""
if ENV["GEL_LOCKFILE"] && ENV["GEL_LOCKFILE"] != "" && !ENV["GEL_DISABLED"]
Gel::Environment.activate(output: $stderr)
end
@@ -15,6 +15,14 @@ def initialize(root)
@monitor = Monitor.new
end

def marshal_dump
@root
end

def marshal_load(v)
initialize(v)
end

def stub_set
@stub_set ||= Gel::StubSet.new(@root)
end

0 comments on commit 99ef598

Please sign in to comment.
You can’t perform that action at this time.