-
-
Notifications
You must be signed in to change notification settings - Fork 304
Fix xcodemake log path generation #467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import { existsSync, readdirSync, statSync } from 'fs'; | |
| import * as path from 'path'; | ||
| import * as os from 'os'; | ||
| import * as fs from 'fs/promises'; | ||
| import { createHash } from 'crypto'; | ||
| import { getConfig } from './config-store.ts'; | ||
|
|
||
| let overriddenXcodemakePath: string | null = null; | ||
|
|
@@ -68,7 +69,7 @@ async function installXcodemake(): Promise<boolean> { | |
| } | ||
|
|
||
| const scriptContent = await response.text(); | ||
| await fs.writeFile(xcodemakePath, scriptContent, 'utf8'); | ||
| await fs.writeFile(xcodemakePath, patchXcodemakeScript(scriptContent), 'utf8'); | ||
|
|
||
| await fs.chmod(xcodemakePath, 0o755); | ||
| log('info', 'Made xcodemake executable'); | ||
|
|
@@ -125,12 +126,59 @@ export function doesMakefileExist(projectDir: string): boolean { | |
| return existsSync(`${projectDir}/Makefile`); | ||
| } | ||
|
|
||
| export function doesMakeLogFileExist(projectDir: string, command: string[]): boolean { | ||
| const originalDir = process.cwd(); | ||
| function sanitizeXcodemakeLogTag(args: string[]): string { | ||
| const sanitized = ['xcodemake', ...args] | ||
| .join('_') | ||
| .replace(/[/:]+/g, '_') | ||
| .replace(/[^\p{L}\p{N}._+=,@ -]+/gu, '_') | ||
| .replace(/\s+/g, '_') | ||
| .replace(/_+/g, '_') | ||
| .replace(/^_+|_+$/g, ''); | ||
|
|
||
| try { | ||
| process.chdir(projectDir); | ||
| return sanitized || 'xcodemake'; | ||
| } | ||
|
|
||
| function getXcodemakeLogFileName(args: string[]): string { | ||
| const logSuffix = `-${createHash('md5').update(args.join('\0')).digest('hex')}.log`; | ||
| const maxLogNameLength = 150; | ||
| const maxLogTagLength = Math.max(0, maxLogNameLength - logSuffix.length); | ||
| const logTag = sanitizeXcodemakeLogTag(args).slice(0, maxLogTagLength).replace(/_+$/g, ''); | ||
|
|
||
| return `${logTag || 'xcodemake'}${logSuffix}`; | ||
| } | ||
|
|
||
| function patchXcodemakeScript(scriptContent: string): string { | ||
| const patchedImports = scriptContent.includes('use Digest::MD5 qw(md5_hex);') | ||
| ? scriptContent | ||
| : scriptContent.replace('use IO::File;\n', 'use IO::File;\nuse Digest::MD5 qw(md5_hex);\n'); | ||
|
|
||
| return patchedImports | ||
| .replace( | ||
| 'my $log = "xcodemake @original_ARGV.log";', | ||
| `my $logTag = join "_", ("xcodemake", @original_ARGV); | ||
| $logTag =~ s{[/:]+}{_}g; | ||
| $logTag =~ s{[^[:alnum:]._+=,@ -]+}{_}g; | ||
| $logTag =~ s{\\s+}{_}g; | ||
| $logTag =~ s{_+}{_}g; | ||
| $logTag =~ s{^_+|_+$}{}g; | ||
| $logTag ||= "xcodemake"; | ||
| my $maxLogNameLength = 150; | ||
| my $logSuffix = "-" . md5_hex(join "\\0", @original_ARGV) . ".log"; | ||
| $logTag = substr($logTag, 0, $maxLogNameLength - length($logSuffix)); | ||
| $logTag =~ s{_+$}{}; | ||
| my $log = ($logTag || "xcodemake") . $logSuffix;`, | ||
| ) | ||
| .replaceAll( | ||
| `dollarEscape($make_dep_source); | ||
| unescape("'", $make_dep_source);`, | ||
| `dollarEscape($make_dep_source); | ||
| unescape("'", $make_dep_source); | ||
| escape(" ", $make_dep_source);`, | ||
| ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fragile patch leaves script unchangedMedium Severity
Reviewed by Cursor Bugbot for commit 5c0baf1. Configure here. |
||
| } | ||
|
|
||
| export function doesMakeLogFileExist(projectDir: string, command: string[]): boolean { | ||
| try { | ||
| const xcodemakeCommand = ['xcodemake', ...command.slice(1)]; | ||
| const escapedCommand = xcodemakeCommand.map((arg) => { | ||
| // Remove projectDir from arguments if present at the start | ||
|
|
@@ -140,11 +188,10 @@ export function doesMakeLogFileExist(projectDir: string, command: string[]): boo | |
| } | ||
| return arg; | ||
| }); | ||
| const commandString = escapedCommand.join(' '); | ||
| const logFileName = `${commandString}.log`; | ||
| log('debug', `Checking for Makefile log: ${logFileName} in directory: ${process.cwd()}`); | ||
| const logFileName = getXcodemakeLogFileName(escapedCommand.slice(1)); | ||
| log('debug', `Checking for Makefile log: ${logFileName} in directory: ${projectDir}`); | ||
|
|
||
| const files = readdirSync('.'); | ||
| const files = readdirSync(projectDir); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PATH xcodemake log name mismatchMedium Severity
Additional Locations (1)Reviewed by Cursor Bugbot for commit 5c0baf1. Configure here. |
||
| const exists = files.includes(logFileName); | ||
| log('debug', `Makefile log ${exists ? 'exists' : 'does not exist'}: ${logFileName}`); | ||
| return exists; | ||
|
|
@@ -154,8 +201,6 @@ export function doesMakeLogFileExist(projectDir: string, command: string[]): boo | |
| `Error checking for Makefile log: ${error instanceof Error ? error.message : String(error)}`, | ||
| ); | ||
| return false; | ||
| } finally { | ||
| process.chdir(originalDir); | ||
| } | ||
| } | ||
|
|
||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The TypeScript code uses a Unicode-aware regex to sanitize log file names, while the patched Perl script uses
[:alnum:], which may not handle Unicode correctly without explicit UTF-8 mode, causing a mismatch.Severity: LOW
Suggested Fix
To ensure consistent behavior across different environments, add
use utf8;oruse feature 'unicode_strings';to the beginning of the patched Perl script. This will guarantee that the[:alnum:]character class correctly handles Unicode characters, aligning its behavior with the TypeScript implementation.Prompt for AI Agent
Also affects:
src/utils/xcodemake.ts:160~161Did we get this right? 👍 / 👎 to inform future reviews.