Skip to content
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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 51 additions & 7 deletions src/Xpress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,64 @@
include("Lib/Lib.jl")
include("helper.jl")
include("api.jl")
include("license.jl")
Copy link
Member

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.

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(

Check warning on line 52 in src/Xpress.jl

View check run for this annotation

Codecov / codecov/patch

src/Xpress.jl#L52

Added line #L52 was not covered by tests
"Could not find xpauth.xpr license file. Set the `XPRESSDIR` or " *
"`XPAUTH_PATH` environment variables.",
)
end

function initialize()
Libdl.dlopen(libxprs)
userlic()
Copy link
Member

Choose a reason for hiding this comment

The 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?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see the explanation in the license.jl file

Copy link
Member Author

Choose a reason for hiding this comment

The 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)))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joaquimg any points on why this is necessary?

Copy link
Member

Choose a reason for hiding this comment

The 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.")

Check warning on line 76 in src/Xpress.jl

View check run for this annotation

Codecov / codecov/patch

src/Xpress.jl#L74-L76

Added lines #L74 - L76 were not covered by tests
end
else
@info("Xpress: Failed to find working license.")
GC.@preserve buffer begin
Lib.XPRSgetlicerrmsg(pointer(buffer), 1024)
error(unsafe_string(pointer(buffer)))

Check warning on line 82 in src/Xpress.jl

View check run for this annotation

Codecov / codecov/patch

src/Xpress.jl#L79-L82

Added lines #L79 - L82 were not covered by tests
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"
Expand Down
116 changes: 0 additions & 116 deletions src/license.jl

This file was deleted.

Loading