Skip to content

Commit 7d652dc

Browse files
committed
[emscripten] Add emscripten deploy command.
Prepares a stack for use as an HTML5 standalone's startup stack. Loads the stack, applies an edition-dependent transformation, and then saves it back to disk.
1 parent c3184b3 commit 7d652dc

9 files changed

Lines changed: 100 additions & 0 deletions

File tree

engine/engine-sources.gypi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@
782782
'src/deploy.cpp',
783783
'src/deploy_capsule.cpp',
784784
'src/deploy_dmg.cpp',
785+
'src/deploy_emscripten.cpp',
785786
'src/deploy_file.cpp',
786787
'src/deploy_linux.cpp',
787788
'src/deploy_macosx.cpp',

engine/src/deploy.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,8 @@ Parse_stat MCIdeDeploy::parse(MCScriptPoint& sp)
607607
m_platform = PLATFORM_IOS_EMBEDDED;
608608
else if (sp . token_is_cstring("androidembedded"))
609609
m_platform = PLATFORM_ANDROID_EMBEDDED;
610+
else if (sp . token_is_cstring("emscripten"))
611+
m_platform = PLATFORM_EMSCRIPTEN;
610612
else
611613
return PS_ERROR;
612614
}
@@ -662,6 +664,8 @@ void MCIdeDeploy::exec_ctxt(MCExecContext& ctxt)
662664
t_is_licensed = (MClicenseparameters . deploy_targets & kMCLicenseDeployToIOSEmbedded) != 0;
663665
else if (m_platform == PLATFORM_ANDROID_EMBEDDED)
664666
t_is_licensed = (MClicenseparameters . deploy_targets & kMCLicenseDeployToAndroidEmbedded) != 0;
667+
else if (m_platform == PLATFORM_EMSCRIPTEN)
668+
t_is_licensed = (MClicenseparameters . deploy_targets & kMCLicenseDeployToHTML5) != 0;
665669

666670
if (!t_is_licensed)
667671
{
@@ -684,6 +688,8 @@ void MCIdeDeploy::exec_ctxt(MCExecContext& ctxt)
684688
MCDeployToAndroid(t_params);
685689
else if (m_platform == PLATFORM_IOS_EMBEDDED)
686690
MCDeployToIOS(t_params, true);
691+
else if (m_platform == PLATFORM_EMSCRIPTEN)
692+
MCDeployToEmscripten(t_params);
687693

688694
MCDeployError t_error;
689695
t_error = MCDeployCatch();

engine/src/deploy.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ Exec_stat MCDeployToLinux(const MCDeployParameters& p_params);
166166
Exec_stat MCDeployToMacOSX(const MCDeployParameters& p_params);
167167
Exec_stat MCDeployToIOS(const MCDeployParameters& p_params, bool embedded);
168168
Exec_stat MCDeployToAndroid(const MCDeployParameters& p_params);
169+
Exec_stat MCDeployToEmscripten(const MCDeployParameters& p_params);
169170

170171
////////////////////////////////////////////////////////////////////////////////
171172

@@ -430,6 +431,9 @@ enum MCDeployError
430431
kMCDeployErrorMacOSXBadCpuType,
431432
kMCDeployErrorMacOSXBadTarget,
432433

434+
/* An error occurred while creating the startup stack */
435+
kMCDeployErrorEmscriptenBadStack,
436+
433437
// SIGN ERRORS
434438

435439
kMCDeployErrorNoCertificate,

engine/src/deploy_emscripten.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* -*-c++-*-
2+
3+
Copyright (C) 2003-2015 LiveCode Ltd.
4+
5+
This file is part of LiveCode.
6+
7+
LiveCode is free software; you can redistribute it and/or modify it under
8+
the terms of the GNU General Public License v3 as published by the Free
9+
Software Foundation.
10+
11+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
12+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
18+
19+
#include "prefix.h"
20+
21+
#include "parsedef.h"
22+
#include "filedefs.h"
23+
24+
#include "dispatch.h"
25+
#include "stacksecurity.h"
26+
27+
#include "deploy.h"
28+
29+
Exec_stat
30+
MCDeployToEmscripten(const MCDeployParameters & p_params)
31+
{
32+
MCStack *t_startup_stack = nil;
33+
34+
/* Load the startup stack */
35+
if (IO_NORMAL != MCdispatcher->loadfile(p_params.output, t_startup_stack))
36+
{
37+
MCDeployThrow(kMCDeployErrorBadRead);
38+
goto error_cleanup;
39+
}
40+
41+
/* Prepare the startup stack for use during engine boot */
42+
if (!MCStackSecurityEmscriptenPrepareStartupStack(t_startup_stack))
43+
{
44+
MCDeployThrow(kMCDeployErrorEmscriptenBadStack);
45+
goto error_cleanup;
46+
}
47+
48+
/* Save the stack back to disk */
49+
if (IO_NORMAL != MCdispatcher->savestack(t_startup_stack, p_params.output))
50+
{
51+
MCDeployThrow(kMCDeployErrorBadWrite);
52+
goto error_cleanup;
53+
}
54+
55+
/* Clean up */
56+
delete t_startup_stack;
57+
58+
return ES_NORMAL;
59+
60+
error_cleanup:
61+
if (nil != t_startup_stack)
62+
{
63+
delete t_startup_stack;
64+
}
65+
66+
return ES_ERROR;
67+
}

engine/src/deploy_file.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ const char *MCDeployErrorToString(MCDeployError p_error)
311311
case kMCDeployErrorMacOSXBadTarget:
312312
return "invalid mac/ios standalone engine file";
313313

314+
case kMCDeployErrorEmscriptenBadStack:
315+
return "could not prepare startup stack";
316+
314317
case kMCDeployErrorNoCertificate:
315318
return "could not load certificate";
316319
case kMCDeployErrorBadCertificate:

engine/src/ide.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ class MCIdeDeploy: public MCStatement
246246

247247
PLATFORM_IOS_EMBEDDED,
248248
PLATFORM_ANDROID_EMBEDDED,
249+
250+
PLATFORM_EMSCRIPTEN,
249251

250252
PLATFORM_SERVER,
251253
};

engine/src/mode_development.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,7 @@ Exec_stat MCProperty::mode_set(MCExecPoint& ep)
10061006
{ "server", kMCLicenseDeployToServer },
10071007
{ "ios-embedded", kMCLicenseDeployToIOSEmbedded },
10081008
{ "android-embedded", kMCLicenseDeployToIOSEmbedded },
1009+
{ "html5", kMCLicenseDeployToHTML5 },
10091010
};
10101011

10111012
MClicenseparameters . deploy_targets = 0;

engine/src/stacksecurity.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,16 @@ IO_stat MCStackSecurityRead(char *r_string, uint32_t p_length, IO_handle p_strea
108108
void MCStackSecurityProcessCapsule(void *p_start, void *p_finish)
109109
{
110110
}
111+
////////////////////////////////////////////////////////////////////////////////
112+
113+
/* ================================================================
114+
* Emscripten standalone deployment
115+
* ================================================================ */
116+
117+
bool
118+
MCStackSecurityEmscriptenPrepareStartupStack(MCStack *r_stack)
119+
{
120+
return true;
121+
}
111122

112123
////////////////////////////////////////////////////////////////////////////////

engine/src/stacksecurity.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ IO_stat MCStackSecurityRead(char *r_string, uint32_t p_length, IO_handle p_strea
5050

5151
void MCStackSecurityProcessCapsule(void *p_start, void *p_finish);
5252

53+
//////////
54+
55+
/* Create a startup stack for an Emscripten standalone. */
56+
bool MCStackSecurityEmscriptenPrepareStartupStack(MCStack *r_stack);
57+
5358
////////////////////////////////////////////////////////////////////////////////
5459

5560
#endif

0 commit comments

Comments
 (0)