Skip to content

Commit

Permalink
Load standards into CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
macumber committed Aug 6, 2016
1 parent c45a4be commit 8d37c9a
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea
.ruby-version
.bundle
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 @@ -297,7 +297,7 @@ if(BUILD_OPENSTUDIO_GEMS)
else()
add_custom_target(openstudio-gems ALL
rm -rf ${OPENSTUDIO_GEMS_DIR}
COMMAND bundle install --path=${OPENSTUDIO_GEMS_DIR}
COMMAND bundle install --without=test --path=${OPENSTUDIO_GEMS_DIR}
COMMAND rm -rf "${OPENSTUDIO_GEMS_DIR}/ruby/2.0.0/cache"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/dependencies/ruby/"
DEPENDS "${CMAKE_SOURCE_DIR}/dependencies/ruby/Gemfile" "${CMAKE_SOURCE_DIR}/dependencies/ruby/build_openstudio_gems.bat")
Expand Down
5 changes: 3 additions & 2 deletions dependencies/ruby/Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# gems in this file are packaged into openstudio.exe
# gems listed here should not have binary components
# gems listed here must be able to read resource files from the embedded files location
# need to adjust hard coded paths in embedded_help.rb

gem 'openstudio-workflow', :github => 'NREL/OpenStudio-workflow-gem', :ref => '37f56f9f54f3a9bd030820b47e77d5e72c71c64f'
gem 'openstudio-standards', :github => 'NREL/openstudio-standards', :ref => 'f960bc5cd123de066e116d170dfa85574c939fa6'
gem 'openstudio-workflow', :github => 'NREL/OpenStudio-workflow-gem', :ref => '6f5f0b797caa87e4e7e2c07a8cc6c36ae3d8300b'
gem 'openstudio-standards', :github => 'NREL/openstudio-standards', :ref => 'c65b0ec070d301de89c39b2fbe704376c76b7f1e'

51 changes: 46 additions & 5 deletions dependencies/ruby/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,61 @@
GIT
remote: git://github.com/NREL/OpenStudio-workflow-gem.git
revision: c2f6ed3b51515b512378c7a913537b43851e8229
ref: c2f6ed3b51515b512378c7a913537b43851e8229
revision: 6f5f0b797caa87e4e7e2c07a8cc6c36ae3d8300b
ref: 6f5f0b797caa87e4e7e2c07a8cc6c36ae3d8300b
specs:
openstudio-workflow (1.0.0.alpha.0)
openstudio-workflow (1.0.0.rc1)
colored (~> 1.2)
facter (>= 2.0)
multi_json (~> 1.10)
rubyXL (~> 3.3)
rubyzip (~> 1.2)

GIT
remote: git://github.com/NREL/openstudio-standards.git
revision: 0712d0dcab9b0b6d9699125bc3ab425a211f475b
branch: master
revision: c65b0ec070d301de89c39b2fbe704376c76b7f1e
ref: c65b0ec070d301de89c39b2fbe704376c76b7f1e
specs:
openstudio-standards (0.1.4)

GEM
remote: http://rubygems.org/
specs:
CFPropertyList (2.2.8)
colored (1.2)
facter (2.4.6)
CFPropertyList (~> 2.2.6)
facter (2.4.6-x64-mingw32)
ffi (~> 1.9.5)
win32-dir (~> 0.4.8)
win32-security (~> 0.2.5)
facter (2.4.6-x86-mingw32)
ffi (~> 1.9.5)
win32-dir (~> 0.4.8)
win32-security (~> 0.2.5)
win32console (~> 1.3.2)
ffi (1.9.14-x64-mingw32)
ffi (1.9.14-x86-mingw32)
mini_portile2 (2.1.0)
multi_json (1.12.1)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
nokogiri (1.6.8-x64-mingw32)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
nokogiri (1.6.8-x86-mingw32)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
pkg-config (1.1.7)
rubyXL (3.3.21)
nokogiri (>= 1.4.4)
rubyzip (>= 1.1.6)
rubyzip (1.2.0)
win32-dir (0.4.9)
ffi (>= 1.0.0)
win32-security (0.2.5)
ffi
win32console (1.3.2-x86-mingw32)

PLATFORMS
ruby
Expand Down
4 changes: 2 additions & 2 deletions dependencies/ruby/build_openstudio_gems.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
REM first argument is location to install gems
set PATH=%PATH%;C:\Program Files\Git\cmd
rmdir /S /Q "%1"
bundle install --path="%1"
rmdir /S /Q "%1/ruby/2.0.0/cache"
call bundle install --without=test --path="%1"
rmdir /S /Q "%1/ruby/2.0.0/cache"
2 changes: 1 addition & 1 deletion openstudiocore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ endif()
# openstudio gems

set(OPENSTUDIO_GEMS_ZIP_FILENAME "openstudio-gems.tar.gz")
set(OPENSTUDIO_GEMS_ZIP_EXPECTED_MD5 "bc574f74016c5ebb6fb3e970e4370d77")
set(OPENSTUDIO_GEMS_ZIP_EXPECTED_MD5 "6ea8fdeecc7fbac93731e31da64e284e")

set(OPENSTUDIO_GEMS_ZIP_LOCAL_PATH "${CMAKE_BINARY_DIR}/${OPENSTUDIO_GEMS_ZIP_FILENAME}")
if(EXISTS "${OPENSTUDIO_GEMS_ZIP_LOCAL_PATH}")
Expand Down
9 changes: 9 additions & 0 deletions openstudiocore/src/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ endforeach()

file(GLOB_RECURSE RB_FILES FOLLOW_SYMLINKS "${CMAKE_BINARY_DIR}/openstudio-gems/ruby/2.0.0/bundler/**/*.rb")
file(GLOB_RECURSE IDF_FILES FOLLOW_SYMLINKS "${CMAKE_BINARY_DIR}/openstudio-gems/ruby/2.0.0/bundler/**/*.idf")
file(GLOB_RECURSE JSON_FILES FOLLOW_SYMLINKS "${CMAKE_BINARY_DIR}/openstudio-gems/ruby/2.0.0/bundler/**/*.json")

foreach( _FILE ${RB_FILES} )
file(RELATIVE_PATH LOCATION "${CMAKE_BINARY_DIR}/openstudio-gems" ${_FILE})
Expand All @@ -88,6 +89,12 @@ foreach( _FILE ${IDF_FILES} )
list(APPEND EMBEDDED_PATHS ${LOCATION})
endforeach()

foreach( _FILE ${JSON_FILES} )
file(RELATIVE_PATH LOCATION "${CMAKE_BINARY_DIR}/openstudio-gems" ${_FILE})
list(APPEND FILES ${_FILE})
list(APPEND EMBEDDED_PATHS ${LOCATION})
endforeach()

list(APPEND FILES "${CMAKE_CURRENT_SOURCE_DIR}/embedded_help.rb")
list(APPEND EMBEDDED_PATHS "embedded_help.rb")

Expand Down Expand Up @@ -138,6 +145,8 @@ add_custom_command(

set_source_files_properties(${EMBED_SOURCE_FILES} PROPERTIES HEADER_FILE_ONLY TRUE)

source_group(embedded_files FILES ${OUTPUT})

add_executable(openstudio
main.cpp
"${CMAKE_CURRENT_BINARY_DIR}/SWIGRubyRuntime.hxx"
Expand Down
38 changes: 36 additions & 2 deletions openstudiocore/src/cli/embedded_help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ module Kernel
$LOAD_PATH << ':/ruby/2.0.0'
# TODO configure this in a better way
# these hardcoded platform paths are brain dead
# DLM: yes they are :-)
$LOAD_PATH << ':/ruby/2.0.0/x86_64-darwin13.4.0'
$LOAD_PATH << ':/ruby/2.0.0/x64-mswin64_120'
$LOAD_PATH << ':/ruby/2.0.0/bundler/gems/openstudio-standards-eb7b32237fb4/openstudio-standards/lib'
$LOAD_PATH << ':/ruby/2.0.0/bundler/gems/OpenStudio-workflow-gem-c2f6ed3b5151/lib'
$LOAD_PATH << ':/ruby/2.0.0/bundler/gems/openstudio-standards-c65b0ec070d3/openstudio-standards/lib'
$LOAD_PATH << ':/ruby/2.0.0/bundler/gems/OpenStudio-workflow-gem-6f5f0b797caa/lib'
$LOADED = []

alias :original_require_relative :require_relative
Expand Down Expand Up @@ -99,10 +100,43 @@ def require_relative path
if absolute_path.chars.first == ':'
absolute_path[0] = ''
absolute_path = File.expand_path absolute_path

# strip Windows drive letters
if /[A-Z\:]/.match(absolute_path)
absolute_path = absolute_path[2..-1]
end
absolute_path = ':' + absolute_path
end
return require absolute_path
end

# this function either reads a file from the embedded archive or from disk, returns file content as a string
def load_resource_relative(path, mode='r')

absolute_path = File.dirname(caller_locations(1,1)[0].path) + '/' + path
if absolute_path.chars.first == ':'
absolute_path[0] = ''
absolute_path = File.expand_path absolute_path

# strip Windows drive letters
if /[A-Z\:]/.match(absolute_path)
absolute_path = absolute_path[2..-1]
end
absolute_path = ':' + absolute_path
end

if EmbeddedScripting::hasFile(absolute_path)
return EmbeddedScripting::getFileAsString(absolute_path)
end

result = ""
if File.exists?(path)
File.open(path, mode) do |file|
result = file.read
end
end
return result
end

end

0 comments on commit 8d37c9a

Please sign in to comment.