Skip to content

Commit ff55af2

Browse files
KristofferCKristofferC
andcommitted
add update function to apps and fix a bug when adding an already installed app (#4263)
Co-authored-by: KristofferC <[email protected]> (cherry picked from commit e3d4561)
1 parent 6f89667 commit ff55af2

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed

src/Apps/Apps.jl

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ function _resolve(manifest::Manifest, pkgname=nothing)
111111
# TODO: Julia path
112112
generate_shims_for_apps(pkg.name, pkg.apps, dirname(projectfile), joinpath(Sys.BINDIR, "julia"))
113113
end
114-
115114
write_manifest(manifest, app_manifest_file())
116115
end
117116

@@ -145,10 +144,12 @@ function add(pkg::PackageSpec)
145144
new = Pkg.Operations.download_source(ctx, pkgs)
146145
end
147146

147+
# Run Pkg.build()?
148+
149+
Base.rm(joinpath(app_env_folder(), pkg.name); force=true, recursive=true)
148150
sourcepath = source_path(ctx.env.manifest_file, pkg)
149151
project = get_project(sourcepath)
150152
# TODO: Wrong if package itself has a sourcepath?
151-
152153
entry = PackageEntry(;apps = project.apps, name = pkg.name, version = project.version, tree_hash = pkg.tree_hash, path = pkg.path, repo = pkg.repo, uuid=pkg.uuid)
153154
manifest.deps[pkg.uuid] = entry
154155

@@ -193,6 +194,50 @@ function develop(pkg::PackageSpec)
193194
@info "For package: $(pkg.name) installed apps: $(join(keys(project.apps), ","))"
194195
end
195196

197+
198+
update(pkgs_or_apps::String) = update([pkgs_or_apps])
199+
function update(pkgs_or_apps::Vector)
200+
for pkg_or_app in pkgs_or_apps
201+
if pkg_or_app isa String
202+
pkg_or_app = PackageSpec(pkg_or_app)
203+
end
204+
update(pkg_or_app)
205+
end
206+
end
207+
208+
function update(pkg::Union{PackageSpec, Nothing}=nothing)
209+
ctx = app_context()
210+
manifest = ctx.env.manifest
211+
deps = Pkg.Operations.load_manifest_deps(manifest)
212+
for dep in deps
213+
info = manifest.deps[dep.uuid]
214+
if pkg === nothing || info.name !== pkg.name
215+
continue
216+
end
217+
Pkg.activate(joinpath(app_env_folder(), info.name)) do
218+
# precompile only after updating all apps?
219+
if pkg !== nothing
220+
Pkg.update(pkg)
221+
else
222+
Pkg.update()
223+
end
224+
end
225+
sourcepath = abspath(source_path(ctx.env.manifest_file, info))
226+
project = get_project(sourcepath)
227+
# Get the tree hash from the project file
228+
manifest_file = manifestfile_path(joinpath(app_env_folder(), info.name))
229+
manifest_app = Pkg.Types.read_manifest(manifest_file)
230+
manifest_entry = manifest_app.deps[info.uuid]
231+
232+
entry = PackageEntry(;apps = project.apps, name = manifest_entry.name, version = manifest_entry.version, tree_hash = manifest_entry.tree_hash,
233+
path = manifest_entry.path, repo = manifest_entry.repo, uuid = manifest_entry.uuid)
234+
235+
manifest.deps[dep.uuid] = entry
236+
Pkg.Types.write_manifest(manifest, app_manifest_file())
237+
end
238+
return
239+
end
240+
196241
function status(pkgs_or_apps::Vector)
197242
if isempty(pkgs_or_apps)
198243
status()
@@ -257,8 +302,7 @@ end
257302

258303

259304
function require_not_empty(pkgs, f::Symbol)
260-
261-
if pkgs == nothing || isempty(pkgs)
305+
if pkgs === nothing || isempty(pkgs)
262306
pkgerror("app $f requires at least one package")
263307
end
264308
end
@@ -306,7 +350,7 @@ function rm(pkg_or_app::Union{PackageSpec, Nothing}=nothing)
306350
end
307351
end
308352
end
309-
353+
# XXX: What happens if something fails above and we do not write out the updated manifest?
310354
Pkg.Types.write_manifest(manifest, app_manifest_file())
311355
return
312356
end

src/REPLMode/command_declarations.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,21 @@ pkg> app develop ~/mypackages/Example
647647
pkg> app develop --local Example
648648
```
649649
"""
650+
],
651+
PSA[:name => "update",
652+
:short_name => "up",
653+
:api => Apps.update,
654+
:completions => :complete_installed_apps,
655+
:should_splat => false,
656+
:arg_count => 0 => Inf,
657+
:arg_parser => parse_package,
658+
:description => "update app",
659+
:help => md"""
660+
app update pkg
661+
662+
Updates the apps for packages `pkg...` or apps `app...`.
663+
```
664+
""",
650665
], # app
651666
]
652667
] #command_declarations

0 commit comments

Comments
 (0)