Skip to content

Commit cdf3644

Browse files
committed
[[ Bug 19197 ]] Add script-only capsule section types
1 parent 8cfb0af commit cdf3644

File tree

7 files changed

+130
-7
lines changed

7 files changed

+130
-7
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Script-only deploy
2+
It is now possible to use script-only stacks in the mainstack and auxiliary
3+
stack parameters to the deploy command.

engine/src/capsule.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@ enum MCCapsuleSectionType
7070
// including the digest section tag.
7171
kMCCapsuleSectionTypeDigest,
7272

73-
// The stack section contains the principal stackfile to be loaded on
73+
// The stack section contains the principal (binary) stackfile to be loaded on
7474
// startup.
75-
kMCCapsuleSectionTypeStack,
75+
kMCCapsuleSectionTypeMainStack,
7676

77+
// The stack section contains the principal (script-only) stackfile to be loaded on
78+
// startup.
79+
kMCCapsuleSectionTypeScriptOnlyMainStack,
80+
7781
// An external section contains a external that should be loaded into the
7882
// environment on startup;.
7983
kMCCapsuleSectionTypeExternal,
@@ -84,6 +88,10 @@ enum MCCapsuleSectionType
8488
// Auxiliary stack sections contain other mainstacks that should be loaded
8589
// alongside the mainstack (but not opened initially).
8690
kMCCapsuleSectionTypeAuxiliaryStack,
91+
92+
// Script-only auxiliary stack sections contain other (script-only) mainstacks that should be loaded
93+
// alongside the mainstack (but not opened initially).
94+
kMCCapsuleSectionTypeScriptOnlyAuxiliaryStack,
8795

8896
// Simulator redirect sections contain mappings from engine relative
8997
// paths to absolute paths on the host system.

engine/src/deploy.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,48 @@ static bool MCDeployWriteCapsuleDefineStandaloneSections(const MCDeployParameter
443443
return t_success;
444444
}
445445

446+
static bool MCDeployCapsuleDefineFromStackFile(MCDeployCapsuleRef p_self, MCStringRef p_filename, MCDeployFileRef p_file, bool p_mainstack)
447+
{
448+
MCAutoDataRef t_contents;
449+
if (!MCS_loadbinaryfile(p_filename, &t_contents))
450+
return false;
451+
452+
IO_handle t_stream = nil;
453+
t_stream = MCS_fakeopen(MCDataGetBytePtr(*t_contents),MCDataGetLength(*t_contents));
454+
455+
if (t_stream == nil)
456+
return false;
457+
458+
bool t_script_only = MCdispatcher -> streamstackisscriptonly(t_stream);
459+
MCS_close(t_stream);
460+
461+
MCCapsuleSectionType t_type;
462+
if (p_mainstack)
463+
{
464+
if (t_script_only)
465+
{
466+
t_type = kMCCapsuleSectionTypeScriptOnlyMainStack;
467+
}
468+
else
469+
{
470+
t_type = kMCCapsuleSectionTypeMainStack;
471+
}
472+
}
473+
else
474+
{
475+
if (t_script_only)
476+
{
477+
t_type = kMCCapsuleSectionTypeScriptOnlyAuxiliaryStack;
478+
}
479+
else
480+
{
481+
t_type = kMCCapsuleSectionTypeAuxiliaryStack;
482+
}
483+
}
484+
485+
return MCDeployCapsuleDefineFromFile(p_self, t_type, p_file);
486+
}
487+
446488
// This method constructs and then writes out a capsule to the given output file.
447489
// The capsule contents is derived from the deploy parameters structure.
448490
// The offset in the file after writing is returned in x_offset.
@@ -514,7 +556,7 @@ bool MCDeployWriteCapsule(const MCDeployParameters& p_params, MCDeployFileRef p_
514556

515557
// Now we add the main stack
516558
if (t_success)
517-
t_success = MCDeployCapsuleDefineFromFile(t_capsule, kMCCapsuleSectionTypeStack, t_stackfile);
559+
t_success = MCDeployCapsuleDefineFromStackFile(t_capsule, p_params . stackfile, t_stackfile, true);
518560

519561
// Now we add the auxillary stackfiles, if any
520562
MCAutoArray<MCDeployFileRef> t_aux_stackfiles;
@@ -528,7 +570,7 @@ bool MCDeployWriteCapsule(const MCDeployParameters& p_params, MCDeployFileRef p_
528570
if (t_success && !MCDeployFileOpen((MCStringRef)t_val, kMCOpenFileModeRead, t_aux_stackfiles[i]))
529571
t_success = MCDeployThrow(kMCDeployErrorNoAuxStackfile);
530572
if (t_success)
531-
t_success = MCDeployCapsuleDefineFromFile(t_capsule, kMCCapsuleSectionTypeAuxiliaryStack, t_aux_stackfiles[i]);
573+
t_success = MCDeployCapsuleDefineFromStackFile(t_capsule, (MCStringRef)t_val, t_aux_stackfiles[i], false);
532574
}
533575

534576
// AL-2015-02-10: [[ Standalone Inclusions ]] Add the resource mappings, if any.

engine/src/dispatch.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@ IO_stat readheader(IO_handle& stream, uint32_t& r_version)
448448
return IO_NORMAL;
449449
}
450450

451+
bool MCDispatch::streamstackisscriptonly(IO_handle stream)
452+
{
453+
uint32_t t_version;
454+
return readheader(stream, t_version) != IO_NORMAL;
455+
}
456+
451457
// This method reads a stack from the given stream. The stack is set to
452458
// have parent MCDispatch, and filename MCcmd. It is designed to be used
453459
// for embedded stacks/deployed stacks/revlet stacks.

engine/src/dispatch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ class MCDispatch : public MCObject
292292
MCStack* &r_stack,
293293
const char* &r_result);
294294

295+
// Determine if the stream contains a script-only stack
296+
bool streamstackisscriptonly(IO_handle stream);
297+
295298
// Integrate a loaded stack into the environemnt, sending reloadStack
296299
// if required.
297300
void processstack(MCStringRef p_openpath, MCStack* &x_stack);

engine/src/mode_installer.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ bool MCStandaloneCapsuleCallback(void *p_self, const uint8_t *p_digest, MCCapsul
11871187
}
11881188
break;
11891189

1190-
case kMCCapsuleSectionTypeStack:
1190+
case kMCCapsuleSectionTypeMainStack:
11911191
if (MCdispatcher -> readstartupstack(p_stream, self -> stack) != IO_NORMAL)
11921192
{
11931193
MCresult -> sets("failed to read project stack");
@@ -1198,6 +1198,18 @@ bool MCStandaloneCapsuleCallback(void *p_self, const uint8_t *p_digest, MCCapsul
11981198
// the startup script and such work.
11991199
MCstaticdefaultstackptr = MCdefaultstackptr = self -> stack;
12001200
break;
1201+
1202+
case kMCCapsuleSectionTypeScriptOnlyMainStack:
1203+
if (MCdispatcher -> readscriptonlystartupstack(p_stream, p_length, self -> stack) != IO_NORMAL)
1204+
{
1205+
MCresult -> sets("failed to read project stack");
1206+
return false;
1207+
}
1208+
1209+
// MW-2012-10-25: [[ Bug ]] Make sure we set these to the main stack so that
1210+
// the startup script and such work.
1211+
MCstaticdefaultstackptr = MCdefaultstackptr = self -> stack;
1212+
break;
12011213

12021214
case kMCCapsuleSectionTypeDigest:
12031215
uint8_t t_read_digest[16];
@@ -1248,6 +1260,24 @@ bool MCStandaloneCapsuleCallback(void *p_self, const uint8_t *p_digest, MCCapsul
12481260
MCdispatcher -> processstack(kMCEmptyString, t_aux_stack);
12491261
}
12501262
break;
1263+
1264+
case kMCCapsuleSectionTypeScriptOnlyAuxiliaryStack:
1265+
{
1266+
MCStack *t_aux_stack;
1267+
const char *t_result;
1268+
if (MCdispatcher -> trytoreadscriptonlystackofsize(kMCEmptyString,
1269+
p_stream,
1270+
p_length,
1271+
nullptr,
1272+
t_aux_stack,
1273+
t_result)
1274+
!= IO_NORMAL)
1275+
{
1276+
MCresult -> sets("failed to read auxillary stack");
1277+
return false;
1278+
}
1279+
}
1280+
break;
12511281

12521282
case kMCCapsuleSectionTypeLicense:
12531283
{

engine/src/mode_standalone.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ bool MCStandaloneCapsuleCallback(void *p_self, const uint8_t *p_digest, MCCapsul
259259
}
260260
break;
261261

262-
case kMCCapsuleSectionTypeStack:
262+
case kMCCapsuleSectionTypeMainStack:
263263
if (MCdispatcher -> readstartupstack(p_stream, self -> stack) != IO_NORMAL)
264264
{
265265
MCresult -> sets("failed to read standalone stack");
@@ -270,7 +270,19 @@ bool MCStandaloneCapsuleCallback(void *p_self, const uint8_t *p_digest, MCCapsul
270270
// the startup script and such work.
271271
MCstaticdefaultstackptr = MCdefaultstackptr = self -> stack;
272272
break;
273-
273+
274+
case kMCCapsuleSectionTypeScriptOnlyMainStack:
275+
if (MCdispatcher -> readscriptonlystartupstack(p_stream, p_length, self -> stack) != IO_NORMAL)
276+
{
277+
MCresult -> sets("failed to read standalone stack");
278+
return false;
279+
}
280+
281+
// MW-2012-10-25: [[ Bug ]] Make sure we set these to the main stack so that
282+
// the startup script and such work.
283+
MCstaticdefaultstackptr = MCdefaultstackptr = self -> stack;
284+
break;
285+
274286
case kMCCapsuleSectionTypeExternal:
275287
{
276288
MCAutoStringRef t_external_str;
@@ -332,6 +344,25 @@ bool MCStandaloneCapsuleCallback(void *p_self, const uint8_t *p_digest, MCCapsul
332344
MCdispatcher -> processstack(kMCEmptyString, t_aux_stack);
333345
}
334346
break;
347+
348+
case kMCCapsuleSectionTypeScriptOnlyAuxiliaryStack:
349+
{
350+
MCStack *t_aux_stack;
351+
const char *t_result;
352+
if (MCdispatcher -> trytoreadscriptonlystackofsize(kMCEmptyString,
353+
p_stream,
354+
p_length,
355+
nullptr,
356+
t_aux_stack,
357+
t_result)
358+
!= IO_NORMAL)
359+
{
360+
MCresult -> sets("failed to read auxillary stack");
361+
return false;
362+
}
363+
MCdispatcher -> processstack(kMCEmptyString, t_aux_stack);
364+
}
365+
break;
335366

336367
case kMCCapsuleSectionTypeModule:
337368
{

0 commit comments

Comments
 (0)