Skip to content

Commit

Permalink
Add DocC (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Feb 4, 2025
1 parent c53c300 commit 0e732f6
Show file tree
Hide file tree
Showing 743 changed files with 2,058 additions and 26 deletions.
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

0 comments on commit 0e732f6

Please sign in to comment.