Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit f5bf46f

Browse files
committed
JS resource compilation, platform independent.
1 parent 272fb80 commit f5bf46f

File tree

5 files changed

+108
-51
lines changed

5 files changed

+108
-51
lines changed

appshell.gyp

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'variables': {
77
'appname': 'Brackets',
88
'pkg-config': 'pkg-config',
9+
'target_arch%': 'environment',
910
'chromium_code': 1,
1011
'conditions': [
1112
[ 'OS=="mac"', {
@@ -165,18 +166,48 @@
165166
],
166167
}],
167168
['OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
169+
'actions': [
170+
{
171+
'action_name': 'appshell_extensions_js',
172+
'inputs': [
173+
'appshell/appshell_extensions.js',
174+
],
175+
'outputs': [
176+
'appshell_extensions_js.o',
177+
],
178+
'action': [
179+
'objcopy',
180+
'--input',
181+
'binary',
182+
'--output',
183+
'<(output_bfd)',
184+
'--binary-architecture',
185+
'i386',
186+
'<@(_inputs)',
187+
'<@(_outputs)',
188+
],
189+
'message': 'compiling js resource'
190+
},
191+
],
168192
'cflags': [
169193
'<!@(<(pkg-config) --cflags gtk+-2.0 gthread-2.0)',
194+
'<(march)',
170195
],
171196
'include_dirs': [
172197
'.',
173-
],
198+
],
174199
'default_configuration': 'Release',
175200
'configurations': {
176201
'Release': {},
177202
'Debug': {},
178203
},
179204
'copies': [
205+
{
206+
'destination': '<(PRODUCT_DIR)/lib',
207+
'files': [
208+
'<@(appshell_bundle_libraries_linux)',
209+
],
210+
},
180211
{
181212
'destination': '<(PRODUCT_DIR)',
182213
'files': [
@@ -191,10 +222,13 @@
191222
'link_settings': {
192223
'ldflags': [
193224
'<!@(<(pkg-config) --libs-only-other gtk+-2.0 gthread-2.0)',
194-
'$(BUILDTYPE)/lib.target/libcef.so',
225+
'-Wl,-rpath,\$$ORIGIN/lib',
226+
'<(march)'
195227
],
196228
'libraries': [
197229
'<!@(<(pkg-config) --libs-only-l gtk+-2.0 gthread-2.0)',
230+
'$(BUILDTYPE)/lib.target/libcef.so',
231+
'appshell_extensions_js.o',
198232
],
199233
},
200234
}],
@@ -230,9 +264,10 @@
230264
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
231265
},
232266
'conditions': [
233-
['OS=="linux"', {
267+
['OS=="linux"', {
234268
'cflags': [
235269
'<!@(<(pkg-config) --cflags gtk+-2.0 gthread-2.0)',
270+
'<(march)',
236271
],
237272
'default_configuration': 'Release',
238273
'configurations': {
@@ -310,5 +345,23 @@
310345
}, # target appshell_helper_app
311346
],
312347
}], # OS=="mac"
348+
['target_arch=="ia32"', {
349+
'variables': {
350+
'output_bfd': 'elf32-i386',
351+
'march': '-m32',
352+
},
353+
}],
354+
['target_arch=="x64"', {
355+
'variables': {
356+
'output_bfd': 'elf64-x86-64',
357+
'march': '-m64',
358+
},
359+
}],
360+
['target_arch=="environment"', {
361+
'variables': {
362+
'output_bfd': '<!(uname -m | sed "s/x86_64/elf64-x86-64/;s/i.86/elf32-i386/")',
363+
'march': ' ',
364+
},
365+
}],
313366
],
314367
}

appshell/appshell_extensions_gtk.cpp

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323

2424
#include "appshell_extensions.h"
25+
#include "appshell_extensions_platform.h"
2526
#include "client_handler.h"
2627

2728
#include <errno.h>
@@ -65,8 +66,8 @@ class LiveBrowserMgrLin
6566
LiveBrowserMgrLin();
6667
virtual ~LiveBrowserMgrLin();
6768

68-
int m_closeLiveBrowserHeartbeatTimerId;
69-
int m_closeLiveBrowserTimeoutTimerId;
69+
int m_closeLiveBrowserHeartbeatTimerId;
70+
int m_closeLiveBrowserTimeoutTimerId;
7071
CefRefPtr<CefProcessMessage> m_closeLiveBrowserCallback;
7172
CefRefPtr<CefBrowser> m_browser;
7273

@@ -682,18 +683,6 @@ void BringBrowserWindowToFront(CefRefPtr<CefBrowser> browser)
682683
}
683684
}
684685

685-
// void ConvertToNativePath(ExtensionString& filename)
686-
// {
687-
// // Convert '/' to '\'
688-
// replace(filename.begin(), filename.end(), '/', '\\');
689-
// }
690-
691-
// void ConvertToUnixPath(ExtensionString& filename)
692-
// {
693-
// // Convert '\\' to '/'
694-
// replace(filename.begin(), filename.end(), '\\', '/');
695-
// }
696-
697686
// // Maps errors from errno.h to the brackets error codes
698687
// // found in brackets_extensions.js
699688
// int ConvertErrnoCode(int errorCode, bool isReading)
@@ -767,22 +756,22 @@ int ShowFolderInOSWindow(ExtensionString pathname)
767756

768757
int ConvertLinuxErrorCode(int errorCode, bool isReading)
769758
{
770-
// switch (errorCode) {
771-
// case NO_ERROR:
772-
// return NO_ERROR;
773-
// case ENOENT:
774-
// case ERROR_FILE_NOT_FOUND:
775-
// return ERR_NOT_FOUND;
776-
// case EACCESS:
777-
// return isReading ? ERR_CANT_READ : ERR_CANT_WRITE;
778-
// case ERROR_WRITE_PROTECT:
779-
// return ERR_CANT_WRITE;
780-
// case ERROR_HANDLE_DISK_FULL:
781-
// return ERR_OUT_OF_SPACE;
782-
// case ERROR_ALREADY_EXISTS:
783-
// return ERR_FILE_EXISTS;
784-
// default:
785-
// return ERR_UNKNOWN;
786-
// }
787-
return errorCode;
788-
}
759+
switch (errorCode) {
760+
case NO_ERROR:
761+
return NO_ERROR;
762+
case ENOENT:
763+
return ERR_NOT_FOUND;
764+
case EACCES:
765+
return isReading ? ERR_CANT_READ : ERR_CANT_WRITE;
766+
case ENOTDIR:
767+
return ERR_NOT_DIRECTORY;
768+
// case ERROR_WRITE_PROTECT:
769+
// return ERR_CANT_WRITE;
770+
// case ERROR_HANDLE_DISK_FULL:
771+
// return ERR_OUT_OF_SPACE;
772+
// case ERROR_ALREADY_EXISTS:
773+
// return ERR_FILE_EXISTS;
774+
default:
775+
return ERR_UNKNOWN;
776+
}
777+
}

appshell/cefclient_gtk.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ void TerminationSignalHandler(int signatl) {
3131
destroy();
3232
}
3333

34+
//Callback for File > Exit... menu item.
35+
gboolean ExitActivated(GtkWidget* widget) {
36+
destroy();
37+
}
38+
3439
// // Callback for Debug > Get Source... menu item.
3540
// gboolean GetSourceActivated(GtkWidget* widget) {
3641
// if (g_handler.get() && g_handler->GetBrowserId())
@@ -204,7 +209,10 @@ GtkWidget* CreateMenu(GtkWidget* menu_bar, const char* text) {
204209

205210
GtkWidget* CreateMenuBar() {
206211
GtkWidget* menu_bar = gtk_menu_bar_new();
207-
GtkWidget* debug_menu = CreateMenu(menu_bar, "Tests");
212+
GtkWidget* debug_menu = CreateMenu(menu_bar, "File");
213+
214+
AddMenuEntry(debug_menu, "Exit",
215+
G_CALLBACK(ExitActivated));
208216

209217
return menu_bar;
210218
}
@@ -361,4 +369,4 @@ CefString AppGetCachePath() {
361369
cachePath.append("/cef_data");
362370

363371
return CefString(cachePath);
364-
}
372+
}

appshell/client_app_gtk.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <string>
3434

3535
extern time_t g_appStartupTime;
36+
extern char _binary_appshell_appshell_extensions_js_start;
3637

3738
CefString ClientApp::GetCurrentLanguage()
3839
{
@@ -43,22 +44,25 @@ CefString ClientApp::GetCurrentLanguage()
4344

4445
std::string ClientApp::GetExtensionJSSource()
4546
{
46-
//Another bloody TODO here.
47-
std:: string extensionJSPath(AppGetSupportDirectory());
48-
extensionJSPath.append("/appshell_extensions.js");
49-
FILE* file = fopen(extensionJSPath.c_str(),"r");
50-
if(file == NULL)
51-
{
52-
return "";
53-
}
47+
//# We objcopy the appshell/appshell_extensions.js file, and link it directly into the binary.
48+
//# See http://www.linuxjournal.com/content/embedding-file-executable-aka-hello-world-version-5967
49+
const char* p = &_binary_appshell_appshell_extensions_js_start;
50+
std:: string content(p);
51+
// std:: string extensionJSPath(AppGetSupportDirectory());
52+
// extensionJSPath.append("/appshell_extensions.js");
53+
// FILE* file = fopen(extensionJSPath.c_str(),"r");
54+
// if(file == NULL)
55+
// {
56+
// return "";
57+
// }
5458

55-
fseek(file, 0, SEEK_END);
56-
long int size = ftell(file);
57-
rewind(file);
59+
// fseek(file, 0, SEEK_END);
60+
// long int size = ftell(file);
61+
// rewind(file);
5862

59-
char* content = (char*)calloc(size + 1, 1);
63+
// char* content = (char*)calloc(size + 1, 1);
6064

61-
fread(content,1,size,file);
65+
// fread(content,1,size,file);
6266

6367
return content;
6468
}

appshell_paths.gypi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,8 @@
156156
'appshell_bundle_resources_linux': [
157157
'$(BUILDTYPE)/locales',
158158
],
159+
'appshell_bundle_libraries_linux': [
160+
'$(BUILDTYPE)/lib.target/libcef.so',
161+
],
159162
},
160163
}

0 commit comments

Comments
 (0)