Class: MobyUtil::GemHelper

Inherits:
Object show all
Defined in:
lib/tdriver/util/common/gem.rb

Class Method Summary collapse

Class Method Details

.create_build_filesObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/tdriver/util/common/gem.rb', line 24

def self.create_build_files

  # Create build files. These are required, as RubyGems expects that external dependencies 
  # are built during the gem installation process and will not complete the installation 
  # if these files are missing.

  begin

    # remove following line when native extensions are supported by tdriver
    #raise LoadError

    # skip native extension build if running in java environment
    raise LoadError if MobyUtil::EnvironmentHelper.java?

    # skip also if windows env. until proper solution found how to compile in windows env.
    raise LoadError if MobyUtil::EnvironmentHelper.windows? 

    # makefile creation module
    require 'mkmf'
    
    # name of ruby native extension
    extension_name = 'tdriver/native_extensions'

    # destination
    dir_config( extension_name )

    # create makefile for implementation 
    create_makefile( extension_name )

  rescue Exception

    # create dummy makefile if building native extension fails or is not supported
    File.open( 'Makefile', 'w' ) { | f | f.write "all:\n\ninstall:\n\n" }

    if MobyUtil::EnvironmentHelper.windows? 

      File.open( 'nmake.bat', 'w') { |f| f.write "SET ERRORLEVEL=0" }
      File.open( 'make.bat', 'w') { |f| f.write "SET ERRORLEVEL=0" }
      File.open( 'extconf.dll', 'w' ) {}

    else

      File.open( 'make', 'w' ){ | f | f.write '#!/bin/sh'; f.chmod f.stat.mode | 0111; }
      File.open( 'extconf.so', 'w' ) {}

    end

  end

end

.grant_file_access_rights(folder, user_name = nil, user_group = nil) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/tdriver/util/common/gem.rb', line 75

def self.grant_file_access_rights( folder, user_name = nil, user_group = nil )

  if MobyUtil::EnvironmentHelper.posix?

    # change folder ownership to user and add writing access to each file
    user_name = MobyUtil::EnvironmentHelper.user_name if user_name.nil?
    user_group = MobyUtil::EnvironmentHelper.user_group( user_name ) if user_group.nil?

    MobyUtil::EnvironmentHelper.change_file_ownership!( folder, user_name, user_group, true )

    `chmod -R u+w #{ folder }`

  end

end

.install(*parameters) {|parameters| ... } ⇒ Object

TODO: document

Yields:

  • (parameters)

Raises:

  • (ArgumentError)


92
93
94
95
96
97
98
99
100
101
102
# File 'lib/tdriver/util/common/gem.rb', line 92

def self.install( *parameters, &block )

  raise ArgumentError.new( "Target folder must be specified as first argument" ) if parameters.empty?

  yield( *parameters )

  MobyUtil::GemHelper.create_build_files

  MobyUtil::GemHelper.grant_file_access_rights( parameters.first )

end