-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DNMY: Refactor and tidy src/license.jl #240
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,20 +28,64 @@ | |
include("Lib/Lib.jl") | ||
include("helper.jl") | ||
include("api.jl") | ||
include("license.jl") | ||
include("MOI/MOI_wrapper.jl") | ||
include("MOI/MOI_callbacks.jl") | ||
|
||
function _get_xpauthpath(; verbose::Bool) | ||
candidates = String[pwd(), dirname(libxprs)] | ||
for key in ("XPAUTH_PATH", "XPRESS_DIR") | ||
if haskey(ENV, key) | ||
push!(candidates, replace(ENV[key], "\"" => "")) | ||
end | ||
end | ||
push!(candidates, joinpath(dirname(dirname(libxprs)), "bin")) | ||
for candidate in candidates | ||
for filename in (candidate, joinpath(candidate, "xpauth.xpr")) | ||
if isfile(filename) | ||
if verbose | ||
@info("Xpress: Found license file $filename") | ||
end | ||
return filename | ||
end | ||
end | ||
end | ||
return error( | ||
"Could not find xpauth.xpr license file. Set the `XPRESSDIR` or " * | ||
"`XPAUTH_PATH` environment variables.", | ||
) | ||
end | ||
|
||
function initialize() | ||
Libdl.dlopen(libxprs) | ||
userlic() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all our code relies on calling this. I would not like to deprecate unless extremely necessary. |
||
verbose = !haskey(ENV, "XPRESS_JL_NO_INFO") | ||
path_lic = _get_xpauthpath(; verbose) | ||
touch(path_lic) | ||
lic = Ref{Cint}(1) | ||
# TODO(odow): why do we call XPRSlicense twice? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see the explanation in the license.jl file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't find the comments very descriptive haha |
||
Lib.XPRSlicense(lic, path_lic) | ||
buffer = Vector{Cchar}(undef, 1024 * 8) | ||
ierr = GC.@preserve buffer begin | ||
Lib.XPRSlicense(lic, Cstring(pointer(buffer))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @joaquimg any points on why this is necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this buffer might not be needed, it probably came from a copy-paste from the usage below. |
||
end | ||
if ierr == 16 | ||
if verbose | ||
@info("Xpress: Development license detected.") | ||
end | ||
elseif ierr == 0 | ||
if verbose | ||
@info("Xpress: User license detected.") | ||
end | ||
else | ||
@info("Xpress: Failed to find working license.") | ||
GC.@preserve buffer begin | ||
Lib.XPRSgetlicerrmsg(pointer(buffer), 1024) | ||
error(unsafe_string(pointer(buffer))) | ||
end | ||
end | ||
Lib.XPRSinit(C_NULL) | ||
# Calling free is not necessary since destroyprob is called | ||
# in the finalizer. | ||
return | ||
end | ||
|
||
include("MOI/MOI_wrapper.jl") | ||
include("MOI/MOI_callbacks.jl") | ||
|
||
function __init__() | ||
if !haskey(ENV, "XPRESS_JL_NO_AUTO_INIT") && | ||
get(ENV, "JULIA_REGISTRYCI_AUTOMERGE", "false") != "true" | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the idea of moving all this code to the root file.
A user/developer should not start their trip into express from this license code.