-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use xcresulttool as a special case reader in readDirectory
- Loading branch information
Showing
3 changed files
with
110 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { lstat } from "node:fs/promises"; | ||
import { platform } from "node:os"; | ||
import path from "node:path"; | ||
import { invokeStdoutCliTool } from "../toolRunner.js"; | ||
import { isDefined } from "../validation.js"; | ||
|
||
const XCODE_INSTALL_URL = | ||
"https://developer.apple.com/documentation/safari-developer-tools/installing-xcode-and-simulators"; | ||
|
||
const XCODE_SWITCH_COMMAND = "sudo xcode-select -s /Applications/Xcode.app/Contents/Developer"; | ||
|
||
export const XCRESULTTOOL_MISSING_MESSAGE = `xcresulttool is required to parse Xcode Result bundles, but we can't access it on this machine. | ||
This tool is a part of Xcode. Please make sure Xcode is installed. Visit this page to learn more about the installation:\n | ||
${XCODE_INSTALL_URL} | ||
Note that xcresulttool doesn't come with Command Line Tools for Xcode. You need the full Xcode package to get it. If you have both | ||
installed, make sure the full installation is selected. If it's not, switch it with xcode-select. For example: | ||
${XCODE_SWITCH_COMMAND} | ||
The original error:`; | ||
|
||
const bundleInfoFilePaths = new Set([ | ||
"Info.plist", | ||
"Contents/Info.plist", | ||
"Support Files/Info.plist", | ||
"Resources/Info.plist", | ||
]); | ||
|
||
export const IS_MAC = platform() === "darwin"; | ||
|
||
/** | ||
* On Mac OS returns `true` if and only if the path points to a directory that has the `"com.apple.xcode.resultbundle"` | ||
* uniform type identifier in its content type tree. | ||
* On other platforms return `false`. | ||
*/ | ||
export const isXcResultBundle = async (directory: string) => { | ||
const hasXcResultUti = IS_MAC ? await checkUniformTypeIdentifier(directory, "com.apple.xcode.resultbundle") : false; | ||
return hasXcResultUti || isMostProbablyXcResultBundle(directory); | ||
}; | ||
|
||
/** | ||
* Returns `true` if and only if the path points to an item that has the specified uniform type identifier in its | ||
* content type tree. | ||
* Requires Mac OS. | ||
*/ | ||
export const checkUniformTypeIdentifier = async (itemPath: string, uti: string) => { | ||
const mdlsArgs = ["-raw", "-attr", "kMDItemContentTypeTree", itemPath]; | ||
const stringToSearch = `"${uti}"`; | ||
|
||
for await (const line of invokeStdoutCliTool("mdls", mdlsArgs)) { | ||
if (line.indexOf(stringToSearch) !== -1) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
export const isMostProbablyXcResultBundle = (directory: string) => | ||
isDefined(findBundleInfoFile(directory)) || followsXcResultNaming(directory); | ||
|
||
export const followsXcResultNaming = (directory: string) => directory.endsWith(".xcresult"); | ||
|
||
/** | ||
* If the provided directory contains an Info.plist file in one of the well-known locations, returns the absolute path | ||
* of that file. Otherwise, returns `undefined`. | ||
* Directories with such files are most probably Mac OS bundles and should be treated accordingly. | ||
* | ||
* NOTE: not all bundles contain an Info.plist file. But the ones we're interested in (XCResult bundles, specifically) | ||
* does. | ||
*/ | ||
export const findBundleInfoFile = async (directory: string) => { | ||
for (const infoFilePath of bundleInfoFilePaths) { | ||
const infoFileAbsPath = path.join(directory, infoFilePath); | ||
const stat = await lstat(infoFileAbsPath); | ||
|
||
if (stat.isFile()) { | ||
return infoFileAbsPath; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters