-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckWithXcode.js
More file actions
192 lines (167 loc) · 7.1 KB
/
checkWithXcode.js
File metadata and controls
192 lines (167 loc) · 7.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// ===================================================================
// Handler Function: checkWithXcode
// Builds Xcode projects with configurable options
// Fixed version - removes problematic shell script generation
// ===================================================================
// Import shared functions
const shared = require('sharedFunctions');
function taskLog(message) {
console.log(message);
stdOut.push(message);
}
/**
* Check and build project with Xcode using xcodebuild
* @param {Object} params - Command parameters
* @param {string} params.projectName - Name of the project (without .xcodeproj extension)
* @param {string} params.projectDir - Absolute path to the project directory
* @param {string} [params.scheme=""] - Scheme name (defaults to first scheme if empty)
* @param {string} [params.configuration="Debug"] - Build configuration (Debug/Release/Profile)
* @param {string} [params.platform="macosx"] - Target platform (macosx/iphoneos/iphonesimulator)
* @param {boolean} [params.clean=false] - Clean build before building
* @param {boolean} [params.showOperationLogs=false] - Show verbose operation logs
*/
function checkWithXcode(params) {
var projectName = params.projectName || "";
var projectDir = params.projectDir || "";
var dirValidation;
taskLog("=== Xcode Build Task ===");
taskLog("Project: " + projectName);
taskLog("Directory: " + projectDir);
// Validate input parameters
if (!projectDir) {
return shared.setErrorResult("Missing required parameter: projectDir", {
operation: "checkWithXcode"
});
}
dirValidation = shared.validateDirectoryPath(projectDir, "projectDir");
if (!dirValidation.ok) {
return shared.setErrorResult(dirValidation.message, {
operation: "checkWithXcode"
});
}
projectDir = dirValidation.value;
if (!MCPStudio.fileExists(projectDir)) {
return shared.setErrorResult("Project directory not found: " + projectDir, {
operation: "checkWithXcode",
path: projectDir
});
}
// Normalize project name (remove .xcodeproj extension if present)
projectName = projectName.replace(/\.xcodeproj$/i, "");
// Set default values from params
var scheme = params.scheme || "";
var configuration = params.configuration || "Debug";
var platform = params.platform || "macosx";
var codesign = params.codesign || params.codeSigningIdentity || "";
var cleanBuild = (params.clean === true);
var showOperationLogs = (params.showOperationLogs === true);
var alltargets = (params.alltargets === true);
taskLog("[Script] Scheme: " + scheme);
taskLog("[Script] Configuration: " + configuration);
taskLog("[Script] Platform: " + platform);
taskLog("[Script] Clean Build: " + cleanBuild);
taskLog("[Script] Show Operation Logs: " + showOperationLogs);
taskLog("[Script] Team Identifier: " + codesign);
var shellScript = '#!/bin/bash\n';
var success = false;
// get notified
shellScript += 'set -euo pipefail\n';
// Clean build artifacts if requested
if (cleanBuild) {
shellScript += '# Clean previous build artifacts\n';
shellScript += 'PROJECT_DIR=' + shared.quoteShellArgument(projectDir) + '\n';
shellScript += 'cd "${PROJECT_DIR}" || exit 1\n';
shellScript += 'rm -rf DerivedData/ || true\n\n';
shellScript += 'rm -rf build/DerivedData/ || true\n\n';
shellScript += 'rm -rf Build/DerivedData/ || true\n\n';
taskLog("[Script] Cleaning previous builds...");
success = MCPStudio.shell(shellScript);
if (!success) {
return shared.setErrorResult("Failed to clean build directory", {
operation: "checkWithXcode",
path: projectDir,
projectName: projectName
});
}
shellScript = '#!/bin/bash\n';
shellScript += 'set -euo pipefail\n';
}
shellScript += 'PROJECT_NAME=' + shared.quoteShellArgument(projectName) + '\n';
shellScript += 'PROJECT_DIR=' + shared.quoteShellArgument(projectDir) + '\n';
shellScript += 'ARCH=`uname -m`\n';
shellScript += 'cd "${PROJECT_DIR}" || exit 1\n';
shellScript += 'xcodebuild';
// Use only valid xcodebuild parameters
shellScript += ' -project "${PROJECT_NAME}.xcodeproj"';
/* additional xcodebuild params */
shellScript += ' -arch ${ARCH}';
if (alltargets === true) {
shellScript += ' -alltargets ';
}
if (codesign.length > 0) {
shellScript += ' --codeSigningIdentity ' + shared.quoteShellArgument(codesign);
}
if (scheme.length > 0) {
shellScript += ' -scheme ' + shared.quoteShellArgument(scheme);
}
if (platform.length > 0) {
shellScript += ' -sdk ' + shared.quoteShellArgument(platform);
}
// Fixed: check if configuration is not empty string instead of numeric comparison
if (configuration && configuration.length > 0) {
shellScript += ' -configuration ' + shared.quoteShellArgument(configuration);
}
/* end */
if (!codesign || codesign.length === 0) {
shellScript += ' CODE_SIGNING_ALLOWED=NO build || exit 1\n';
} else {
shellScript += ' build || exit 1\n';
}
shellScript += 'exit 0\n';
taskLog("[Script] Run: " + shellScript);
success = MCPStudio.shell(shellScript);
if (!success) {
MCPStudio.setToolResult(JSON.stringify({
text: "[Script] Build FAILED for " + projectName + "\n" +
(stdOut && stdOut.length > 0 ? stdOut.join("\n") : "") +
(stdErr && stdErr.length > 0 ? "\nErrors and Warnings:\n" + stdErr.join("\n") : ""),
metadata: {
path: projectDir,
projectName: projectName,
configuration: configuration,
platform: platform,
operation: "checkWithXcode",
codesign: codesign,
success: false,
stdout: stdOut,
stderr: stdErr,
}
}));
taskLog("[Script] Build failed!"+
(stdOut && stdOut.length > 0 ? stdOut.join("\n") : "") +
(stdErr && stdErr.length > 0 ? "\nErrors and Warnings:\n" + stdErr.join("\n") : ""));
}
else {
MCPStudio.setToolResult(JSON.stringify({
text: "Build completed successfully for " + projectName + "\n" +
(stdOut && stdOut.length > 0 ? stdOut.join("\n") : "") +
(stdErr && stdErr.length > 0 ? "\nErrors and Warnings:\n" + stdErr.join("\n") : ""),
metadata: {
path: projectDir,
projectName: projectName,
configuration: configuration,
platform: platform,
operation: "checkWithXcode",
codesign: codesign,
success: true,
stdout: stdOut,
stderr: stdErr,
}
}));
taskLog("[Script] Build successful!");
}
return null; // Result already set via MCPStudio.setToolResult
}
module.exports = {
checkWithXcode
};