gosu / releasy

A rake task generator to help with building/packaging/deploying Ruby applications (⚠️ unmaintained)
https://spooner.github.com/libraries/releasy/
MIT License
378 stars 29 forks source link

Can't lunch the build app on OS X #42

Closed Swatto closed 11 years ago

Swatto commented 11 years ago

After failling to launch complex game width releasy, I decide to test width the simplest code as possible :

require 'rubygems'
require 'chingu'
include Gosu
include Chingu

class Game < Chingu::Window

  def initialize
    super(400,600)
  end

end

Game.new.show

I write the Rakefile :

require 'rubygems'
require 'bundler/setup'
require 'releasy'

Releasy::Project.new do
  name "testReleasy"
  version "1.0.0"
  verbose

  executable "main.rb"
  files [
    "main.rb",
    "media/*.*"
  ]
  add_link "http://www.example.com", "My website"
  exclude_encoding

  # Create a variety of releases, for all platforms.
  add_build :osx_app do
    url "com.example.testing"
    wrapper "wrappers/gosu-mac-wrapper-0.7.44.tar.gz"
    # icon "media/icon.icns"
    add_package :dmg
  end
end

I run the build and everything seems to work :

But when I lunch the app, it closes instantly the game (no message and no error visible). I try with ruby 1.9.2 and 1.9.1 : no difference.

For information, I'm on Mac OS 10.8.2.

bil-bas commented 11 years ago

The .app wrapper actually contains Ruby 1.9.2 so that is what it will run your game with. It shouldn't matter what version is used to build it though (It has been tested with 1.8.7, 1.9.2 & 1.9.3, though I recommend 1.9.3).

The usual problem with an application not starting (.exe/.app) is that assets are being loaded based on an assumption of where the working directory is (you should always use file-relative paths). Obviously not the problem with your minimal example, of course!

I don't have access to OSX myself, so I will see if I can get someone to sanity check this for you - sorry!

jlnr commented 11 years ago

@Swatto OS X logs all the error during app launch in the console. Launch /Applications/Utilities/Console.app or enter Console into Spotlight to find it. Then clear it, and double-click your game again. You should see an error appear.

Swatto commented 11 years ago

@jlnr Thanks for that ! I didn't know the possibility to see errors here.

Here's the errors that OS X have :

Dock: no information back from LS about running process
com.apple.launchd.peruser.501: ([0x0-0x2ba2ba].com.xXxXxXx.twist[23160]) Exited with code: 1

Any ideas ?

bil-bas commented 11 years ago

The error you are looking for should be referring to "com.example.testing" not "com.apple.launchd.peruser" since that is the main reason for setting the #url in Releasy, I think. waits for jlnr to provide wisdom

jlnr commented 11 years ago

@Swatto, is it possible for you to create a ZIP archive of the app and share it with me for testing?

@Spooner, launchd is what is trying to open the .app :)

Swatto commented 11 years ago

I create a zip with all the project. It contains the source code, the wrapper and the bugging app.

@jlnr, you can download the project here. Thanks to investigate on this.

jlnr commented 11 years ago

@Swatto: I am not sure why Console is not showing anything useful, it used to do so... @Spooner Is Releasy redirecting $stderr anywhere?

So what I did is to run the game inside the pkg folder by hand from the Terminal:

Air:my_application_1_0_0_OSX jlnr$ My\ Application.app/Contents/MacOS/My\ Application 
[snip a lot of noise here]
Application.app/Contents/Resources/main.rb:12:in `chdir': No such file or directory - application (Errno::ENOENT)

And sure enough, main.rb does a Dir.chdir 'application', which does not exist. I am not sure if this is an issue with Releasy or with the Rakefile above. But that should help you guys figure it out :)

bil-bas commented 11 years ago

@jlnr If Releasy is in verbose mode, then it should not suppress any messages at all.

I did see that line last time I looked at Releasy and thought "that shouldn't work", but since no-one had complained, I assumed it did ;) It should be an absolute, not relative path, since I don't know what dir the application has been run in - I can only assume that previous tests did work but that default directory has changed since then. I hope I didn't add that in a fit of madness after the last OSX test :$

Presumably it worked when you commented out that line (or changed it to the correct path relative to __FILE__?).

Swatto commented 11 years ago

@Spooner Do you think you can fix that or you don't know why it fails ?

jlnr commented 11 years ago

@Spooner I think it'd work just fine if you replaced load 'main.rb' by require_relative 'application/main' as the last line.

Also, strictly speaking, the file inside Resources (the main.rb supplied by Releasy) should be Main.rb because that's what Gosu is loading, and you can configure OS X to be case sensitive. Though I really don't know who does that, and why. :)

bil-bas commented 11 years ago

Hmm, it should be created as Main.rb, but I suppose that wouldn't be an error when I test it on Windows if I did get that wrong :/ The "application/main" is just running the executable the user defined.

bil-bas commented 11 years ago

@Swatto I think jlnr worked it out last night. The workaround (without having to hack the generated files and until I fix Releasy :$) is to avoid having any files called "main.rb" in your game. Please confirm if this works and I'll make a proper bug report for this issue. Thanks!

Swatto commented 11 years ago

I confirm : this solve my problem with this simple test. Name a file "main.rb" breaks on OS X.

Now I need to debug my real game that don't launch too. I will post here the newest version if you can help me (this will be the gift for my godson's birthday).

Swatto commented 11 years ago

I rename my "main.rb' but I can't launch it too. If someone can't take a look at my game, it would be cool.

Sorry for the french comment but my godson want to learn programming so I explain the code of the game.

bil-bas commented 11 years ago

Had a poke around:

Releasy isn't a run-time dependency, so you should do this in your gemfile:

group :development do
  gem "releasy"
end

This means it won't get included in the Releasy releases or pointlessly loaded when you start the game itself, but you will need to change your rakefile:

require 'bundler'
Bundler.require :development # Only require Releasy, since we don't need to load Gosu/Chingu at this point.

Don't use MP3 sounds, since they aren't supported by Gosu on all platforms (e.g. I couldn't get them to work on Windows). Use Ogg Vorbis (.ogg) instead - you can use Audacity to convert them easily!

bil-bas commented 11 years ago

Oh, otherwise it seemed OK. You correctly set the Chingu asset load paths and use require_relative everywhere, so you aren't making any assumptions about the current working directory, which is good. Please re-check the console log to see if any errors are going there, now we've resolved the main.rb issue...

Swatto commented 11 years ago

Thanks for you answer. I do respectively everything :

This don't fix the problem. Here's the log that the console gives me :

com.apple.launchd.peruser.501[273] ([0x0-0x67e67e].com.coool.twist[12094]): Exited with code: 1

If you try to build it on your computer, does it failed or not ? Could we try to fix it on my repo to avoid to spam here and take the conclusion of the modification to fix Releasy ?

bil-bas commented 11 years ago

Well, it runs on Windows, now that the ogg files replaced the mp3s, which helps me ;)

I tried building with Ocra and it didn't seem to like Bundler.require (although I like that a lot). Not sure if the OSX .app can cope with it, so maybe try it more manually:

require 'bundler/setup' unless defined?(OSX_EXECUTABLE) or ENV['OCRA_EXECUTABLE']
require "gosu"
require "chingu"

Note that there is absolutely no reason to use Bundler inside an exe/app, since there can't be more than one version of the gems. All using it does is extend the duration of the startup phase. This is something I need to document further...eventually.

Swatto commented 11 years ago

This simple line

require 'bundler/setup' unless defined?(OSX_EXECUTABLE) or ENV['OCRA_EXECUTABLE']

Fix everything. Thank you for your patience.

I think you should edit your readme file with the Main.rb issue and this line too.

ariejan commented 11 years ago

Had the same issue. Try moving the app out of the dmg onto your desktop or to Applications.

Swatto commented 11 years ago

@ariejan it's looks like logic to me if the program want to write some code in the app (like high score) in the dmg, it will crash.

bil-bas commented 11 years ago

You should really be writing high scores (or settings files) into somewhere like ~/.my_application/scores.yml rather than into a file next to the executable. This also avoids the problem of people on Windows putting the executable into Program Files (which people do, although the running program won't have write rights).

Swatto commented 11 years ago

And how could it be done ? The arborescence of the disc is different on Mac and Windows.

bil-bas commented 11 years ago
save_dir = File.expand_path("~/.my_application")

expand_path will resolve the ~ for you to the user's home directory. You could alternatively use ENV['APPDIR'], if set which I think is the more normal application directory on Windows, but I'm sure no-one would mind if you just stuck it in the user's home directory.

daniero commented 11 years ago

When I finally got Rake to work (after struggling with version hell for an hour or two), the app wouldn't load at all. I checked the contents of the .app package and found that there was something wrong in pkg/testapp_1_0_OSX/testapp.app/Contents/Resources/Main.rb: When I change line 12 to the following, everything works:

Dir.chdir '../Resources/application'

The original line, which only chdirs to application, seems to be generated from https://github.com/Spooner/releasy/blob/master/lib/releasy/builders/osx_app.rb#L188

bil-bas commented 11 years ago

Regarding Rake, you should just be able to use "bundle exec rake". I suspect, however, that I should be a lot more permissive about rake versions.

jlnr commented 11 years ago

Oops - edit: I'll also try to reproduce the Dir.chdir thing. This bug still somehow sounds familiar :) But I'll comment on the right ticket next time.

bil-bas commented 11 years ago

I closed this because it should have been posted in the issue actually dealing with main.rb (https://github.com/Spooner/releasy/issues/44)