Skip to content

Add DocC #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
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
43 changes: 43 additions & 0 deletions Scripts/soundness/docc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

# Directories containing the flags
FEATURE_FLAGS_DIR="Sources/PackageDSL/SwiftSettings/FeatureFlags"
UNSAFE_FLAGS_DIR="Sources/PackageDSL/SwiftSettings/UnsafeFlags"
FRONTEND_FLAGS_DIR="Sources/PackageDSL/SwiftSettings/UnsafeFlags/Frontend"
DOCC_FILE="Sources/PackageDSL/PackageDSL.docc/PackageDSL.md"

# Function to extract struct names from Swift files
extract_struct_names() {
local dir=$1
local recursive=$2
local maxdepth_arg=${recursive:+""} ${recursive:-"-maxdepth 1"}
find "$dir" $maxdepth_arg -name "*.swift" -exec grep -h "^public struct" {} \; | sed 's/public struct \([^:]*\).*/- ``\1``/' | sort
}

# Create temporary file
tmp_file=$(mktemp)

# Read the original file up to "### Feature Flags"
sed -n '1,/### Feature Flags/p' "$DOCC_FILE" > "$tmp_file"

# Add Feature Flags
echo "" >> "$tmp_file"
extract_struct_names "$FEATURE_FLAGS_DIR" true >> "$tmp_file"

# Add Unsafe Flags section
echo "" >> "$tmp_file"
echo "### Unsafe Flags" >> "$tmp_file"
echo "" >> "$tmp_file"
extract_struct_names "$UNSAFE_FLAGS_DIR" false >> "$tmp_file"

# Add Frontend Flags section
echo "" >> "$tmp_file"
echo "### Frontend Flags" >> "$tmp_file"
echo "" >> "$tmp_file"
extract_struct_names "$FRONTEND_FLAGS_DIR" false >> "$tmp_file"

# Replace the original file
mv "$tmp_file" "$DOCC_FILE"

# Make the file executable
chmod +x "$0"
40 changes: 37 additions & 3 deletions Scripts/soundness/features.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,43 @@ create_feature_file() {
echo "// swiftlint:disable line_length" > "$output_directory/$feature_state_dir/${feature_name}.swift"
echo "///" >> "$output_directory/$feature_state_dir/${feature_name}.swift"
# Format each line of documentation with ///
echo "$documentation" | sed '/^$/d' | while IFS= read -r line; do
echo "/// $line" >> "$output_directory/$feature_state_dir/${feature_name}.swift"
done
echo "$documentation" | sed '/^$/d' | awk '
BEGIN { first_printed = 0 }
{
if (!first_printed) {
line = $0
pos = 1
in_parentheses = 0
period_pos = 0

# Scan through the line character by character
while (pos <= length(line)) {
char = substr(line, pos, 1)
if (char == "(") in_parentheses = 1
else if (char == ")") in_parentheses = 0
else if (char == "." && !in_parentheses) {
period_pos = pos
break
}
pos++
}

if (period_pos > 0) {
# Print everything up to and including the period
print "/// " substr(line, 1, period_pos)
print "///"
# Print the rest of the line if anything remains
rest = substr(line, period_pos + 1)
if (length(rest) > 0) {
print "/// " rest
}
first_printed = 1
next
}
}
print "/// " $0
}
' >> "$output_directory/$feature_state_dir/${feature_name}.swift"
echo "///" >> "$output_directory/$feature_state_dir/${feature_name}.swift"
echo "/// - SeeAlso: [$proposal_title ($proposal_number)]($html_url)" >> "$output_directory/$feature_state_dir/${feature_name}.swift"
echo "///" >> "$output_directory/$feature_state_dir/${feature_name}.swift"
Expand Down
1 change: 1 addition & 0 deletions Scripts/soundness/unsafeflags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ process_flags() {
# Generate Swift file
{
echo "/// Passes the flag \`$original_flag\`"
echo "///"
if [ ! -z "$description" ]; then
# Split description into lines of max 80 characters (accounting for "/// " prefix)
capitalized_desc=$(echo "$description" | sed 's/^[[:lower:]]/\U&/')
Expand Down
1 change: 0 additions & 1 deletion Sources/PackageDSL/Package+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ extension Package {
$0.allDependencies()
}
}
let targetDependencies = dependencies.compactMap { $0 as? Target }
let packageTargetDependencies = dependencies.compactMap { $0 as? TargetDependency }
let allPackageDependencies =
packageTargetDependencies.map(\.package) + packageDependencies
Expand Down
Loading