Skip to content

Commit 0494da8

Browse files
committed
Add OSX support.
1 parent 641d075 commit 0494da8

File tree

179 files changed

+87
-31190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+87
-31190
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
bindata.go
22
runx.exe
33
runx
4+
runtime/

Runfile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
composer:
2-
install:
3-
command: docker-compose -f docker-compose.yml -f docker-utils.yml run composer install
4-
help: Install Composer dependencies.
5-
update:
6-
command: docker-compose -f docker-compose.yml -f docker-utils.yml run composer update
7-
help: Update Composer dependencies.
1+
run :ls do
2+
puts 'okay ls!'
3+
end

build-osx.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
set -x
4+
5+
if [ ! -d runtime ]; then
6+
mkdir -p runtime/lib/ruby
7+
mkdir -p runtime/lib/app
8+
curl -L --fail https://d6r77u77i8pq3.cloudfront.net/releases/traveling-ruby-20141215-2.1.5-osx.tar.gz | tar -zxv -C runtime/lib/ruby
9+
fi
10+
11+
cp runx.rb runtime/lib/app/runx.rb
12+
go-bindata runtime/...
13+
go build

main.go

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"hash/fnv"
1212
"encoding/hex"
1313
"github.com/kardianos/osext"
14+
"github.com/mitchellh/go-homedir"
1415
)
1516

1617
func selfDigest() (string, error) {
@@ -30,7 +31,7 @@ func selfDigest() (string, error) {
3031
if _, err := io.Copy(hash, file); err != nil {
3132
return "", err
3233
}
33-
34+
3435
result = hash.Sum(result)
3536
digest := hex.EncodeToString(result)
3637

@@ -43,13 +44,17 @@ func deployRuntime() (string, error) {
4344
return "", err
4445
}
4546

46-
runxDir := "runx-" + digest
47-
dir := path.Join(os.TempDir(), runxDir)
47+
home, err := homedir.Dir()
48+
if err != nil {
49+
return "", err
50+
}
51+
52+
dir := path.Join(home, ".runx", digest)
4853
err = os.Mkdir(dir, 0700)
4954
if os.IsExist(err) {
5055
return dir, nil
5156
} else {
52-
err = RestoreAssets(dir, "win32")
57+
err = RestoreAssets(dir, "runtime")
5358
if err != nil {
5459
return "", err
5560
}
@@ -58,30 +63,73 @@ func deployRuntime() (string, error) {
5863
}
5964
}
6065

66+
func setupWin32(dir string) string {
67+
root := path.Join(dir, "runtime", "lib", "ruby")
68+
ruby := path.Join(root, "bin.real", "ruby.exe")
69+
70+
version := "2.1.0"
71+
arch := "i386-mingw32"
72+
73+
rubyLib := strings.Join([]string{
74+
path.Join(root, "lib", "ruby", "site_ruby", version),
75+
path.Join(root, "lib", "ruby", "site_ruby", version, arch),
76+
path.Join(root, "lib", "ruby", "site_ruby"),
77+
path.Join(root, "lib", "ruby", "vendor_ruby", version),
78+
path.Join(root, "lib", "ruby", "vendor_ruby", version, arch),
79+
path.Join(root, "lib", "ruby", "vendor_ruby"),
80+
path.Join(root, "lib", "ruby", version),
81+
path.Join(root, "lib", "ruby", version, arch),
82+
}, ";")
83+
os.Setenv("RUBYLIB", rubyLib)
84+
85+
return ruby
86+
}
87+
88+
func setupOsx(dir string) string {
89+
root := path.Join(dir, "runtime", "lib", "ruby")
90+
ruby := path.Join(root, "bin.real", "ruby")
91+
92+
version := "2.1.0"
93+
arch := "x86_64-darwin13.0"
94+
95+
os.Setenv("ORIG_DYLD_LIBRARY_PATH", os.Getenv("LD_LIBRARY_PATH"))
96+
os.Setenv("ORIG_TERMINFO", os.Getenv("TERMINFO"))
97+
os.Setenv("ORIG_SSL_CERT_DIR", os.Getenv("SSL_CERT_DIR"))
98+
os.Setenv("ORIG_SSL_CERT_FILE", os.Getenv("SSL_CERT_FILE"))
99+
os.Setenv("ORIG_RUBYOPT", os.Getenv("RUBYOPT"))
100+
os.Setenv("ORIG_RUBYLIB", os.Getenv("RUBYLIB"))
101+
os.Unsetenv("DYLD_LIBRARY_PATH")
102+
os.Setenv("TERMINFO", "/usr/share/terminfo")
103+
os.Unsetenv("SSL_CERT_DIR")
104+
os.Setenv("SSL_CERT_FILE", path.Join(root, "lib", "ca-bundle.crt"))
105+
os.Setenv("RUBYOPT", "-r" + path.Join(root, "lib", "restore_environment"))
106+
os.Setenv("GEM_HOME", path.Join(root, "lib", "ruby", "gems", version))
107+
os.Setenv("GEM_PATH", path.Join(root, "lib", "ruby", "gems", version))
108+
109+
rubyLib := strings.Join([]string{
110+
path.Join(root, "lib", "ruby", "site_ruby", version),
111+
path.Join(root, "lib", "ruby", "site_ruby", version, arch),
112+
path.Join(root, "lib", "ruby", "site_ruby"),
113+
path.Join(root, "lib", "ruby", "vendor_ruby", version),
114+
path.Join(root, "lib", "ruby", "vendor_ruby", version, arch),
115+
path.Join(root, "lib", "ruby", "vendor_ruby"),
116+
path.Join(root, "lib", "ruby", version),
117+
path.Join(root, "lib", "ruby", version, arch),
118+
}, ":")
119+
os.Setenv("RUBYLIB", rubyLib)
120+
121+
return ruby
122+
}
123+
61124
func main() {
62125
dir, err := deployRuntime()
63126
if err != nil {
64127
log.Fatal(err)
65128
return
66129
}
67130

68-
ruby := path.Join(dir, "win32", "lib", "ruby", "bin.real", "ruby.exe")
69-
script := path.Join(dir, "win32", "lib", "app", "runx.rb")
70-
71-
version := "2.1.0"
72-
arch := "i386-mingw32"
73-
74-
rubyLib := strings.Join([]string{
75-
path.Join(dir, "win32", "lib", "ruby", "lib", "ruby", "site_ruby", version),
76-
path.Join(dir, "win32", "lib", "ruby", "lib", "ruby", "site_ruby", version, arch),
77-
path.Join(dir, "win32", "lib", "ruby", "lib", "ruby", "site_ruby"),
78-
path.Join(dir, "win32", "lib", "ruby", "lib", "ruby", "vendor_ruby", version),
79-
path.Join(dir, "win32", "lib", "ruby", "lib", "ruby", "vendor_ruby", version, arch),
80-
path.Join(dir, "win32", "lib", "ruby", "lib", "ruby", "vendor_ruby"),
81-
path.Join(dir, "win32", "lib", "ruby", "lib", "ruby", version),
82-
path.Join(dir, "win32", "lib", "ruby", "lib", "ruby", version, arch),
83-
}, ";")
84-
os.Setenv("RUBYLIB", rubyLib)
131+
ruby := setupOsx(dir)
132+
script := path.Join(dir, "runtime", "lib", "app", "runx.rb")
85133

86134
// We want to run "ruby runx.rb [args...]".
87135
// We exclude the first argument to this process since it's just self.

runx.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def find_runfile
3535
dir = Dir.pwd
3636
while dir != previous
3737
runfile = File.join(dir, 'Runfile')
38-
return runfile.gsub(File::SEPARATOR, File::ALT_SEPARATOR) if File.exist?(runfile)
38+
return runfile.gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR) if File.exist?(runfile)
3939
previous = dir
4040
dir = File.expand_path(File.join(dir, '..'))
4141
end

win32/lib/app/.gitkeep

Whitespace-only changes.

win32/lib/ruby/bin.real/gem

Lines changed: 0 additions & 25 deletions
This file was deleted.

win32/lib/ruby/bin.real/gem.bat

Lines changed: 0 additions & 6 deletions
This file was deleted.

win32/lib/ruby/bin.real/irb

Lines changed: 0 additions & 11 deletions
This file was deleted.

win32/lib/ruby/bin.real/irb.bat

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)