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

use artifacts, remove BinaryProvider dependency #5

Merged
merged 1 commit into from
Apr 9, 2020
Merged
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
13 changes: 10 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@
language: julia
os:
- linux
- osx
julia:
- 1.0
- 1.1
- 1.3
- 1.4
- nightly
matrix:
allow_failures:
- julia: nightly
notifications:
email: false
# uncomment the following lines to override the default test script
#script: # the default script is equivalent to the following
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia -e 'Pkg.clone(pwd()); Pkg.build("GoogleCodeSearch"); Pkg.test("GoogleCodeSearch"; coverage=true)';
after_success:
- julia -e 'if VERSION >= v"0.7.0-" using Pkg end; cd(Pkg.dir("GoogleCodeSearch")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())';
# push coverage results to Coveralls
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())';
# push coverage results to Codecov
#- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
10 changes: 6 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name = "GoogleCodeSearch"
uuid = "be5e5202-b427-58d6-b196-3d129152056c"
authors = ["Tanmay Mohapatra <[email protected]>"]
version = "0.1.1"
version = "0.2.0"

[deps]
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
GoogleCodeSearch_jll = "6c08f7c7-e449-597e-96d3-8117915de277"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand All @@ -17,5 +17,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
test = ["Test"]

[compat]
julia = "~1"
HTTP = "~0.8"
julia = "1.3,1.4"
HTTP = "0.8"
JSON = "0.21"
GoogleCodeSearch_jll = "1.2"
3 changes: 0 additions & 3 deletions deps/.gitignore

This file was deleted.

38 changes: 0 additions & 38 deletions deps/build.jl

This file was deleted.

7 changes: 1 addition & 6 deletions src/GoogleCodeSearch.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
module GoogleCodeSearch

using BinaryProvider
using Sockets
using JSON
using HTTP
using GoogleCodeSearch_jll

import Base: show
export Ctx, index, search, show, indices, clear_indices, paths_indexed, run_http

const depsjl_path = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
if !isfile(depsjl_path)
error("GoogleCodeSearch not installed properly, run Pkg.build(\"GoogleCodeSearch\"), restart Julia and try again")
end
include(depsjl_path)
include("codesearch.jl")
include("server.jl")

Expand Down
54 changes: 44 additions & 10 deletions src/codesearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,39 @@ end
show(io::IO, ctx::Ctx) = print(io, "GoogleCodeSearch.Ctx(store=\"" * ctx.store * "\")")

function readcmd_with_index(ctx::Ctx, cmd::Cmd, idxpath::String)
oc = lock(ctx.lock) do
pipe_out = Pipe()
pipe_err = Pipe()
proc = lock(ctx.lock) do
withenv("CSEARCHINDEX"=>idxpath) do
OutputCollector(cmd)
run(pipeline(cmd, stdout=pipe_out, stderr=pipe_err), wait=false)
end
end
success = wait(oc)
success, oc.stdout_linestream.lines, oc.stderr_linestream.lines

success = false
stdout_buff = PipeBuffer()
stderr_buff = PipeBuffer()

@sync begin
@async begin
wait(proc)
success = (proc.exitcode == 0)
close(Base.pipe_writer(pipe_out))
close(Base.pipe_writer(pipe_err))
end
@async begin
reader_out = Base.pipe_reader(pipe_out)
while !(eof(reader_out))
write(stdout_buff, readavailable(reader_out))
end
end
@async begin
reader_err = Base.pipe_reader(pipe_err)
while !(eof(reader_err))
write(stderr_buff, readavailable(reader_err))
end
end
end
success, readlines(stdout_buff; keep=true), readlines(stderr_buff; keep=true)
end

"""
Expand All @@ -44,11 +70,13 @@ Returns a list of paths that have been indexed.
"""
function paths_indexed(ctx::Ctx)
paths = Set{String}()
cmd = Cmd([cindex, "-list"])
cmd = cindex() do cindex_path
Cmd([cindex_path, "-list"])
end
for idxpath in indices(ctx)
success, out, err = readcmd_with_index(ctx, cmd, idxpath)
if success
for (t,m) in out
for m in out
push!(paths, strip(m))
end
else
Expand All @@ -62,7 +90,9 @@ end
Index paths by calling the index method. While indexing, ensure paths are sorted such that paths appearing later are not substrings of those earlier. Otherwise, the earlier indexed entries are erased (strange behavior of `cindex`).
"""
function index(ctx::Ctx, path::String)
cmd = Cmd([cindex, path])
cmd = cindex() do cindex_path
Cmd([cindex_path, path])
end
success, out, err = readcmd_with_index(ctx, cmd, ctx.resolver(ctx,path))
success
end
Expand All @@ -76,7 +106,9 @@ function index(ctx::Ctx, paths::Vector{String})
end
results = Bool[]
for (idxpath, paths) in idxpaths
cmd = Cmd(append!([cindex], paths))
cmd = cindex() do cindex_path
Cmd(append!([cindex_path], paths))
end
success, out, err = readcmd_with_index(ctx, cmd, idxpath)
push!(results, success)
end
Expand All @@ -94,7 +126,9 @@ The search method returns a vector of named tuples, each describing a match.
- `text`: text that matched
"""
function search(ctx::Ctx, pattern::String; ignorecase::Bool=false, pathfilter::Union{Nothing,String}=nothing, maxresults::Int=20)
cmdparts = [csearch]
cmdparts = csearch() do csearch_path
[csearch_path]
end
if pathfilter !== nothing
push!(cmdparts, "-f")
push!(cmdparts, pathfilter)
Expand All @@ -108,7 +142,7 @@ function search(ctx::Ctx, pattern::String; ignorecase::Bool=false, pathfilter::U
idxpath = joinpath(ctx.store, idx)
success, out, err = readcmd_with_index(ctx, cmd, idxpath)
if success
for (_,s) in out
for s in out
s = strip(s)
( isempty(s) || !startswith(s, "/")) && continue
parts = split(s, ':'; limit=3)
Expand Down