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
|
# File 'lib/pray/materialize.rb', line 7
def materialize_project(
manifest_path: nil,
frozen: false,
locked: false,
offline: false,
refresh: false
)
context = Invocation.invocation_context
manifest_path = File.expand_path(manifest_path || context.manifest_path)
unless File.exist?(manifest_path)
raise Error.manifest("missing #{manifest_path}")
end
project_root = context.project_root
options = ResolveOptions.new(
offline: offline,
refresh: refresh,
environment: context.environment
)
allow_git_refresh_fallback = !locked && !frozen
project = begin
Resolve.resolve_project_in_context(manifest_path, project_root, options)
rescue Error => error
if allow_git_refresh_fallback &&
!offline &&
!refresh &&
Resolve.resolution_may_benefit_from_git_source_refresh?(error)
refreshed = options.dup
refreshed.refresh = true
Resolve.resolve_project_in_context(manifest_path, project_root, refreshed)
else
raise
end
end
rendered = Render.render_project(project)
lockfile_path = default_lockfile_path(project.project_root)
next_lockfile = LockfileIO.build_lockfile(
project.manifest_hash,
project.environment,
project.project_root,
project.manifest.sources,
project.manifest.targets,
rendered,
project.packages,
project.source_revisions,
project.source_host_keys
)
if locked
unless File.exist?(lockfile_path)
raise Error.verify("missing Prayfile.lock; run install first")
end
existing = Pray.read_lockfile(lockfile_path)
unless Pray.lockfiles_equivalent?(existing, next_lockfile)
raise Error.verify("lockfile needs update; rerun install to refresh Prayfile.lock")
end
unless frozen
Render.write_rendered_targets(project, rendered)
end
if frozen
rendered.each do |target|
path = File.join(project.project_root, target.path)
on_disk = File.read(path)
if on_disk != target.content
raise Error.render(
"#{path} is stale; rerun install to regenerate it or plan to inspect the diff"
)
end
end
end
return
end
if frozen
existing = File.exist?(lockfile_path) ? Pray.read_lockfile(lockfile_path) : nil
if existing
rendered.each do |target|
output_path = File.join(project.project_root, target.path)
unless File.exist?(output_path)
raise Error.verify("Rendered file #{target.path} is missing under frozen mode")
end
end
end
end
Pray.write_lockfile_if_changed(lockfile_path, next_lockfile)
Render.write_rendered_targets(project, rendered)
end
|