Skip to content

Commit

Permalink
precompile_checker
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Feb 11, 2020
1 parent 8fe7890 commit ae70b35
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/bot/precompileInclude.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,34 +121,46 @@ function precompile_deactivator(package_path::String, precompile_path::String)
""")
end
end
################################################################

"""
precompile_enclusure(package_path::String, precompile_path::String)
precompile_checker(package_path::String)
Writes a `@static` enclosure to contain inclusion of precompile scripts
# Examples
```julia
examples
```
Checks if any other precompile code already exists
"""
function precompile_enclusure(package_path::String, precompile_path::String)
function precompile_checker(package_path::String)
if !isfile(package_path)
error("$package_path file doesn't exist")
end

# read package
package_text = Base.read(package_path, String)

if occursin("_precompile_()",package_text) # precompiles without enclosure!
error("""Please remove `_precompile_()` and any other code that includes a `_precompile_()` function from $package_path
New version of SnoopCompile automatically creates the code.
""")
else
return nothing
end
end

"""
precompile_enclusure(package_path::String, precompile_path::String)
Writes a `@static` enclosure to contain inclusion of precompile scripts
# Examples
```julia
examples
```
"""
function precompile_enclusure(package_path::String, precompile_path::String)
enclosure_regex = r"^\@static\s+if\s+should_precompile[\s\S]*end\s*#\s*precompile_enclusure$"

if occursin(enclosure_regex, package_text) # has enclosure

else # no enclosure

if occursin("_precompile_()",package_text) # precompiles without enclosure!
error("Please remove `_precompile_()` and any code that includes a `_precompile_` function from $package_path")
end

# write enclosure
@info "SnoopCompile will try to write some code before end of the module in $package_path"

Expand Down

0 comments on commit ae70b35

Please sign in to comment.