Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/develop' into geometry_e…
Browse files Browse the repository at this point in the history
…ditor
  • Loading branch information
macumber committed Jul 13, 2018
2 parents ff372c1 + 10b655b commit 1e6e55f
Show file tree
Hide file tree
Showing 19 changed files with 31,134 additions and 111 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
.ruby-version
.bundle
test_gems
test_fails.txt
/build/
/build_debug/
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(OpenStudioMeta)

set(CMAKE_VERSION_MAJOR 2)
set(CMAKE_VERSION_MINOR 6)
set(CMAKE_VERSION_PATCH 0)
set(CMAKE_VERSION_PATCH 1)

set(CMAKE_VERSION_BUILD "Unknown" CACHE STRING "Build number")
find_package(Git)
Expand Down
2 changes: 1 addition & 1 deletion openstudiocore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()

project(OpenStudio VERSION 2.6.0)
project(OpenStudio VERSION 2.6.1)

include(ExternalProject)
include(CPackComponent)
Expand Down
2 changes: 1 addition & 1 deletion openstudiocore/resources/model/OpenStudio.idd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!IDD_Version 2.6.0
!IDD_Version 2.6.1
! *****************************************************************************
! This file is the Input Data Dictionary (IDD) for OpenStudio Model.
!
Expand Down
33 changes: 33 additions & 0 deletions openstudiocore/src/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,36 @@ if( BUILD_PAT )
endif()



# find all tests
file(GLOB RUBY_TEST_SRC "test/test*.rb")


# add a test for each unit test
set(RUBY_TEST_REQUIRES "#include test files")
foreach(f ${RUBY_TEST_SRC})

file(READ "${f}" CONTENTS)
string(REGEX MATCHALL "def +test_([A-Za-z_0-9 ]+)" FOUND_TESTS ${CONTENTS})

foreach(HIT ${FOUND_TESTS})
string(REGEX REPLACE "def +test_([A-Za-z_0-9]+)" "\\1" TEST_NAME ${HIT})
string(REGEX MATCH "/?([A-Za-z_0-9 ]+)\\.rb" FILE_NAME ${f})
string(REGEX REPLACE "/?([A-Za-z_0-9 ]+)\\.rb" "\\1" FILE_NAME ${FILE_NAME})
if(BUILD_TESTING)
if(MSVC)
add_test(NAME "CLITest-${FILE_NAME}-${TEST_NAME}"
COMMAND "${CMAKE_COMMAND}" -E chdir "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>"
"$<TARGET_FILE:openstudio>" "${f}" "--name=test_${TEST_NAME}"
)
else()
add_test(NAME "CLITest-${FILE_NAME}-${TEST_NAME}"
COMMAND "${CMAKE_COMMAND}" -E chdir "${CMAKE_CURRENT_BINARY_DIR}"
"$<TARGET_FILE:openstudio>" "${f}" "--name=test_${TEST_NAME}"
)
endif()

set_tests_properties("CLITest-${FILE_NAME}-${TEST_NAME}" PROPERTIES TIMEOUT 660 )
endif()
endforeach()
endforeach()
4 changes: 3 additions & 1 deletion openstudiocore/src/cli/embedded_help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def self.preprocess_ruby_script(s)
module Kernel
# ":" is our root path to the embedded file system
# make sure it is in the ruby load path
$:.unshift(ENV['RUBYLIB']) if ENV['RUBYLIB']
if ENV['RUBYLIB']
ENV['RUBYLIB'].split(File::PATH_SEPARATOR).each {|lib| $LOAD_PATH.unshift(lib)}
end
$LOAD_PATH << ':'
$LOAD_PATH << ':/ruby/2.2.0'
$LOAD_PATH << ':/ruby/2.2.0/x86_64-darwin15'
Expand Down
258 changes: 152 additions & 106 deletions openstudiocore/src/cli/openstudio_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ def base_dir
end
end

# have to do some forward declaration and pre-require to get around autoload cycles
#module Bundler
#end

# This is the code chunk to allow for an embedded IRB shell. From Jason Roelofs, found on StackOverflow
module IRB # :nodoc:
Expand Down Expand Up @@ -365,6 +368,31 @@ def parse_main_args(main_args)
ENV['GEM_HOME'] = new_home
end

# Operate on the bundle option to set BUNDLE_GEMFILE
use_bundler = false
if main_args.include? '--bundle'
option_index = main_args.index '--bundle'
path_index = option_index + 1
gemfile = main_args[path_index]
main_args.slice! path_index
main_args.slice! main_args.index '--bundle'

$logger.info "Setting BUNDLE_GEMFILE to #{gemfile}"
ENV['BUNDLE_GEMFILE'] = gemfile
use_bundler = true
end

if main_args.include? '--bundle_path'
option_index = main_args.index '--bundle_path'
path_index = option_index + 1
bundle_path = main_args[path_index]
main_args.slice! path_index
main_args.slice! main_args.index '--bundle_path'

$logger.info "Setting BUNDLE_PATH to #{bundle_path}"
ENV['BUNDLE_PATH'] = bundle_path
end

Gem.paths.path << ':/ruby/2.2.0/gems/'
Gem.paths.path << ':/ruby/2.2.0/bundler/gems/'

Expand Down Expand Up @@ -404,122 +432,138 @@ def parse_main_args(main_args)
# EmbeddedScripting not available
end

# activate bundler
#Gem::Specification.each do |spec|
# if spec.gem_dir.chars.first == ':'
# if spec.name == 'bundler'
# # DLM would like to have bundler support in the cli
# #spec.activate
#
# # DLM: for now remove this gem
# Gem::Specification.remove_spec(spec)
# end
# end
#end

# require bundler
# have to do some forward declaration and pre-require to get around autoload cycles
#module Bundler
#end
#require 'bundler/gem_helpers'
#require 'bundler/errors'
#require 'bundler/plugin'
#require 'bundler/source'
#require 'bundler/definition'
#require 'bundler/dsl'
#require 'bundler/dsl'
#require 'bundler'

#begin
# # activate bundled gems
# # bundler will look in:
# # 1) ENV["BUNDLE_GEMFILE"]
# # 2) find_file("Gemfile", "gems.rb")
# Bundler.setup
# Bundler.require
#rescue Bundler::BundlerError => e
# puts "#{e.message}"
# #puts e.backtrace.join("\n")
# if e.is_a?(Bundler::GemNotFound)
# puts "Run `bundle install` to install missing gems."
# elsif e.is_a?(Bundler::ProductionError)
#
# else
#
# end
# exit e.status_code
#end

# DLM: test code, useful for testing from command line using system ruby
#Gem::Specification.each do |spec|
# if /openstudio/.match(spec.name)
# original_embedded_gems[spec.name] = spec
# end
#end

# find final set of embedded gems that are also found on disk with equal or higher version but compatible major version
final_embedded_gems = original_embedded_gems.clone
# activate or remove bundler
Gem::Specification.each do |spec|
current_embedded_gem = final_embedded_gems[spec.name]

# not an embedded gem
next if current_embedded_gem.nil?

if spec.version > current_embedded_gem.version
# only allow higher versions with compatible major version
if spec.version.to_s.split('.').first == current_embedded_gem.version.to_s.split('.').first
$logger.debug "Found system gem #{spec.name} #{spec.version}, overrides embedded gem"
final_embedded_gems[spec.name] = spec
if spec.gem_dir.chars.first == ':'
if spec.name == 'bundler'
if use_bundler
spec.activate
else
# DLM: don't remove, used by Resolver
#Gem::Specification.remove_spec(spec)
end
end
end
end

# get a list of all the embedded gems and their dependencies
dependencies = []
final_embedded_gems.each_value do |spec|
#$logger.debug "Accumulating dependencies for #{spec.name} #{spec.version}"
dependencies << Gem::Dependency.new(spec.name)
dependencies.concat(spec.runtime_dependencies)
end
#dependencies.each {|d| $logger.debug "Found dependency #{d}"}

# resolve dependencies
activation_errors = false
original_load_path = $:.clone
resolver = Gem::Resolver.for_current_gems(dependencies)
resolver.resolve.each do |request|
do_activate = true
spec = request.spec

# check if this is one of our embedded gems
if final_embedded_gems[spec.name]

# check if gem can be loaded from RUBYLIB, this supports developer use case
original_load_path.each do |lp|
if File.exists?(File.join(lp, spec.name)) || File.exists?(File.join(lp, spec.name + '.rb')) || File.exists?(File.join(lp, spec.name + '.so'))
$logger.debug "Found #{spec.name} in '#{lp}', overrides gem #{spec.spec_file}"
Gem::Specification.remove_spec(spec)
do_activate = false
break
if use_bundler

# require bundler
# have to do some forward declaration and pre-require to get around autoload cycles
require 'bundler/errors'
#require 'bundler/environment_preserver'
require 'bundler/plugin'
#require 'bundler/rubygems_ext'
require 'bundler/rubygems_integration'
require 'bundler/version'
require 'bundler/ruby_version'
#require 'bundler/constants'
#require 'bundler/current_ruby'
require 'bundler/gem_helpers'
#require 'bundler/plugin'
require 'bundler/source'
require 'bundler/definition'
require 'bundler/dsl'
require 'bundler'

begin
# activate bundled gems
# bundler will look in:
# 1) ENV["BUNDLE_GEMFILE"]
# 2) find_file("Gemfile", "gems.rb")
#require 'bundler/setup'

Bundler.setup
#Bundler.require
rescue Bundler::BundlerError => e
puts "#{e.message}"
#puts e.backtrace.join("\n")
if e.is_a?(Bundler::GemNotFound)
puts "GemNotFound, Run `bundle install` to install missing gems."
exit e.status_code
elsif e.is_a?(Bundler::ProductionError)
puts "ProductionError, Run `bundle install` to install missing gems."
exit e.status_code
else
# no Gemfile,
end
end

else
# not using_bundler

# DLM: test code, useful for testing from command line using system ruby
#Gem::Specification.each do |spec|
# if /openstudio/.match(spec.name)
# original_embedded_gems[spec.name] = spec
# end
#end

# find final set of embedded gems that are also found on disk with equal or higher version but compatible major version
final_embedded_gems = original_embedded_gems.clone
Gem::Specification.each do |spec|
current_embedded_gem = final_embedded_gems[spec.name]

# not an embedded gem
next if current_embedded_gem.nil?

if spec.version > current_embedded_gem.version
# only allow higher versions with compatible major version
if spec.version.to_s.split('.').first == current_embedded_gem.version.to_s.split('.').first
$logger.debug "Found system gem #{spec.name} #{spec.version}, overrides embedded gem"
final_embedded_gems[spec.name] = spec
end
end
end

if do_activate
$logger.debug "Activating gem #{spec.spec_file}"
begin
spec.activate
rescue Gem::LoadError
$logger.error "Error activating gem #{spec.spec_file}"
# get a list of all the embedded gems and their dependencies
dependencies = []
final_embedded_gems.each_value do |spec|
#$logger.debug "Accumulating dependencies for #{spec.name} #{spec.version}"
dependencies << Gem::Dependency.new(spec.name)
dependencies.concat(spec.runtime_dependencies)
end
#dependencies.each {|d| $logger.debug "Found dependency #{d}"}

# resolve dependencies
activation_errors = false
original_load_path = $:.clone
resolver = Gem::Resolver.for_current_gems(dependencies)
resolver.resolve.each do |request|
do_activate = true
spec = request.spec

# check if this is one of our embedded gems
if final_embedded_gems[spec.name]

# check if gem can be loaded from RUBYLIB, this supports developer use case
original_load_path.each do |lp|
if File.exists?(File.join(lp, spec.name)) || File.exists?(File.join(lp, spec.name + '.rb')) || File.exists?(File.join(lp, spec.name + '.so'))
$logger.debug "Found #{spec.name} in '#{lp}', overrides gem #{spec.spec_file}"
Gem::Specification.remove_spec(spec)
do_activate = false
break
end
end
end
end

end

if activation_errors
return false
end

if do_activate
$logger.debug "Activating gem #{spec.spec_file}"
begin
spec.activate
rescue Gem::LoadError
$logger.error "Error activating gem #{spec.spec_file}"
end
end

end

if activation_errors
return false
end

end # use_bundler

# Handle -e commands
remove_indices = []
$eval_cmds = []
Expand Down Expand Up @@ -661,7 +705,7 @@ def help(list_all=false, quiet=false)
'--no-ssl',
'-i', '--include',
'-e', '--execute',
'--gem_path', '--gem_home']
'--gem_path', '--gem_home', '--bundle', '--bundle_path']
command_list.each do |key, data|
# Skip non-primary commands. These only show up in extended
# help output.
Expand All @@ -681,6 +725,8 @@ def help(list_all=false, quiet=false)
o.on('-e', '--execute CMD', 'Execute one line of script (may be used more than once). Returns after executing commands.')
o.on('--gem_path DIR', 'Add additional directory to add to front of GEM_PATH environment variable (may be used more than once)')
o.on('--gem_home DIR', 'Set GEM_HOME environment variable')
o.on('--bundle GEMFILE', 'Use bundler for GEMFILE')
o.on('--bundle_path BUNDLE_PATH', 'Use bundler installed gems in BUNDLE_PATH')
o.separator ''
o.separator 'Common commands:'

Expand Down
4 changes: 4 additions & 0 deletions openstudiocore/src/cli/test/bundle/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'http://rubygems.org'

gem 'openstudio-standards', '0.2.0'
gem 'tilt', '2.0.8'
Loading

0 comments on commit 1e6e55f

Please sign in to comment.