From 6570aedbb0f7c1a355ecd46f49100a57ca456c5b Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Mon, 10 Sep 2012 13:23:13 -0700 Subject: [PATCH] Making `rake install` almost work --- Rakefile | 25 +++++------- atom.gyp | 2 +- native/atom_application.h | 1 + native/atom_application.mm | 66 ++++++++++++++++++++++++++++++-- native/atom_window_controller.mm | 10 ++--- 5 files changed, 77 insertions(+), 27 deletions(-) diff --git a/Rakefile b/Rakefile index 48e042ccc..a7499b508 100644 --- a/Rakefile +++ b/Rakefile @@ -14,7 +14,7 @@ end desc "Build Atom via `xcodebuild`" task :build => ["create-project", "verify-prerequisites"] do - command = "xcodebuild -target Atom -configuration Release SYMROOT=#{BUILD_DIR}" + command = "xcodebuild -target Atom -configuration Debug SYMROOT=#{BUILD_DIR}" output = `#{command}` if $?.exitstatus != 0 $stderr.puts "Error #{$?.exitstatus}:\n#{output}" @@ -40,10 +40,10 @@ task :package => :build do end end -desc "Installs symlink from `application_path() to /Applications directory" +desc "Creates symlink from `application_path() to /Applications/Atom and creates a CLI at /usr/local/bin/atom" task :install => :build do if path = application_path() - FileUtils.ln_sf File.expand_path(path), "/Applications/Desktop" + FileUtils.ln_sf File.expand_path(path), "/Applications" usr_bin = "/usr/local/bin" usr_bin_exists = ENV["PATH"].split(":").include?(usr_bin) if usr_bin_exists @@ -90,19 +90,12 @@ task :"copy-files-to-bundle" => :"verify-prerequisites" do mkdir_p "#{dest}/v8_extensions" cp Dir.glob("#{project_dir}/native/v8_extensions/*.js"), "#{dest}/v8_extensions/" - if resource_path = ENV['RESOURCE_PATH'] - # CoffeeScript can't deal with unescaped whitespace in 'Atom Helper.app' path - escaped_dest = dest.gsub("Atom Helper.app", "Atom\\ Helper.app") - `coffee -c -o \"#{escaped_dest}/src/stdlib\" \"#{resource_path}/src/stdlib/require.coffee\"` - cp_r "#{resource_path}/static", dest - else - # TODO: Restore this list when we add in all of atoms source - %w(src static vendor spec benchmark bundles themes).each do |dir| - dest_path = File.join(dest, dir) - rm_rf dest_path - cp_r dir, dest_path - `coffee -c '#{dest_path}'` - end + %w(src static vendor spec benchmark bundles themes).each do |dir| + dest_path = File.join(dest, dir) + rm_rf dest_path + cp_r dir, dest_path + + `coffee -c '#{dest_path}'` end end diff --git a/atom.gyp b/atom.gyp index 9181ec9dc..51435b920 100644 --- a/atom.gyp +++ b/atom.gyp @@ -25,7 +25,7 @@ 'configurations': { 'Debug': { 'xcode_config_file': 'native/mac/debug.xcconfig', - 'defines': ['RESOURCE_PATH="$RESOURCE_PATH"'], + 'defines': ['DEBUG=1', 'RESOURCE_PATH=\"$RESOURCE_PATH\"'], }, 'Release': { }, diff --git a/native/atom_application.h b/native/atom_application.h index 8f176a63f..6ac96a9e1 100644 --- a/native/atom_application.h +++ b/native/atom_application.h @@ -8,6 +8,7 @@ class AtomCefClient; BOOL handlingSendEvent_; } ++ (NSMutableDictionary *)arguments; + (id)applicationWithArguments:(char **)argv count:(int)argc; + (CefSettings)createCefSettings; - (void)open:(NSString *)path; diff --git a/native/atom_application.mm b/native/atom_application.mm index 8e46406f2..59efc0c1f 100644 --- a/native/atom_application.mm +++ b/native/atom_application.mm @@ -3,13 +3,68 @@ #import "native/atom_application.h" #import "native/atom_window_controller.h" #import "native/atom_cef_app.h" +#import @implementation AtomApplication +static NSMutableDictionary *sArguments; + ++ (NSMutableDictionary *)arguments { + if (!sArguments) { + sArguments = [[NSMutableDictionary alloc] init]; + + // Defaults + #ifdef RESOURCE_PATH + [sArguments setObject:[NSString stringWithUTF8String:RESOURCE_PATH] forKey:@"resource-path"]; + #endif + } + + return sArguments; +} + ++ (void)parseArguments:(char **)argv count:(int)argc { + int opt; + int longindex; + + if (argc > 2 && strcmp(argv[argc - 2], "-NSDocumentRevisionsDebugMode") == 0) { // Because Xcode inserts useless command-line args by default: http://trac.wxwidgets.org/ticket/13732 + argc -= 2; // Ignore last two arguments + } + + static struct option longopts[] = { + { "resource-path", optional_argument, NULL, 'r' }, + { "benchmark", optional_argument, NULL, 'b' }, + { "test", optional_argument, NULL, 't' }, + { NULL, 0, NULL, 0 } + }; + + while ((opt = getopt_long(argc, argv, "r:bth?", longopts, &longindex)) != -1) { + switch (opt) { + case 'r': + [[self arguments] setObject:[NSString stringWithUTF8String:optarg] forKey:@"resource-path"]; + break; + case 'b': + [[self arguments] setObject:[NSNumber numberWithBool:YES] forKey:@"benchmark"]; + break; + case 't': + [[self arguments] setObject:[NSNumber numberWithBool:YES] forKey:@"test"]; + break; + default: + printf("usage: atom [--resource-path=] []"); + } + } + + argc -= optind; + argv += optind; + + if (argc > 0) { + [[self arguments] setObject:[NSString stringWithUTF8String:argv[0]] forKey:@"path"]; + } +} + + (id)applicationWithArguments:(char **)argv count:(int)argc { NSApplication *application = [super sharedApplication]; CefInitialize(CefMainArgs(argc, argv), [self createCefSettings], new AtomCefApp); - + [self parseArguments:argv count:argc]; return application; } @@ -47,6 +102,7 @@ } - (void)open:(NSString *)path { + NSLog(@"%@", path); [[AtomWindowController alloc] initWithPath:path]; } @@ -71,13 +127,15 @@ - (void)applicationWillFinishLaunching:(NSNotification *)notification { _backgroundWindowController = [[AtomWindowController alloc] initInBackground]; - NSArray *processArguments = [[NSProcessInfo processInfo] arguments]; - if ([processArguments containsObject:@"--benchmark"]) { + if ([[AtomApplication arguments] objectForKey:@"benchmark"]) { [self runBenchmarksThenExit:true]; } - else if ([processArguments containsObject:@"--test"]) { + else if ([[AtomApplication arguments] objectForKey:@"test"]) { [self runSpecsThenExit:true]; } + else { + [self open:[[AtomApplication arguments] objectForKey:@"path"]]; + } } - (void)applicationWillTerminate:(NSNotification *)notification { diff --git a/native/atom_window_controller.mm b/native/atom_window_controller.mm index 15ab5da84..d5ce7d457 100644 --- a/native/atom_window_controller.mm +++ b/native/atom_window_controller.mm @@ -2,6 +2,7 @@ #include "include/cef_client.h" #import "native/atom_cef_client.h" #import "native/atom_window_controller.h" +#import "native/atom_application.h" @implementation AtomWindowController @@ -23,13 +24,10 @@ self = [super initWithWindowNibName:@"AtomWindow"]; _bootstrapScript = [bootstrapScript retain]; -#ifdef RESOURCE_PATH - _resourcePath = [[NSString alloc] initWithUTF8String:RESOURCE_PATH]; -#else - _resourcePath = [[[NSBundle mainBundle] resourcePath] retain]; -#endif - + _resourcePath = [[[AtomApplication arguments] objectForKey:@"resource-path"] retain]; + if (!_resourcePath) _resourcePath = [[[NSBundle mainBundle] resourcePath] retain]; + if (!background) { [self showWindow:self]; }