Skip to content

Commit

Permalink
[CI] Add macros.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison authored and nimgould committed Jan 25, 2024
1 parent 1664ab5 commit f2b4a36
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/julia/check_macros.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Test

# Function to easily get the extension of a file
function file_extension(file::String)
pos_dot = findfirst(==('.'), file)
extension = pos_dot == nothing ? "" : file[pos_dot+1:end]
return extension
end

function append_macros!(macros::Dict{String,String}, path::String)
str = read(path, String)
lines = split(str, '\n')
for line in lines
if startswith(line, "#define")
tab = split(line, " ")
macros[tab[2]] = tab[3]
end
end
return macros
end

global n = 0
macros = Dict{String,String}()
append_macros!(macros, joinpath(@__DIR__, "..", "..", "include", "galahad_modules.h"))
append_macros!(macros, joinpath(@__DIR__, "..", "..", "include", "galahad_blas.h"))
append_macros!(macros, joinpath(@__DIR__, "..", "..", "include", "galahad_lapack.h"))

# Check the number of characters
for (root, dirs, files) in walkdir(joinpath(@__DIR__, "..", "..", "src"))
for file in files
path = joinpath(root, file)
code = read(path, String)
lines = split(code, '\n')
for (i, line) in enumerate(lines)
if (file_extension(file) == "f") && (length(line) > 72)
println("Line $i in the file $file has more than 72 characters.")
global n = n+1
end
if (file_extension(file) ["f90", "F90"]) && (length(line) > 80)
println("Line $i in the file $file has more than 80 characters.")
global n = n+1
end
for symbol in keys(macros)
if occursin(symbol, line) && (file_extension(file) == "f")
line2 = replace(line, symbol => macros[symbol])
if length(line2) > 72
println("Line $i in the file $file has more than 72 characters if $symbol is replaced by $(macros[symbol]).")
global n = n+1
end
end
if occursin(symbol, line) && (file_extension(file) ["f90", "F90"])
line2 = replace(line, symbol => macros[symbol])
if length(line2) > 80
println("Line $i in the file $file has more than 80 characters if $symbol is replaced by $(macros[symbol]).")
global n = n+1
end
end
end
end
end
end

@test n == 0
21 changes: 21 additions & 0 deletions .github/workflows/macros.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Macros
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: GALAHAD -- Check macros
runs-on: ubuntu-latest
steps:
- name: Checkout GALAHAD
uses: actions/checkout@v4
- name: Install Julia
uses: julia-actions/setup-julia@v1
with:
version: 1
arch: x64
- name: Check the Fortran macros
run: julia --color=yes .github/julia/check_macros.jl
File renamed without changes.

0 comments on commit f2b4a36

Please sign in to comment.