-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_julia_project_offline.jl
188 lines (162 loc) · 7.72 KB
/
export_julia_project_offline.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import Pkg
import Pkg.Types
import Pkg.Types:Context,PackageSpec,project_deps_resolve!,registry_resolve!,stdlib_resolve!,ensure_resolved,manifest_info,pkgerror,printpkgstyle,is_stdlib,write_env,projectfile_path
import Pkg:activate
import Pkg.Operations
import Pkg.Operations:source_path,download_source,load_urls,is_dep,update_package_add,load_direct_deps!,check_registered,resolve_versions!,update_manifest!,tracking_registered_version,install_archive,install_git,set_readonly,find_installed,gen_build_code,build_versions,dependency_order_uuids,buildfile,project_rel_path,backwards_compat_for_build,sandbox,testdir,builddir
import Pkg:depots1
using UUIDs
import LibGit2
join_external_source(path_to_external,path_to_source) = joinpath(path_to_external,splitpath(path_to_source)[end-1:end]...)
function source_path(pkg::PackageSpec,path_to_external)
return is_stdlib(pkg.uuid) ? Types.stdlib_path(pkg.name) :
pkg.repo.url !== nothing ? join_external_source(path_to_external,find_installed(pkg.name, pkg.uuid, pkg.tree_hash)) :
pkg.tree_hash !== nothing ? join_external_source(path_to_external,find_installed(pkg.name, pkg.uuid, pkg.tree_hash)) :
nothing
end
function download_source(ctx::Context, pkgs::Vector{PackageSpec},path; readonly=true)
pkgs = filter(tracking_registered_version, pkgs)
urls = load_urls(ctx, pkgs)
return download_source(ctx, pkgs, urls, path; readonly=readonly)
end
function download_source(ctx::Context, pkgs::Vector{PackageSpec},
urls::Dict{UUID, Vector{String}},path_to_external; readonly=true)
Pkg.BinaryProvider.probe_platform_engines!()
new_versions = UUID[]
pkgs_to_install = Tuple{PackageSpec, String}[]
for pkg in pkgs
path = source_path(pkg,path_to_external)
ispath(path) && continue
push!(pkgs_to_install, (pkg, path))
push!(new_versions, pkg.uuid)
end
widths = [textwidth(pkg.name) for (pkg, _) in pkgs_to_install]
max_name = length(widths) == 0 ? 0 : maximum(widths)
########################################
# Install from archives asynchronously #
########################################
jobs = Channel(ctx.num_concurrent_downloads);
results = Channel(ctx.num_concurrent_downloads);
@async begin
for pkg in pkgs_to_install
put!(jobs, pkg)
end
end
for i in 1:ctx.num_concurrent_downloads
@async begin
for (pkg, path) in jobs
if ctx.preview
put!(results, (pkg, true, path))
continue
end
if ctx.use_libgit2_for_all_downloads
put!(results, (pkg, false, path))
continue
end
try
success = install_archive(urls[pkg.uuid], pkg.tree_hash, path)
if success && readonly
set_readonly(path) # In add mode, files should be read-only
end
if ctx.use_only_tarballs_for_downloads && !success
pkgerror("failed to get tarball from $(urls[pkg.uuid])")
end
put!(results, (pkg, success, path))
catch err
put!(results, (pkg, err, catch_backtrace()))
end
end
end
end
missed_packages = Tuple{PackageSpec, String}[]
for i in 1:length(pkgs_to_install)
pkg, exc_or_success, bt_or_path = take!(results)
exc_or_success isa Exception && pkgerror("Error when installing package $(pkg.name):\n",
sprint(Base.showerror, exc_or_success, bt_or_path))
success, path = exc_or_success, bt_or_path
if success
vstr = pkg.version != nothing ? "v$(pkg.version)" : "[$h]"
printpkgstyle(ctx, :Installed, string(rpad(pkg.name * " ", max_name + 2, "─"), " ", vstr))
else
push!(missed_packages, (pkg, path))
end
end
##################################################
# Use LibGit2 to download any remaining packages #
##################################################
for (pkg, path) in missed_packages
uuid = pkg.uuid
if !ctx.preview
install_git(ctx, pkg.uuid, pkg.name, pkg.tree_hash, urls[uuid], pkg.version::VersionNumber, path)
readonly && set_readonly(path)
end
vstr = pkg.version != nothing ? "v$(pkg.version)" : "[$h]"
printpkgstyle(ctx, :Installed, string(rpad(pkg.name * " ", max_name + 2, "─"), " ", vstr))
end
return new_versions
end
function main(path_to_project,path_to_external)
!isdir(path_to_external) ? mkdir(path_to_external) : nothing
activate(path_to_project)
ctx=Context()
println("Project Path : " * path_to_project)
println("Using : " * ctx.env.manifest_file * "\n"
*" " * ctx.env.project_file)
println("Copying these files to " * path_to_external)
Base.cp(ctx.env.project_file,joinpath(path_to_external,basename(ctx.env.project_file)),force=true)
Base.cp(ctx.env.manifest_file,joinpath(path_to_external,basename(ctx.env.manifest_file)),force=true)
project = ctx.env.project
registry_path = joinpath(depots1(),"registries")
registry_path_extern = joinpath(path_to_external,"registries")
mkpath(registry_path_extern)
Base.cp(registry_path,registry_path_extern,force=true)
pkgs = [ PackageSpec(k,v) for (k,v) in project.deps ]
project_deps_resolve!(ctx.env,pkgs)
registry_resolve!(ctx.env,pkgs)
stdlib_resolve!(ctx,pkgs)
ensure_resolved(ctx.env,pkgs)
for (i, pkg) in pairs(pkgs)
entry = manifest_info(ctx.env, pkg.uuid)
pkgs[i] = update_package_add(pkg, entry, is_dep(ctx.env, pkg))
end
foreach(pkg -> ctx.env.project.deps[pkg.name] = pkg.uuid, pkgs) # update set of deps
load_direct_deps!(ctx, pkgs)
check_registered(ctx, pkgs)
resolve_versions!(ctx, pkgs)
update_manifest!(ctx, pkgs)
uuids = download_source(ctx, pkgs,path_to_external;readonly=false)
write_env(ctx) # write env before building
ctx.preview && (printpkgstyle(ctx, :Building, "skipping building in preview mode"); return)
builds = Tuple{String,String}[]
for uuid in uuids
uuid in keys(ctx.stdlibs) && continue
if Types.is_project_uuid(ctx.env, uuid)
path = dirname(ctx.env.project_file)
name = ctx.env.pkg.name
version = ctx.env.pkg.version
else
entry = manifest_info(ctx.env, uuid)
name = entry.name
if entry.tree_hash !== nothing
path = join_external_source(path_to_external,find_installed(name, uuid, entry.tree_hash))
elseif entry.path !== nothing
path = project_rel_path(ctx, entry.path)
else
pkgerror("Could not find either `git-tree-sha1` or `path` for package $name")
end
version = v"0.0"
end
ispath(path) || error("Build path for $name does not exist: $path")
ispath(buildfile(path)) && push!(builds, (name, buildfile(path)))
end
return builds
end
path_to_project = abspath(ARGS[1])
ispath(path_to_project) || error("First argument must be the existent path of your project")
path_to_external = abspath(ARGS[2])
ispath(path_to_external) || mkpath(path_to_external)
path_to_external == path_to_project && error("Both paths cannot be equal")
builds=main(path_to_project,path_to_external)
file = open("to_build.txt","w")
foreach( b -> write(file,b[2]*'\n'),builds)
close(file)