Skip to content

Commit

Permalink
Merge pull request #32 from zgornel/latest
Browse files Browse the repository at this point in the history
PackageCompiler v1.0+ support
  • Loading branch information
zgornel committed Mar 16, 2020
2 parents 0477831 + a4de7b6 commit 58de127
Show file tree
Hide file tree
Showing 15 changed files with 1,046 additions and 201 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*~
__*
*.swp
build/bin/
build/compiled/
docs/build/
benchmarks/
scripts/
Expand Down
70 changes: 70 additions & 0 deletions apps/garc/Manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# This file is machine-generated - editing it directly is not advised

[[ArgParse]]
deps = ["Logging", "TextWrap"]
git-tree-sha1 = "a8fc2e149cd6db276c76faebe197ccd3a92fb9ff"
uuid = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
version = "1.1.0"

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.0"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[Parsers]]
deps = ["Dates", "Test"]
git-tree-sha1 = "0c16b3179190d3046c073440d94172cfc3bb0553"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "0.3.12"

[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[TextWrap]]
git-tree-sha1 = "9250ef9b01b66667380cf3275b3f7488d0e25faf"
uuid = "b718987f-49a8-5099-9789-dcd902bef87d"
version = "1.0.1"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
10 changes: 10 additions & 0 deletions apps/garc/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name = "garc"
uuid = "24b91db2-76cd-4d2b-a5dc-3a2aa5018a08"
authors = ["Corneliu Cofaru <cornel@oxoaresearch.com>"]
version = "0.1.0"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
4 changes: 4 additions & 0 deletions apps/garc/precompile_app.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using garc

push!(ARGS, "arg")
garc.julia_main()
98 changes: 56 additions & 42 deletions garc → apps/garc/src/garc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,15 @@
#############################################
# Garamond script for CLI client operations #
#############################################
module GaramondCLIClient

module garc # The Garamond client

using Sockets
using ArgParse
using Logging
using JSON


########################
# Main client function #
########################
Base.@ccallable function julia_main(ARGS::Vector{String})::Cint
# Parse command line arguments
args = get_unix_socket_client_arguments(ARGS)

# Logging
log_levels = Dict("debug" => Logging.Debug,
"info" => Logging.Info,
"warning" => Logging.Warn,
"error" => Logging.Error)
logger = ConsoleLogger(stdout,
get(log_levels, lowercase(args["log-level"]), Logging.Info))
global_logger(logger)

# Start client
@debug "~ GARAMOND~ (unix-socket client)"
unixsocket = args["unix-socket"]
if issocket(unixsocket)
conn = connect(unixsocket)
if isempty(args["query"]) && !args["kill"]
@warn "Empty query, nothing to search. Exiting..."
else
# Construct Garamond request
request = construct_json_request(args)
# Search
iosearch(conn, request, args["pretty"])
end
# Close connection and exit
close(conn)
else
@warn "$unixsocket is not a proper UNIX socket. Exiting..."
end
return 0
end


# Support for parsing to Symbol for the ArgParse package
import ArgParse: parse_item
function ArgParse.parse_item(::Type{Symbol}, x::AbstractString)
Expand All @@ -59,7 +22,7 @@ end
# Function that parses Garamond's unix-socket client arguments
function get_unix_socket_client_arguments(args::Vector{String})
s = ArgParseSettings()
@add_arg_table s begin
@add_arg_table! s begin
"query"
help = "the search query"
arg_type = String
Expand Down Expand Up @@ -221,9 +184,60 @@ function iosearch(connection, request, pretty=false)
end


########################
# Main module function #
########################
function julia_main()::Cint
try
real_main()
catch
Base.invokelatest(Base.display_error, Base.catch_stack())
return 1
end
return 0
end


function real_main()
# Parse command line arguments
args = get_unix_socket_client_arguments(ARGS)

# Logging
log_levels = Dict("debug" => Logging.Debug,
"info" => Logging.Info,
"warning" => Logging.Warn,
"error" => Logging.Error)
logger = ConsoleLogger(stdout,
get(log_levels, lowercase(args["log-level"]), Logging.Info))
global_logger(logger)

# Start client
@debug "~ GARAMOND~ (unix-socket client)"
unixsocket = args["unix-socket"]
if issocket(unixsocket)
conn = connect(unixsocket)
if isempty(args["query"]) && !args["kill"]
@warn "Empty query, nothing to search. Exiting..."
else
# Construct Garamond request
request = construct_json_request(args)
# Search
iosearch(conn, request, args["pretty"])
end
# Close connection and exit
close(conn)
else
@warn "$unixsocket is not a proper UNIX socket. Exiting..."
end
return 0
end


##############
# Run client #
##############
julia_main(ARGS)
if abspath(PROGRAM_FILE) == @__FILE__
real_main()
end

end # GaramondCLIClient
end # module
Loading

0 comments on commit 58de127

Please sign in to comment.