-
Notifications
You must be signed in to change notification settings - Fork 0
CradlePlugin으로 target 단위 Mermaid .mmd 개발 산출물을 생성하도록 구현한다 #34
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
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c6b6f49
feat: DependencyGraph diagram 표식 추가
opficdev 621df33
feat: Mermaid graph 정적 분석 추가
opficdev 756f4c3
feat: Mermaid graph 표현 추가
opficdev 8651ff3
feat: Mermaid 산출물 관리 도구 추가
opficdev 64932ec
feat: CradlePlugin artifact 빌드 연동 추가
opficdev e79383d
test: CradlePlugin 소비자 산출물 경계 검증
opficdev 38759f9
feat: ExampleApp CradlePlugin Xcode 연결 추가
opficdev ea76a61
chore: 설계 및 검토 역할 모델 변경
opficdev e12c6c7
feat: target 단일 Mermaid graph 생성
opficdev 58deb22
fix: Mermaid graph 이름 중복 제거
opficdev 617d321
feat: ExampleApp Mermaid 복사 스크립트 분리
opficdev 8d03449
fix: Mermaid escaped lifetime 판별 교정
opficdev e7f411b
fix: Xcode Mermaid target 경로 탐색 교정
opficdev 05ff0f3
test: Mermaid target 특수문자 경로 검증 추가
opficdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -12,6 +12,9 @@ DerivedData/ | |
| xcuserdata/ | ||
| *.xcuserstate | ||
|
|
||
| # Mermaid 개발 산출물 | ||
| .cradle/ | ||
|
|
||
| # 인증·환경 | ||
| .netrc | ||
| .env | ||
|
|
||
Binary file added
BIN
+19 MB
Artifacts/CradleDiagramMaker.artifactbundle/CradleDiagramMaker-arm64/bin/CradleDiagramMaker
Binary file not shown.
Binary file added
BIN
+19.7 MB
Artifacts/CradleDiagramMaker.artifactbundle/CradleDiagramMaker-x86_64/bin/CradleDiagramMaker
Binary file not shown.
This file contains hidden or 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,23 @@ | ||
| { | ||
| "schemaVersion": "1.0", | ||
| "artifacts": { | ||
| "CradleDiagramMaker": { | ||
| "version": "0.1.0", | ||
| "type": "executable", | ||
| "variants": [ | ||
| { | ||
| "path": "CradleDiagramMaker-arm64/bin/CradleDiagramMaker", | ||
| "supportedTriples": [ | ||
| "arm64-apple-macosx" | ||
| ] | ||
| }, | ||
| { | ||
| "path": "CradleDiagramMaker-x86_64/bin/CradleDiagramMaker", | ||
| "supportedTriples": [ | ||
| "x86_64-apple-macosx" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,89 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -eu | ||
|
|
||
| search_root="${OBJROOT}/BuildToolPluginIntermediates" | ||
| destination_directory="${SRCROOT}/.cradle" | ||
| destination="${destination_directory}/DependencyGraph.mmd" | ||
| matches="${TARGET_TEMP_DIR}/cradle-diagram-paths.txt" | ||
| temporary="" | ||
|
|
||
| cleanup() { | ||
| /bin/rm -f "${matches}" | ||
|
|
||
| if [ -n "${temporary}" ]; then | ||
| /bin/rm -f "${temporary}" | ||
| fi | ||
| } | ||
|
|
||
| trap cleanup EXIT | ||
|
|
||
| : > "${matches}" | ||
|
|
||
| case "${TARGET_NAME}" in | ||
| */*) | ||
| echo "warning: Xcode target 이름에 경로 구분자가 있어 기존 파일을 유지합니다." | ||
| exit 0 | ||
| ;; | ||
| esac | ||
|
|
||
| target_path_pattern=$(printf '%s' "${TARGET_NAME}" | /usr/bin/sed 's/[][\\*?]/\\&/g') | ||
|
|
||
| if [ -d "${search_root}" ]; then | ||
| if ! /usr/bin/find "${search_root}" \ | ||
| -type f \ | ||
| ! -type l \ | ||
| -path "*/${target_path_pattern}/CradlePlugin/CradleDiagrams/*/DependencyGraph.mmd" \ | ||
| -print > "${matches}"; then | ||
| echo "warning: Cradle DependencyGraph.mmd를 찾지 못해 기존 파일을 유지합니다." | ||
| exit 0 | ||
| fi | ||
| fi | ||
|
|
||
| count=$(/usr/bin/wc -l < "${matches}" | /usr/bin/tr -d ' ') | ||
|
|
||
| if [ "${count}" -ne 1 ]; then | ||
| echo "warning: Cradle DependencyGraph.mmd 후보를 하나로 결정하지 못해 기존 파일을 유지합니다." | ||
| exit 0 | ||
| fi | ||
|
|
||
| source_path=$(/usr/bin/sed -n '1p' "${matches}") | ||
|
|
||
| if [ ! -f "${source_path}" ] || [ -L "${source_path}" ]; then | ||
| echo "warning: Cradle DependencyGraph.mmd가 없어 기존 파일을 유지합니다." | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [ -L "${destination_directory}" ] || { [ -e "${destination_directory}" ] && [ ! -d "${destination_directory}" ]; }; then | ||
| echo "warning: .cradle 경로를 안전하게 쓸 수 없어 기존 파일을 유지합니다." | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [ -L "${destination}" ] || { [ -e "${destination}" ] && [ ! -f "${destination}" ]; }; then | ||
| echo "warning: DependencyGraph.mmd 경로를 안전하게 쓸 수 없어 기존 파일을 유지합니다." | ||
| exit 0 | ||
| fi | ||
|
|
||
| if ! /bin/mkdir -p "${destination_directory}"; then | ||
| echo "warning: .cradle 디렉터리를 만들지 못해 기존 파일을 유지합니다." | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [ -f "${destination}" ] && /usr/bin/cmp -s "${source_path}" "${destination}"; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| if ! temporary=$(/usr/bin/mktemp "${destination_directory}/.DependencyGraph.mmd.XXXXXX"); then | ||
| echo "warning: Cradle DependencyGraph.mmd 임시 파일을 만들지 못해 기존 파일을 유지합니다." | ||
| exit 0 | ||
| fi | ||
|
|
||
| if ! /bin/cp "${source_path}" "${temporary}"; then | ||
| echo "warning: Cradle DependencyGraph.mmd 복사에 실패해 기존 파일을 유지합니다." | ||
| exit 0 | ||
| fi | ||
|
|
||
| if ! /bin/mv -f "${temporary}" "${destination}"; then | ||
| echo "warning: Cradle DependencyGraph.mmd 반영에 실패해 기존 파일을 유지합니다." | ||
| exit 0 | ||
| fi | ||
This file contains hidden or 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 hidden or 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,84 @@ | ||
| // | ||
| // CradlePlugin.swift | ||
| // CradlePlugin | ||
| // | ||
| // Created by opfic on 9/4/26. | ||
| // | ||
|
|
||
| import Foundation | ||
| import PackagePlugin | ||
|
|
||
| #if canImport(XcodeProjectPlugin) | ||
| import XcodeProjectPlugin | ||
| #endif | ||
|
|
||
| // target source의 DependencyGraph Mermaid `.mmd` 산출물을 만드는 Build Tool Plugin | ||
| @main | ||
| struct CradlePlugin: BuildToolPlugin { | ||
| // 현재 SwiftPM source target을 단위로 Mermaid 생성 명령 구성 | ||
| func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] { | ||
| guard let sourceTarget = target as? SwiftSourceModuleTarget else { | ||
| return [] | ||
| } | ||
| let tool = try context.tool(named: "CradleDiagramMaker") | ||
| let sourcePaths = sourceTarget.sourceFiles | ||
| .filter { $0.type == .source } | ||
| .map(\.url) | ||
| .sorted { $0.path < $1.path } | ||
| return mermaidBuildCommands( | ||
| toolURL: tool.url, | ||
| pluginWorkDirectoryURL: context.pluginWorkDirectoryURL, | ||
| moduleName: sourceTarget.moduleName, | ||
| sourceURLs: sourcePaths | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| #if canImport(XcodeProjectPlugin) | ||
| // Xcode 프로젝트 target의 Mermaid 생성 진입점 | ||
| extension CradlePlugin: XcodeBuildToolPlugin { | ||
| // 현재 Xcode target source를 단위로 Mermaid 생성 명령 구성 | ||
| func createBuildCommands(context: XcodePluginContext, target: XcodeTarget) throws -> [Command] { | ||
| let tool = try context.tool(named: "CradleDiagramMaker") | ||
| let sourceURLs = target.inputFiles | ||
| .map(\.url) | ||
| .filter { $0.pathExtension == "swift" } | ||
| .sorted { $0.path < $1.path } | ||
| // 표시 이름을 Swift module로 해석하지 않고 단일 출력 경로 요소로 변환 | ||
| let allowed = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "_- ")) | ||
| let namespace = target.displayName.addingPercentEncoding(withAllowedCharacters: allowed) ?? target.id | ||
| return mermaidBuildCommands( | ||
| toolURL: tool.url, | ||
| pluginWorkDirectoryURL: context.pluginWorkDirectoryURL, | ||
| moduleName: namespace, | ||
| sourceURLs: sourceURLs | ||
| ) | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
| // SwiftPM·Xcode target의 입력 변경과 반복 빌드에 적용할 Mermaid 명령 구성 | ||
| private func mermaidBuildCommands( | ||
| toolURL: URL, | ||
| pluginWorkDirectoryURL: URL, | ||
| moduleName: String, | ||
| sourceURLs: [URL] | ||
| ) -> [Command] { | ||
| let outputDirectory = pluginWorkDirectoryURL.appendingPathComponent("CradleDiagrams") | ||
| let arguments = [ | ||
| "--module", moduleName, | ||
| "--output", outputDirectory.path | ||
| ] | ||
| + sourceURLs.map(\.path) | ||
|
|
||
| return [ | ||
| // `.mmd`를 resource로 등록하지 않고 매 빌드에서 기존 파일 정리까지 수행 | ||
| .buildCommand( | ||
| displayName: "Cradle Mermaid diagrams", | ||
| executable: toolURL, | ||
| arguments: arguments, | ||
| inputFiles: sourceURLs, | ||
| outputFiles: [] | ||
| ) | ||
| ] | ||
| } |
This file contains hidden or 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,19 @@ | ||
| # Cradle | ||
|
|
||
| Cradle은 Swift Macro를 사용해 의존성 graph의 factory를 생성하는 라이브러리입니다. | ||
|
|
||
| ## Mermaid 개발 산출물 | ||
|
|
||
| `CradlePlugin`은 build 중 Mermaid 원본을 생성합니다. Xcode에서 바로 열 파일이 필요하면 target의 마지막 Run Script 단계가 `.cradle/DependencyGraph.mmd`로 복사하게 설정할 수 있습니다. | ||
|
|
||
| ### ExampleApp 설정 | ||
|
|
||
| `Examples/ExampleApp`의 `Cradle Mermaid copy` 단계는 [CopyCradleMermaid.sh](Examples/ExampleApp/Scripts/CopyCradleMermaid.sh)를 실행합니다. 같은 설정을 추가할 때는 이 단계를 target의 마지막 Build Phase에 두고 Based on dependency analysis를 선택 해제합니다. | ||
|
|
||
| ```sh | ||
| /bin/sh "${SRCROOT}/Scripts/CopyCradleMermaid.sh" | ||
| ``` | ||
|
|
||
| `Cmd+B`를 마치면 `Examples/ExampleApp/.cradle/DependencyGraph.mmd`가 생성됩니다. `.cradle/`은 Git에서 제외되며 앱이나 라이브러리 제품에 포함되지 않습니다. | ||
|
|
||
| Xcode의 build 도구 작업 경로는 공개된 고정 경로가 아닙니다. 이 설정은 현재 `CradlePlugin` 산출물을 쉽게 열기 위한 방법이므로, Xcode 구조가 바뀐 뒤 경고가 나오면 [CopyCradleMermaid.sh](Examples/ExampleApp/Scripts/CopyCradleMermaid.sh)의 검색 경로를 확인해야 합니다. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.