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

Commit 5400cc2

Browse files
committed
[[ Bug 19658 ]] Make CEF work in Linux
This patch changes the layout of the CEF files so that things will run from the -bin folder when building from source, from the IDE and in Standalones.
1 parent aaa43ad commit 5400cc2

File tree

6 files changed

+107
-14
lines changed

6 files changed

+107
-14
lines changed

Installer/package.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,7 @@ component Externals.MacOSX
721721
//////////
722722

723723
component Externals.CEF.Linux
724-
into [[TargetFolder]]/Externals/CEF place
725-
executable linux-[[TargetArchitecture]]:revbrowser-cefprocess
726-
executable linux-[[TargetArchitecture]]:libbrowser-cefprocess
724+
into [[TargetFolder]]/CEF place
727725
executable linux-[[TargetArchitecture]]:CEF/libcef.so
728726
executable linux-[[TargetArchitecture]]:CEF/libffmpegsumo.so
729727
executable linux-[[TargetArchitecture]]:CEF/libpdf.so
@@ -732,9 +730,6 @@ component Externals.CEF.Linux
732730
file linux-[[TargetArchitecture]]:CEF/cef_100_percent.pak
733731
file linux-[[TargetArchitecture]]:CEF/cef_200_percent.pak
734732
file linux-[[TargetArchitecture]]:CEF/cef_extensions.pak
735-
file linux-[[TargetArchitecture]]:CEF/icudtl.dat
736-
file linux-[[TargetArchitecture]]:CEF/natives_blob.bin
737-
file linux-[[TargetArchitecture]]:CEF/snapshot_blob.bin
738733
// Horrible workaround for a libCEF bug
739734
into [[TargetFolder]] place
740735
file linux-[[TargetArchitecture]]:CEF/icudtl.dat

ide-support/revsaveasstandalone.livecodescript

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,7 +2255,7 @@ private command revCopyCEFResources pPlatform, pStandalonePath, pCopyRevBrowserR
22552255
revAddMapping pPlatform, "CEF/libcef", "Externals/CEF/libcef"
22562256
break
22572257
case pPlatform contains "Linux"
2258-
put tCurrentLocation & slash & "Externals/CEF" into tCEFDest
2258+
put tCurrentLocation & slash & "CEF" into tCEFDest
22592259

22602260
revSBEnsureFolder tCEFDest
22612261
if the result is not empty then
@@ -2296,12 +2296,12 @@ private command revCopyCEFResources pPlatform, pStandalonePath, pCopyRevBrowserR
22962296
end if
22972297

22982298
repeat for each line tCEFFile in tCEFFiles
2299-
revSBCopyFileToFolder tCefResources & slash & tCEFFile, tCurrentLocation, "revStandaloneProgressCallback", the long id of me
2299+
revSBCopyFileToFolder tCefResources & slash & ".." & slash & tCEFFile, tCurrentLocation, "revStandaloneProgressCallback", the long id of me
23002300
if the result is not empty then
23012301
revStandaloneAddWarning "Linux, external failed to copy:" && quote & tCefResources & slash & tCEFFile & quote
23022302
end if
23032303
end repeat
2304-
revAddMapping pPlatform, "CEF/libcef", "Externals/CEF/libcef"
2304+
--revAddMapping pPlatform, "CEF/libcef", "Externals/CEF/libcef"
23052305
break
23062306
default
23072307
break

libbrowser/libbrowser.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@
306306
'ldflags':
307307
[
308308
'-Wl,--allow-shlib-undefined',
309-
'-Wl,-rpath=\\$$ORIGIN',
309+
'-Wl,-rpath=\\$$ORIGIN/CEF',
310310
],
311311
},
312312
],

libbrowser/src/libbrowser_cef.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,101 @@ static const char *kCefPathSeparatorStr = "/";
316316
static const char kCefPathSeparator = '/';
317317
#endif
318318

319+
#if defined(TARGET_PLATFORM_LINUX)
320+
321+
#include <sys/types.h>
322+
#include <sys/stat.h>
323+
#include <unistd.h>
324+
325+
////////////////////////////////////////////////////////////////////////////////
326+
327+
static bool get_link_size(const char *p_path, uint32_t &r_size)
328+
{
329+
if (p_path == nil)
330+
return false;
331+
332+
struct stat t_stat;
333+
if (lstat(p_path, &t_stat) == -1)
334+
return false;
335+
336+
r_size = t_stat.st_size;
337+
return true;
338+
}
339+
340+
static bool get_link_path(const char *p_link, char *&r_path)
341+
{
342+
bool t_success;
343+
t_success = true;
344+
345+
char *t_buffer;
346+
t_buffer = nil;
347+
uint32_t t_buffer_size;
348+
t_buffer_size = 0;
349+
350+
uint32_t t_link_size;
351+
t_success = get_link_size(p_link, t_link_size);
352+
353+
while (t_success && t_link_size + 1 > t_buffer_size)
354+
{
355+
t_buffer_size = t_link_size + 1;
356+
t_success = MCBrowserMemoryReallocate(t_buffer, t_buffer_size, t_buffer);
357+
358+
if (t_success)
359+
{
360+
int32_t t_read;
361+
t_read = readlink(p_link, t_buffer, t_buffer_size);
362+
363+
t_success = t_read >= 0;
364+
t_link_size = t_read;
365+
}
366+
}
367+
368+
if (t_success)
369+
{
370+
t_buffer[t_link_size] = '\0';
371+
r_path = t_buffer;
372+
}
373+
else
374+
MCBrowserMemoryDeallocate(t_buffer);
375+
376+
return t_success;
377+
}
378+
379+
static bool get_exe_path_from_proc_fs(char *&r_path)
380+
{
381+
return get_link_path("/proc/self/exe", r_path);
382+
}
383+
384+
//////////
385+
386+
const char *__MCCefPlatformGetExecutableFolder(void)
387+
{
388+
static char *s_exe_path = nil;
389+
390+
if (s_exe_path == nil)
391+
{
392+
bool t_success;
393+
t_success = get_exe_path_from_proc_fs(s_exe_path);
394+
if (t_success)
395+
{
396+
// remove library component from path
397+
uint32_t t_index;
398+
if (MCCStringLastIndexOf(s_exe_path, '/', t_index))
399+
s_exe_path[t_index] = '\0';
400+
}
401+
}
402+
403+
return s_exe_path;
404+
}
405+
#endif
406+
319407
static bool __MCCefGetLibraryPath(char*& r_path)
320408
{
321409
void *t_module = nullptr;
410+
/* TODO[Bug 19381] Try libcef in the root folder to to workaround
411+
* placement issues on Linux. */
412+
/*if (t_module == nullptr)
413+
t_module = MCSupportLibraryLoad("./libcef");*/
322414
if (t_module == nullptr)
323415
t_module = MCSupportLibraryLoad("./CEF/libcef");
324416
/* TODO[Bug 19381] On Linux and Windows, the in-git-checkout
@@ -408,8 +500,14 @@ bool MCCefInitialise(void)
408500
t_settings.log_severity = LOGSEVERITY_DISABLE;
409501

410502
bool t_success = true;
503+
#ifdef TARGET_PLATFORM_LINUX
504+
if (t_success)
505+
t_success = __MCCefBuildPath(__MCCefPlatformGetExecutableFolder(), kCefProcessName, &t_settings.browser_subprocess_path);
506+
#else
411507
if (t_success)
412508
t_success = __MCCefBuildPath(t_library_path, kCefProcessName, &t_settings.browser_subprocess_path);
509+
#endif
510+
413511
if (t_success)
414512
t_success = __MCCefBuildPath(t_library_path, "locales", &t_settings.locales_dir_path);
415513
if (t_success)

prebuilt/libcef.gyp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@
130130
'destination': '<(PRODUCT_DIR)/',
131131
'files':
132132
[
133-
'lib/linux/<(target_arch)/CEF/natives_blob.bin',
134-
'lib/linux/<(target_arch)/CEF/snapshot_blob.bin',
135-
'lib/linux/<(target_arch)/CEF/icudtl.dat',
133+
'lib/linux/<(target_arch)/natives_blob.bin',
134+
'lib/linux/<(target_arch)/snapshot_blob.bin',
135+
'lib/linux/<(target_arch)/icudtl.dat',
136136
],
137137
},
138138
{

revbrowser/revbrowser.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
'copies':
134134
[
135135
{
136-
'destination':'<(PRODUCT_DIR)/CEF/',
136+
'destination':'<(PRODUCT_DIR)/',
137137
'files':
138138
[
139139
'<(PRODUCT_DIR)/revbrowser-cefprocess',

0 commit comments

Comments
 (0)