OxygenFramework / Oxygen.jl

💨 A breath of fresh air for programming web apps in Julia
https://oxygenframework.github.io/Oxygen.jl/
MIT License
383 stars 25 forks source link

`find_package` for oxidise macro does not resolve if Oxygen is not in project #184

Closed JanisErdmanis closed 2 months ago

JanisErdmanis commented 2 months ago

When a package depends on Oxygen with @oxidise macro and is loaded seperatelly with using MyPackage a following error is raised:

PkgPrecompileError: The following 1 direct dependency failed to precompile:

PeaceFounder [916f7771-afe2-4319-943d-0e770c333432]

Failed to precompile PeaceFounder [916f7771-afe2-4319-943d-0e770c333432] to "/Users/jerdmanis/.julia/compiled/v1.10/PeaceFounder/jl_IwU1FY".
ERROR: LoadError: MethodError: no method matching dirname(::Nothing)

Closest candidates are:
  dirname(::AbstractString)
   @ Base path.jl:164

Stacktrace:
  [1] top-level scope
    @ ~/.julia/packages/Oxygen/KbVNY/src/Oxygen.jl:25
  [2] include(mod::Module, _path::String)
    @ Base ./Base.jl:495
  [3] include(x::String)
    @ PeaceFounder.Server ~/.julia/packages/PeaceFounder/H5E3m/src/Server/Server.jl:1
  [4] top-level scope
    @ ~/.julia/packages/PeaceFounder/H5E3m/src/Server/Server.jl:14
  [5] include(mod::Module, _path::String)
    @ Base ./Base.jl:495
  [6] include(x::String)
    @ PeaceFounder ~/.julia/packages/PeaceFounder/H5E3m/src/PeaceFounder.jl:1
  [7] top-level scope
    @ ~/.julia/packages/PeaceFounder/H5E3m/src/PeaceFounder.jl:23
  [8] include
    @ ./Base.jl:495 [inlined]
  [9] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing)
    @ Base ./loading.jl:2222
 [10] top-level scope
    @ stdin:3
in expression starting at /Users/jerdmanis/.julia/packages/PeaceFounder/H5E3m/src/Server/Service.jl:1
in expression starting at /Users/jerdmanis/.julia/packages/PeaceFounder/H5E3m/src/Server/Server.jl:1
in expression starting at /Users/jerdmanis/.julia/packages/PeaceFounder/H5E3m/src/PeaceFounder.jl:1
in expression starting at stdin:

This can be resolved by adding Oxygen to the project which is a bit anoying. I think we can resolve this issue if the path to Oxygen library location could be resolved differently with a global variable at compile time or runtime by editing a following line in Oxygen.jl:

 include(joinpath(dirname(Base.find_package("Oxygen")), "methods.jl"))

At compile time it could look something like:

global OXYGEN_PATH::String =  Base.find_package("Oxygen")
...
include(joinpath(dirname(OXYGEN_PATH), "methods.jl"))
...

This however seems could pose issues when compilation cache is relocated which is also important for my usecase. Thus in situations where this does not work out for currently uknown reasons one could run a hack:

using Oxygen
Oxygen.OXYGEN_PATH = Base.find_package("Oxygen")
using MyPackage

which hopefully is never necessary.