Skip to content

Commit 18b3637

Browse files
authored
Cfg5 fixes (#12)
* Add download information to release information * Cleanup + minor fixes
1 parent 1e75c3f commit 18b3637

File tree

7 files changed

+245
-205
lines changed

7 files changed

+245
-205
lines changed

.github/workflows/upload-source-archives.yml

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,47 @@ jobs:
2727
source.zip
2828
source.tar.gz
2929
30-
- name: Add Pages link to release description
30+
- name: Add download instructions and Pages link to release description
3131
run: |
3232
TAG_NAME=${{ github.ref_name }}
3333
REPO=${{ github.repository }}
3434
PAGES_URL="https://vectorgrp.github.io/bazel-rules/?tag=$TAG_NAME"
3535
3636
echo "Updating release description for tag $TAG_NAME"
3737
38+
# Calculate SHA256 of the tar.gz file
39+
TAR_SHA=$(sha256sum source.tar.gz | cut -d' ' -f1)
40+
3841
# Get the current release body
3942
CURRENT_BODY=$(gh api "repos/$REPO/releases/tags/$TAG_NAME" --jq .body)
4043
41-
# Append the Pages link if not already present
42-
if [[ "$CURRENT_BODY" != *"$PAGES_URL"* ]]; then
43-
UPDATED_BODY="$CURRENT_BODY"$'\n\n'"GitHub Pages link for download count: $PAGES_URL"
44+
# Create download instructions
45+
DOWNLOAD_INSTRUCTIONS="In a WORKSPACE or MODULE.bazel file add an http_archive rule to fetch the ruleset:
4446
45-
RELEASE_ID=$(gh api "repos/$REPO/releases/tags/$TAG_NAME" --jq .id)
47+
\`\`\`python
48+
http_archive(
49+
name = \"vector_bazel_rules\",
50+
sha256 = \"$TAR_SHA\",
51+
url = \"https://github.com/vectorgrp/bazel-rules/releases/download/$TAG_NAME/source.tar.gz\",
52+
)
53+
\`\`\`"
4654
47-
gh api -X PATCH "repos/$REPO/releases/$RELEASE_ID" \
48-
-f body="$UPDATED_BODY"
55+
# Check if download instructions are already present
56+
if [[ "$CURRENT_BODY" != *"http_archive"* ]]; then
57+
# Prepend download instructions to the current body
58+
UPDATED_BODY="$DOWNLOAD_INSTRUCTIONS"$'\n\n'"$CURRENT_BODY"
4959
else
50-
echo "Pages link already present, skipping update."
60+
UPDATED_BODY="$CURRENT_BODY"
5161
fi
62+
63+
# Append the Pages link if not already present
64+
if [[ "$UPDATED_BODY" != *"$PAGES_URL"* ]]; then
65+
UPDATED_BODY="$UPDATED_BODY"$'\n\n'"GitHub Pages link for download count: $PAGES_URL"
66+
fi
67+
68+
RELEASE_ID=$(gh api "repos/$REPO/releases/tags/$TAG_NAME" --jq .id)
69+
70+
gh api -X PATCH "repos/$REPO/releases/$RELEASE_ID" \
71+
-f body="$UPDATED_BODY"
5272
env:
5373
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module(
22
name = "vector_bazel_rules",
3-
version = "1.3.2",
3+
version = "1.3.3",
44
)
55

66
bazel_dep(name = "rules_cc", version = "0.1.1")

rules/cfg5/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ exports_files(
2929
),
3030
)
3131

32+
# Export template files for use in rules
33+
exports_files([
34+
"filter_linux.sh.tpl",
35+
"filter_windows.ps1.tpl",
36+
])
37+
3238
toolchain_type(
3339
name = "toolchain_type",
3440
visibility = ["//visibility:public"],

rules/cfg5/filter_linux.sh.tpl

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
set -e -o pipefail
3+
4+
# Filter generated files to include only needed files
5+
mkdir -p "{headers_dir}"
6+
mkdir -p "{sources_dir}"
7+
8+
# Create component-specific directories
9+
{component_dirs_creation}
10+
11+
# Function to determine component from filename
12+
get_component() {{
13+
local file_path="$1"
14+
local filename=$(basename "$file_path")
15+
local base_name=$(basename "$filename" | sed 's/\\.[^.]*$//')
16+
17+
# List of components
18+
components=({components_list})
19+
20+
for component in "${{components[@]}}"; do
21+
if [[ "$base_name" == "${{component}}_"* ]] || [[ "$base_name" == "$component" ]]; then
22+
echo "$component"
23+
return
24+
fi
25+
done
26+
27+
echo "main"
28+
}}
29+
30+
# Filter and copy header files. Ignore all files from the RteAnalyzer folder
31+
{rsync_exe} --log-file="{rsync_log_file_hdrs}" --verbose --prune-empty-dirs --archive --itemize-changes --quiet --filter "+ */" --filter "- **/RteAnalyzer/**" {excluded_files_patterns} --filter "+ **/*.h" --filter "- *" {generator_output_dir} {headers_dir}
32+
33+
# Filter and copy source files. Ignore all files from the RteAnalyzer folder
34+
{rsync_exe} --log-file="{rsync_log_file_srcs}" --verbose --prune-empty-dirs --archive --itemize-changes --quiet --filter "+ */" --filter "- **/RteAnalyzer/**" {excluded_files_patterns} --filter "+ **/*.c" --filter "+ **/*.asm" --filter "+ **/*.inc" --filter "+ **/*.inl" --filter "+ **/*.S" --filter "+ **/*.s" --filter "+ **/*.a" {additional_source_file_endings} --filter "- *" {generator_output_dir} {sources_dir}
35+
36+
# Move component-specific files from main directories to component directories
37+
# Process headers first
38+
find {headers_dir} -name "*.h" | while read -r file; do
39+
component=$(get_component "$file")
40+
41+
# If this file belongs to a specific component, move it to component directory
42+
if [ "$component" != "main" ]; then
43+
component_headers_dir="{headers_dir}/../generated_headers_$component"
44+
if [ -d "$component_headers_dir" ]; then
45+
mv "$file" "$component_headers_dir/"
46+
fi
47+
fi
48+
done
49+
# Process sources
50+
find {sources_dir} -name "*.*" | while read -r file; do
51+
component=$(get_component "$file")
52+
53+
# If this file belongs to a specific component, move it to component directory
54+
if [ "$component" != "main" ]; then
55+
component_sources_dir="{sources_dir}/../generated_sources_$component"
56+
if [ -d "$component_sources_dir" ]; then
57+
mv "$file" "$component_sources_dir/"
58+
fi
59+
fi
60+
done

rules/cfg5/filter_windows.ps1.tpl

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
$ErrorActionPreference = 'Stop'
2+
$PSNativeCommandUseErrorActionPreference = $true
3+
4+
try {{
5+
6+
# List of files to ignore
7+
$ignoreList = @({excluded_files})
8+
9+
# List of components
10+
$components = @({components_list})
11+
12+
# Function to check if a file is in the ignore list
13+
function ShouldIgnore {{
14+
param (
15+
[string]$fileName
16+
)
17+
return $ignoreList -contains $fileName
18+
}}
19+
20+
# Function to determine which component a file belongs to
21+
function GetFileComponent {{
22+
param (
23+
[string]$filePath
24+
)
25+
26+
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($filePath)
27+
28+
foreach ($component in $components) {{
29+
# Check if filename starts with component name (e.g., Com_*, BswM_*, etc.)
30+
if ($fileName -like "${{component}}_*" -or $fileName -eq $component) {{
31+
return $component
32+
}}
33+
}}
34+
35+
return "main" # Default to main if no component match
36+
}}
37+
38+
# Create all destination folders
39+
$allDirs = @("{sources_dir}", "{headers_dir}"{component_dirs_list})
40+
foreach ($dir in $allDirs) {{
41+
if (-not (Test-Path -Path $dir)) {{
42+
New-Item -ItemType Directory -Path $dir -Force
43+
}}
44+
}}
45+
46+
# Process .h files. Ignore all files from the RteAnalyzer folder
47+
Get-ChildItem -Path {generator_output_dir} -Filter *.h -Recurse | Where-Object {{ $_.FullName -notlike "*RteAnalyzer*" }} | ForEach-Object {{
48+
#if (-not (ShouldIgnore -fileName $_.Name)) {{
49+
# Always copy to main headers directory first
50+
Copy-Item -Path $_.FullName -Destination {headers_dir}
51+
#}}
52+
}}
53+
54+
# Define the list of file patterns to include
55+
$sourceFilePatterns = @("*.c", "*.asm", "*.inc", "*.inl", "*.S", "*.s", "*.a")
56+
57+
if ({additional_source_file_endings} -and {additional_source_file_endings} -ne @("")) {{
58+
$sourceFilePatterns += {additional_source_file_endings}
59+
}}
60+
61+
# Process source files. Ignore all files from the RteAnalyzer folder
62+
foreach ($pattern in $sourceFilePatterns) {{
63+
Get-ChildItem -Path {generator_output_dir} -Filter $pattern -Recurse | Where-Object {{ $_.FullName -notlike "*RteAnalyzer*" }} | ForEach-Object {{
64+
if (-not (ShouldIgnore -fileName $_.Name)) {{
65+
# Always copy to main sources directory first
66+
Copy-Item -Path $_.FullName -Destination {sources_dir}
67+
}}
68+
}}
69+
}}
70+
71+
# Move component-specific files from main directories to component directories
72+
# Process headers first
73+
Get-ChildItem -Path {headers_dir} -Filter *.h | ForEach-Object {{
74+
$component = GetFileComponent -filePath $_.FullName
75+
76+
# If this file belongs to a specific component, move it to component directory
77+
if ($component -ne "main") {{
78+
$componentHeadersDir = "{headers_dir}/../generated_headers_${{component}}"
79+
if (Test-Path $componentHeadersDir) {{
80+
Move-Item -Path $_.FullName -Destination $componentHeadersDir
81+
}}
82+
}}
83+
}}
84+
85+
# Process sources
86+
foreach ($pattern in $sourceFilePatterns) {{
87+
Get-ChildItem -Path {sources_dir} -Filter $pattern | ForEach-Object {{
88+
$component = GetFileComponent -filePath $_.FullName
89+
90+
# If this file belongs to a specific component, move it to component directory
91+
if ($component -ne "main") {{
92+
$componentSourcesDir = "{sources_dir}/../generated_sources_${{component}}"
93+
if (Test-Path $componentSourcesDir) {{
94+
Move-Item -Path $_.FullName -Destination $componentSourcesDir
95+
}}
96+
}}
97+
}}
98+
}}
99+
100+
Write-Output "Files have been moved successfully."
101+
}} catch {{
102+
Write-Error "An error occurred: $_"
103+
exit 1
104+
}}

0 commit comments

Comments
 (0)