From 52a2d78d3df84932e942fd94fc8e92d7c2fa2a08 Mon Sep 17 00:00:00 2001 From: aminya Date: Thu, 12 Dec 2019 10:24:57 +0330 Subject: [PATCH] - Refractiring precompilePath - Input args changed - removed extra method --- src/utilities.jl | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/utilities.jl b/src/utilities.jl index 46c770b5d..bd7de83fe 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -1,32 +1,43 @@ export precompileActivator, precompileDeactivator """ - precompileActivator(packageName, filePath) + precompilePath(packageName::String) + +To get the path of precompile_packageName.jl file + +Written exclusively for SnoopCompile Github actions. +""" +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 @@ -34,43 +45,40 @@ function precompileActivator(packageName::String, filePath::String = pathof(eval 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 @@ -78,11 +86,9 @@ function precompileDeactivator(packageName::String, filePath::String = pathof(ev 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)) )