-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Input args changed removed extra method
- Loading branch information
Showing
1 changed file
with
25 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) ) |