Skip to content

Commit bbf63d1

Browse files
DadoumAdam-le-dev
authored andcommitted
Add options to disable multithreading to the CLI.
1 parent 92c38fc commit bbf63d1

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

frontends/cli/source/cli_frontend.d

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import std.array;
66
import std.datetime;
77
import std.exception;
88
import std.format;
9+
import std.parallelism;
910
import std.path;
1011
import std.process;
1112
import std.stdio;
@@ -225,6 +226,7 @@ int entryPoint(Commands commands)
225226
setlocale(LC_ALL, "");
226227
}
227228

229+
defaultPoolThreads = commands.threadCount;
228230
configureLoggingProvider(new shared DefaultProvider(true, commands.debug_ ? Levels.DEBUG : Levels.INFO));
229231

230232
try
@@ -252,6 +254,9 @@ struct Commands
252254
@(NamedArgument("d", "debug").Description("Enable debug logging"))
253255
bool debug_;
254256

257+
@(NamedArgument("thread-count").Description("Numbers of threads to be used for signing the application bundle"))
258+
uint threadCount = uint.max;
259+
255260
@SubCommands
256261
SumType!(AppIdCommand, CertificateCommand, InstallCommand, SignCommand, TeamCommand, ToolCommand, VersionCommand) cmd;
257262
}

frontends/cli/source/install.d

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ struct InstallCommand
2424
@(NamedArgument("udid").Description("UDID of the device (if multiple are available)."))
2525
string udid = null;
2626

27+
@(NamedArgument("singlethread").Description("Run the signature process on a single thread. Sacrifices speed for more consistency."))
28+
bool singlethreaded;
29+
2730
int opCall()
2831
{
2932
Application app = openApp(appPath);
@@ -67,7 +70,7 @@ struct InstallCommand
6770
message = action;
6871
progressBar.index = cast(int) (progress * 100);
6972
progressBar.update();
70-
});
73+
}, !singlethreaded);
7174
progressBar.finish();
7275

7376
return 0;

frontends/cli/source/sign.d

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ struct SignCommand
2828
@(NamedArgument("m", "provision").Description("App's provisioning certificate.").Required())
2929
string mobileProvisionPath;
3030

31+
@(NamedArgument("singlethread").Description("Run the signature process on a single thread. Sacrifices speed for more consistency."))
32+
bool singlethreaded;
33+
3134
@(PositionalArgument(0, "app path").Description("App path."))
3235
string appFolder;
3336

@@ -54,11 +57,12 @@ struct SignCommand
5457
sideloadSign(
5558
app,
5659
new CertificateIdentity(certificate, privateKey),
57-
[app.bundleIdentifier(): ProvisioningProfile("", "", mobileProvisionFile)], // TODO make a better ctor
58-
(p) {
60+
[app.bundleIdentifier(): ProvisioningProfile("", "", mobileProvisionFile)], // TODO make a better ctor
61+
(p) {
5962
progressBar.index = cast(int) (progress += p * 100);
6063
progressBar.update();
61-
}
64+
},
65+
!singlethreaded
6266
);
6367
progressBar.finish();
6468

source/sideload/package.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void sideloadFull(
3030
DeveloperSession developer,
3131
Application app,
3232
void delegate(double progress, string action) progressCallback,
33+
bool isMultithreaded = true,
3334
) {
3435
enum STEP_COUNT = 9.0;
3536
auto log = getLogger();

source/sideload/sign.d

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Tuple!(PlistDict, PlistDict) sign(
3333
CertificateIdentity identity,
3434
ProvisioningProfile[string] provisioningProfiles,
3535
void delegate(double progress) addProgress,
36+
bool isMultithreaded = true,
3637
string teamId = null,
3738
MDxHashFunction sha1Hasher = null,
3839
MDxHashFunction sha2Hasher = null,
@@ -83,12 +84,13 @@ Tuple!(PlistDict, PlistDict) sign(
8384
size_t stepCount = subBundles.length + 2;
8485
const double stepSize = 1.0 / stepCount;
8586

86-
auto subBundlesTask = task({
87+
void signSubBundles() {
8788
foreach (subBundle; parallel(subBundles)) {
8889
auto bundleFiles = subBundle.sign(
8990
identity,
9091
provisioningProfiles,
91-
(double progress) => addProgress(progress * stepSize),
92+
(double progress) => addProgress(progress * stepSize),
93+
isMultithreaded,
9294
teamId,
9395
sha1HasherParallel.get(),
9496
sha2HasherParallel.get()
@@ -144,8 +146,13 @@ Tuple!(PlistDict, PlistDict) sign(
144146
addFile("_CodeSignature".buildPath("CodeResources"));
145147
addFile(subBundle.appInfo["CFBundleExecutable"].str().native());
146148
}
147-
});
148-
subBundlesTask.executeInNewThread();
149+
}
150+
151+
typeof(task(&signSubBundles)) subBundlesTask;
152+
if (isMultithreaded) {
153+
subBundlesTask = task(&signSubBundles);
154+
subBundlesTask.executeInNewThread();
155+
}
149156

150157
log.debugF!"Signing bundle %s..."(baseName(bundleFolder));
151158

@@ -242,7 +249,9 @@ Tuple!(PlistDict, PlistDict) sign(
242249
// too lazy yet to add better progress tracking
243250
addProgress(stepSize);
244251

245-
subBundlesTask.yieldForce();
252+
if (isMultithreaded) {
253+
subBundlesTask.yieldForce();
254+
}
246255

247256
log.debug_("Making CodeResources...");
248257
string codeResources = dict(

0 commit comments

Comments
 (0)