diff --git a/src/utilities.jl b/src/utilities.jl index 46c770b5d..59302702b 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -1,32 +1,41 @@ 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 @@ -34,43 +43,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 +84,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)) )