pik 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/Manifest.txt +9 -8
- data/README.rdoc +13 -3
- data/Rakefile +35 -14
- data/bin/pik_install +50 -10
- data/features/support/env.rb +2 -2
- data/features/{switch_command.feature → use_command.feature} +3 -3
- data/lib/pik.rb +32 -23
- data/lib/pik/commands/command.rb +5 -15
- data/lib/pik/commands/config_command.rb +0 -1
- data/lib/pik/commands/default_command.rb +4 -4
- data/lib/pik/commands/devkit_command.rb +3 -3
- data/lib/pik/commands/install_command.rb +2 -2
- data/lib/pik/commands/{batch_file_editor.rb → script_file_editor.rb} +10 -29
- data/lib/pik/commands/update_command.rb +2 -2
- data/lib/pik/commands/{switch_command.rb → use_command.rb} +3 -3
- data/lib/pik/core_ext/pathname.rb +6 -2
- data/lib/pik/scripts/bash_file.rb +36 -0
- data/lib/pik/scripts/batch_file.rb +32 -0
- data/lib/pik/scripts/ps_file.rb +33 -0
- data/lib/pik/scripts/script_file.rb +45 -0
- data/lib/pik/search_path.rb +4 -0
- data/spec/batch_file_spec.rb +2 -2
- data/spec/pathname_spec.rb +7 -0
- data/spec/search_path_spec.rb +29 -8
- data/spec/switch_command_spec.rb +10 -10
- data/tools/pik.bat +2 -1
- data/tools/pik.ps1 +3 -0
- data/tools/pik_runner.exe +0 -0
- metadata +18 -33
- data/lib/pik/batch_file.rb +0 -70
- data/lib/pik/pik.rb +0 -10
- data/tools/pik/pik_runner +0 -42
- data/tools/pik/pik_runner.exe +0 -0
- data/tools/pik/pik_runner.exy +0 -296
@@ -7,15 +7,15 @@ module Pik
|
|
7
7
|
|
8
8
|
attr_accessor :verbose
|
9
9
|
|
10
|
-
include
|
10
|
+
include ScriptFileEditor
|
11
11
|
|
12
12
|
def execute
|
13
13
|
sys = WindowsEnv.system
|
14
14
|
usr = WindowsEnv.user
|
15
15
|
new_path = [sys['PATH'],usr['PATH']].compact.join(';')
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@
|
16
|
+
@script.set('PATH' => SearchPath.new(new_path) )
|
17
|
+
@script.set('GEM_PATH' => usr['GEM_PATH'] || sys['GEM_PATH'] )
|
18
|
+
@script.set('GEM_HOME' => usr['GEM_HOME'] || sys['GEM_HOME'] )
|
19
19
|
echo_ruby_version(Which::Ruby.find(new_path)) if verbose
|
20
20
|
end
|
21
21
|
|
@@ -27,7 +27,7 @@ module Pik
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def write_make(path)
|
30
|
-
BatchFile.new(path + 'make.bat') do |b|
|
30
|
+
Pik::BatchFile.new(path + 'make.bat') do |b|
|
31
31
|
b.file_data << 'setlocal'
|
32
32
|
b.set(:DEVKIT => config.global[:devkit])
|
33
33
|
b.set(:PATH => "%DEVKIT%\\gcc\\3.4.5\\bin;%DEVKIT%\\msys\\1.0.11\\bin")
|
@@ -37,7 +37,7 @@ module Pik
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def write_sh(path)
|
40
|
-
BatchFile.new(path + 'sh.bat') do |b|
|
40
|
+
Pik::BatchFile.new(path + 'sh.bat') do |b|
|
41
41
|
b.file_data << 'setlocal'
|
42
42
|
b.set(:DEVKIT => config.global[:devkit])
|
43
43
|
b.set(:PATH => "%DEVKIT%\\gcc\\3.4.5\\bin;%DEVKIT%\\msys\\1.0.11\\bin")
|
@@ -47,7 +47,7 @@ module Pik
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def write_gcc(path)
|
50
|
-
BatchFile.new(path + '
|
50
|
+
Pik::BatchFile.new(path + 'gcc.bat') do |b|
|
51
51
|
b.file_data << 'setlocal'
|
52
52
|
b.set(:DEVKIT => config.global[:devkit])
|
53
53
|
b.set(:PATH => "%DEVKIT%\\gcc\\3.4.5\\bin;%PATH%")
|
@@ -14,7 +14,7 @@ module Pik
|
|
14
14
|
def initialize(args=ARGV, config_=nil)
|
15
15
|
super
|
16
16
|
@download_dir = config.global[:download_dir] || PIK_HOME + 'downloads'
|
17
|
-
@install_root = config.global[:install_dir] ||
|
17
|
+
@install_root = config.global[:install_dir] || PIK_HOME + 'rubies'
|
18
18
|
FileUtils.mkdir_p @download_dir.to_s
|
19
19
|
end
|
20
20
|
|
@@ -79,7 +79,7 @@ SEP
|
|
79
79
|
if @hl.agree(question){|answer| answer.default = 'yes' }
|
80
80
|
uri = 'http://downloads.sourceforge.net/sevenzip/7za465.zip'
|
81
81
|
file = download(uri)
|
82
|
-
Zip.fake_unzip(file.to_s, /\.exe|\.dll$/,
|
82
|
+
Zip.fake_unzip(file.to_s, /\.exe|\.dll$/, PIK_SCRIPT.dirname.to_s)
|
83
83
|
else
|
84
84
|
raise QuitError
|
85
85
|
end
|
@@ -1,24 +1,18 @@
|
|
1
1
|
module Pik
|
2
2
|
|
3
|
-
module
|
3
|
+
module ScriptFileEditor
|
4
4
|
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :script
|
6
6
|
|
7
7
|
def initialize(args=ARGV,config=nil)
|
8
8
|
super
|
9
|
-
|
10
|
-
|
11
|
-
editors << @batch
|
12
|
-
end
|
13
|
-
|
14
|
-
def close
|
15
|
-
update_gem_batch
|
16
|
-
super
|
9
|
+
@script = SCRIPT_FILE
|
10
|
+
editors << @script
|
17
11
|
end
|
18
12
|
|
19
13
|
def set(items)
|
20
14
|
items.each do |k, v|
|
21
|
-
@
|
15
|
+
@script.set(k => v)
|
22
16
|
WindowsEnv.user.set(k => v) if global
|
23
17
|
end
|
24
18
|
end
|
@@ -34,33 +28,20 @@ module Pik
|
|
34
28
|
|
35
29
|
# if the new version has a GEM_HOME, add it's bin dir to the path
|
36
30
|
new_path.add(Pathname.new(other[:gem_home]) + 'bin') if other[:gem_home]
|
37
|
-
|
38
|
-
@batch.set('PATH' => new_path.join )
|
31
|
+
@script.set('PATH' => new_path )
|
39
32
|
end
|
40
33
|
|
41
34
|
def switch_gem_home_to(gem_home)
|
42
35
|
gem_home = Pathname(gem_home).to_windows rescue nil
|
43
|
-
@
|
44
|
-
@
|
36
|
+
@script.set('GEM_PATH' => gem_home )
|
37
|
+
@script.set('GEM_HOME' => gem_home )
|
45
38
|
end
|
46
39
|
|
47
40
|
def echo_ruby_version(path, verb='')
|
48
41
|
rb = Which::Ruby.exe(path).basename
|
49
|
-
@
|
42
|
+
@script.call "#{rb} -v"
|
50
43
|
end
|
51
|
-
|
52
|
-
def echo_running_with_ruby_version(path)
|
53
|
-
echo_ruby_version('Running with')
|
54
|
-
end
|
55
|
-
|
56
|
-
def update_gem_batch
|
57
|
-
BatchFile.open(PIK_BATCH) do |gem_bat|
|
58
|
-
# call new .pik/pik batch
|
59
|
-
gem_bat.call(%Q("#{@batch.path.to_windows}")) if @batch
|
60
|
-
gem_bat.write
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
44
|
+
|
64
45
|
end
|
65
46
|
|
66
47
|
end
|
@@ -4,11 +4,11 @@ module Pik
|
|
4
4
|
|
5
5
|
aka :up
|
6
6
|
it "updates pik."
|
7
|
-
include
|
7
|
+
include ScriptFileEditor
|
8
8
|
|
9
9
|
def execute
|
10
10
|
sh "#{Which::Gem.exe} install pik"
|
11
|
-
@
|
11
|
+
@script.call("pik_install #{PIK_SCRIPT.dirname}")
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
@@ -2,12 +2,16 @@
|
|
2
2
|
class Pathname
|
3
3
|
|
4
4
|
def to_s
|
5
|
-
@path.tr('/','\\').sub(
|
5
|
+
@path.tr('/','\\').sub(/^(.):/){|s| s.upcase }
|
6
6
|
end
|
7
7
|
alias to_windows to_s
|
8
8
|
|
9
9
|
def to_ruby
|
10
|
-
@path.tr('\\','/').sub(
|
10
|
+
@path.tr('\\','/').sub(/^(.):/){|s| s.upcase }
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_bash
|
14
|
+
@path.tr('\\','/').sub(/^(.):/){|s| "/#{s[0,1].downcase}"}
|
11
15
|
end
|
12
16
|
|
13
17
|
def ruby
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Pik
|
2
|
+
|
3
|
+
class BashFile < ScriptFile
|
4
|
+
|
5
|
+
attr_accessor :file_data, :file_name, :ruby_dir
|
6
|
+
|
7
|
+
def extname
|
8
|
+
".sh"
|
9
|
+
end
|
10
|
+
|
11
|
+
def header
|
12
|
+
string = "#!/bin/sh\n"
|
13
|
+
string << "# This bash script generated by Pik, the\n"
|
14
|
+
string << "# Ruby Manager for Windows\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(exe)
|
18
|
+
@file_data << "#{exe}\n"
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def set(items)
|
23
|
+
items.each{|k,v|
|
24
|
+
v = v.to_bash if v.respond_to? 'to_bash'
|
25
|
+
@file_data << "export #{k}='#{v}'" }
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def unset(items)
|
30
|
+
items.each{|k| @file_data << "export #{k}=" }
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Pik
|
2
|
+
|
3
|
+
class BatchFile < ScriptFile
|
4
|
+
|
5
|
+
def extname
|
6
|
+
".bat"
|
7
|
+
end
|
8
|
+
|
9
|
+
def header
|
10
|
+
string = "@ECHO OFF\n\n"
|
11
|
+
string << ":: This batch file generated by Pik, the\n"
|
12
|
+
string << ":: Ruby Manager for Windows\n"
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(bat)
|
16
|
+
@file_data << "CALL #{bat}\n"
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def set(items)
|
21
|
+
items.each{|k,v| @file_data << "SET #{k}=#{v}" }
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def unset(*items)
|
26
|
+
items.flatten.each{|k| @file_data << "SET #{k}=" }
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Pik
|
2
|
+
|
3
|
+
class PsFile < ScriptFile
|
4
|
+
|
5
|
+
attr_accessor :file_data, :file_name, :ruby_dir
|
6
|
+
|
7
|
+
def extname
|
8
|
+
".ps1"
|
9
|
+
end
|
10
|
+
|
11
|
+
def header
|
12
|
+
string = "# This powshell script generated by Pik, the\n"
|
13
|
+
string << "# Ruby Manager for Windows\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(exe)
|
17
|
+
@file_data << "#{exe}\n"
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def set(items)
|
22
|
+
items.each{|k,v| @file_data << "$ENV:#{k}=\"#{v}\"" }
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def unset(items)
|
27
|
+
items.each{|k| @file_data << "Remove-Item ENV:#{k}" }
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Pik
|
2
|
+
|
3
|
+
class ScriptFile
|
4
|
+
|
5
|
+
attr_accessor :file_data, :file_name, :ruby_dir
|
6
|
+
|
7
|
+
def initialize(file) #, mode=:new)
|
8
|
+
@file = Pathname.new(file.to_s + extname)
|
9
|
+
@file_data = [header]
|
10
|
+
yield self if block_given?
|
11
|
+
end
|
12
|
+
|
13
|
+
def path
|
14
|
+
@file
|
15
|
+
end
|
16
|
+
|
17
|
+
def extname
|
18
|
+
raise
|
19
|
+
end
|
20
|
+
|
21
|
+
def echo(string='.')
|
22
|
+
string = ' ' + string unless string == '.'
|
23
|
+
@file_data << "ECHO#{string}"
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def remove_line(re)
|
28
|
+
@file_data.reject!{ |i| i =~ re }
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
@file_data.join("\n")
|
33
|
+
end
|
34
|
+
|
35
|
+
def write
|
36
|
+
File.open(@file, 'w+'){|f| f.puts self.to_s }
|
37
|
+
end
|
38
|
+
|
39
|
+
def << (cmd)
|
40
|
+
@file_data << cmd
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/lib/pik/search_path.rb
CHANGED
data/spec/batch_file_spec.rb
CHANGED
data/spec/pathname_spec.rb
CHANGED
@@ -35,4 +35,11 @@ describe Pathname do
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
describe 'to_bash' do
|
39
|
+
it 'should change the file and disk separator' do
|
40
|
+
path = Pathname("z:\\This\\is\\to\\test\\separators")
|
41
|
+
result = '/z/This/is/to/test/separators'
|
42
|
+
path.to_bash.should eql(result)
|
43
|
+
end
|
44
|
+
end
|
38
45
|
end
|
data/spec/search_path_spec.rb
CHANGED
@@ -117,16 +117,37 @@ describe SearchPath do
|
|
117
117
|
@path.replace_or_add('C:/xray/yankee/alpha', path)
|
118
118
|
@path.join.should == new_path
|
119
119
|
end
|
120
|
+
end
|
120
121
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
end
|
122
|
+
describe "#find" do
|
123
|
+
it "should return the first path where block is not false" do
|
124
|
+
path = SearchPath.new(ENV['PATH'])
|
125
|
+
dir = path.find{|i| !!Dir[ File.join(i.gsub('\\','/'), '{ruby.exe, ir.exe}') ].first }
|
126
|
+
dir.should_not be_nil
|
127
|
+
dir.should be_a(String)
|
128
128
|
end
|
129
|
-
|
130
129
|
end
|
131
130
|
|
131
|
+
describe '#to_bash' do
|
132
|
+
it 'should change the file and disk separator' do
|
133
|
+
new_path = 'C:\xray\yankee\zebra;'
|
134
|
+
new_path << 'C:\Program Files\Common Files\Shoes\0.r1134\..;'
|
135
|
+
new_path << 'C:\bin;'
|
136
|
+
new_path << 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;'
|
137
|
+
new_path << 'C:\Program Files\Common Files\Shoes\0.r395\..;'
|
138
|
+
new_path << 'C:\windows\system32'
|
139
|
+
|
140
|
+
bash_path = '/c/xray/yankee/zebra:'
|
141
|
+
bash_path << '/c/Program Files/Common Files/Shoes/0.r1134/..:'
|
142
|
+
bash_path << '/c/bin:'
|
143
|
+
bash_path << '/c/WINDOWS/Microsoft.NET/Framework/v2.0.50727:'
|
144
|
+
bash_path << '/c/Program Files/Common Files/Shoes/0.r395/..:'
|
145
|
+
bash_path << '/c/windows/system32'
|
146
|
+
|
147
|
+
path = SearchPath.new(new_path)
|
148
|
+
path.should be_a SearchPath
|
149
|
+
path.to_bash.should eql(bash_path)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
132
153
|
end
|
data/spec/switch_command_spec.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
|
3
|
-
describe Pik::
|
3
|
+
describe Pik::Use do
|
4
4
|
|
5
5
|
it "should have a summary" do
|
6
|
-
Pik::
|
6
|
+
Pik::Use.summary.should eql("Switches ruby versions based on patterns.")
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should have an alias of sw" do
|
10
|
-
Pik::
|
10
|
+
Pik::Use.names.should include(:sw)
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should have an alias of use" do
|
14
|
-
Pik::
|
14
|
+
Pik::Use.names.should include(:use)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should have a global option" #do
|
18
|
-
# sw = Pik::
|
18
|
+
# sw = Pik::Use.new(['-g'])
|
19
19
|
# sw.global.should be_true
|
20
20
|
# end
|
21
21
|
|
22
22
|
it "should have a gem_home option" # do
|
23
|
-
# sw = Pik::
|
23
|
+
# sw = Pik::Use.new(['-m', 'test'])
|
24
24
|
# sw.gem_home.should eql("test")
|
25
25
|
# end
|
26
26
|
|
@@ -29,9 +29,9 @@ describe Pik::Switch do
|
|
29
29
|
'spec ' => {:path => Pathname('C:/ruby/bin')},
|
30
30
|
'real ' => {:path => Pathname.new(::RbConfig::CONFIG['bindir'] )}
|
31
31
|
}
|
32
|
-
cmd = Pik::
|
32
|
+
cmd = Pik::Use.new(['spec'], conf)
|
33
33
|
cmd.execute
|
34
|
-
batch = cmd.instance_variable_get('@
|
34
|
+
batch = cmd.instance_variable_get('@script').file_data
|
35
35
|
batch.should include("SET GEM_PATH=")
|
36
36
|
batch.should include("SET GEM_HOME=")
|
37
37
|
set_path = batch.grep(/set/i).first
|
@@ -46,9 +46,9 @@ describe Pik::Switch do
|
|
46
46
|
},
|
47
47
|
'real ' => {:path => Pathname.new(::RbConfig::CONFIG['bindir'] )}
|
48
48
|
}
|
49
|
-
cmd = Pik::
|
49
|
+
cmd = Pik::Use.new(['spec'], conf)
|
50
50
|
cmd.execute
|
51
|
-
batch = cmd.instance_variable_get('@
|
51
|
+
batch = cmd.instance_variable_get('@script').file_data
|
52
52
|
batch.should include("SET GEM_PATH=C:\\Users\\martin_blanke\\.gems")
|
53
53
|
batch.should include("SET GEM_HOME=C:\\Users\\martin_blanke\\.gems")
|
54
54
|
end
|