Skip to content

Commit

Permalink
Refractiring precompilePath
Browse files Browse the repository at this point in the history
Input args changed
removed extra method
  • Loading branch information
aminya committed Dec 12, 2019
1 parent ba52820 commit 65090bd
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/utilities.jl
Original file line number Diff line number Diff line change
@@ -1,88 +1,92 @@
export precompileActivator, precompileDeactivator

"""
precompileActivator(packageName, filePath)
precompilePath(packageName::String)
To get the path of precompile_packageName.jl file
"""
function precompilePath(packageName::String)
return "../deps/SnoopCompile/precompile/precompile_$packageName.jl"
end

"""
precompileActivator(packagePath, precompilePath)
Activates precompile of a package by adding or uncommenting include() of *.jl file generated by SnoopCompile and _precompile_().
Written exclusively for SnoopCompile Github actions.
"""
function precompileActivator(packageName::String, filePath::String = pathof(eval(Meta.parse(packageName))) )
function precompileActivator(packagePath::String, precompilePath::String)

file = open(filePath,"r")
file = open(packagePath,"r")
packageText = read(file, String)
close(file)

# Checking availability of _precompile_ code
commented = occursin("#include(\"../deps/SnoopCompile/precompile/precompile_$packageName.jl\")", packageText) && occursin("#_precompile_()", packageText)
commented = occursin("#include($precompilePath)", packageText) && occursin("#_precompile_()", packageText)

available = occursin("include(\"../deps/SnoopCompile/precompile/precompile_$packageName.jl\")", packageText) && occursin("_precompile_()", packageText)
available = occursin("include($precompilePath)", packageText) && occursin("_precompile_()", packageText)

if commented
packageEdited = foldl(replace,
(
"#include(\"../deps/SnoopCompile/precompile/precompile_$packageName.jl\")" => "include(\"../deps/SnoopCompile/precompile/precompile_$packageName.jl\")",
"#include($precompilePath)" => "include($precompilePath)",
"#_precompile_()" => "_precompile_()",
),
init = packageText)

file = open(filePath,"w")
file = open(packagePath,"w")
write(file, packageEdited)
close(file)
elseif available
# do nothing
else
# TODO: add code automatiaclly
error(""" add the following codes into your package:
include(\"../deps/SnoopCompile/precompile/precompile_$packageName.jl\")
include($precompilePath)
_precompile_()
""")
end

end

precompileActivator(packageName::Symbol, filePath::String = pathof(eval(packageName)) ) = precompileActivator(string(packageName), filePath)


"""
precompileDeactivator(packageName, filePath)
precompileDeactivator(packagePath, precompilePath)
Deactivates precompile of a package by commenting include() of *.jl file generated by SnoopCompile and _precompile_().
Written exclusively for SnoopCompile Github actions.
"""
function precompileDeactivator(packageName::String, filePath::String = pathof(eval(Meta.parse(packageName))) )
function precompileDeactivator(packagePath::String, precompilePath::String)

file = open(filePath,"r")
file = open(packagePath,"r")
packageText = read(file, String)
close(file)

# Checking availability of _precompile_ code
commented = occursin("#include(\"../deps/SnoopCompile/precompile/precompile_$packageName.jl\")", packageText) && occursin("#_precompile_()", packageText)
commented = occursin("#include($precompilePath)", packageText) && occursin("#_precompile_()", packageText)

available = occursin("include(\"../deps/SnoopCompile/precompile/precompile_$packageName.jl\")", packageText) && occursin("_precompile_()", packageText)
available = occursin("include($precompilePath)", packageText) && occursin("_precompile_()", packageText)

if available && !commented
packageEdited = foldl(replace,
(
"include(\"../deps/SnoopCompile/precompile/precompile_$packageName.jl\")" => "#include(\"../deps/SnoopCompile/precompile/precompile_$packageName.jl\")",
"include($precompilePath)" => "#include($precompilePath)",
"_precompile_()" => "#_precompile_()",
),
init = packageText)

file = open(filePath,"w")
file = open(packagePath,"w")
write(file, packageEdited)
close(file)
elseif commented
# do nothing
else
# TODO: add code automatiaclly
error(""" add the following codes into your package:
include(\"../deps/SnoopCompile/precompile/precompile_$packageName.jl\")
include($precompilePath)
_precompile_()
""")
end

end

precompileDeactivator(packageName::Symbol, filePath::String) = precompileDeactivator(string(packageName), filePath = pathof(eval(packageName)) )

0 comments on commit 65090bd

Please sign in to comment.