Skip to content

Instantly share code, notes, and snippets.

@ihnorton
Last active January 17, 2018 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihnorton/b9d0a18b3ae00bb5fb78b143eda79d70 to your computer and use it in GitHub Desktop.
Save ihnorton/b9d0a18b3ae00bb5fb78b143eda79d70 to your computer and use it in GitHub Desktop.
Rewrite Slicer VTK and ITK includes to use relative paths
const FS = Base.Filesystem
const regex = r"^((?!//))(#include\s+)(<|\")(\S+)(>|\")\s+"
function get_includes(dir, prefix, exclude="")
includes = Dict{String,String}()
for path in readlines(`bash -c "find $dir -name $prefix*.h -not -path $exclude"`)
(bp,h) = FS.splitdir(path)
bp = replace(bp, dir*"/", "")
if haskey(includes, h)
throw("Key already exists!: $h")
end
includes[h] = bp
end
return includes
end
function lproc(l, rewrites)
if (m = match(regex, l)) != nothing
h = m.captures[4]
if h in keys(rewrites)
#print("== $l == ", m.captures, "\n ")
ret = string(m.captures[1], "vtk/", m.captures[2], m.captures[3], rewrites[h], "/", h, m.captures[5], "\n")
return ret
else
return l
end
else
return l
end
end
function rewrite(file, rewrites)
tmp = map(x -> lproc(x, rewrites),
readlines(file, chomp=false))
return tmp
end
function rewrite_includes(basedir, rewrites)
for file in readlines(`bash -c "find $basedir -name *.cxx -or -name *.h"`)
println(file)
tmp = rewrite(file, rewrites)
open(file, "w") do f
write(f, string(tmp...))
end
end
end
slicer_dir = "/Users/inorton/git/slcr/s5"
sb_dir = "/opt/bld/s5nj"
vtk = "VTKv9"
itk = "ITKv4"
vtk_dir = joinpath(sb_dir, vtk)
itk_dir = joinpath(sb_dir, itk)
vtk_includes = get_includes(vtk_dir, "vtk", "\*/Examples/\*")
itk_includes = get_includes(itk_dir, "itk", "\*/Examples/\*")
rewrites = merge(vtk_includes, itk_includes);
# run with
# rewrite_includes(slicer_dir, rewrites)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment