@@ -27,17 +27,27 @@ def _parse_source(src):
2727 components = components ,
2828 )
2929
30- def _distroless_extension (module_ctx ):
30+ def _distroless_extension (mctx ):
3131 root_direct_deps = []
3232 root_direct_dev_deps = []
3333 reproducible = False
3434
35- for mod in module_ctx .modules :
36- deb_repo = deb_repository .new (module_ctx )
35+ for mod in mctx .modules :
36+
37+ lockf = lockfile .empty (mctx )
38+
39+ # if mod.is_root:
40+
41+ if len (mod .tags .lock ):
42+ lock = mod .tags .lock [0 ]
43+ lockf = lockfile .from_json (mctx , mctx .read (lock .into ))
44+
45+ deb_repo = deb_repository .new (mctx , lockf .facts ())
3746 resolver = dependency_resolver .new (deb_repo )
38- lockf = lockfile . empty ( module_ctx )
47+
3948
4049 for sl in mod .tags .sources_list :
50+ continue
4151 uris = [uri .removeprefix ("mirror+" ) for uri in sl .uris ]
4252 architectures = sl .architectures
4353
@@ -58,6 +68,7 @@ def _distroless_extension(module_ctx):
5868 sources = lockf .sources ()
5969 dependency_sets = lockf .dependency_sets ()
6070 for install in mod .tags .install :
71+ continue
6172 dependency_set = dependency_sets .setdefault (install .dependency_set , {
6273 "sets" : {},
6374 })
@@ -77,8 +88,8 @@ def _distroless_extension(module_ctx):
7788 arch = architectures .pop ()
7889 resolved_count = 0
7990
80- module_ctx .report_progress ("Resolving %s:%s" % (dep_constraint , arch ))
81- (package , dependencies , unmet_dependencies ) = resolver .resolve_all (
91+ mctx .report_progress ("Resolving %s:%s" % (dep_constraint , arch ))
92+ (package , dependencies , unmet_dependencies , warnings ) = resolver .resolve_all (
8293 name = constraint ["name" ],
8394 version = constraint ["version" ],
8495 arch = arch ,
@@ -93,9 +104,12 @@ def _distroless_extension(module_ctx):
93104 " 3 - Ensure that an apt.source_list added for the specified architecture." ,
94105 )
95106
107+ for warning in warnings :
108+ util .warning (mctx , warning )
109+
110+
96111 if len (unmet_dependencies ):
97- # buildifier: disable=print
98- util .warning (module_ctx , "Following dependencies could not be resolved for %s: %s" % (constraint ["name" ], "," .join ([up [0 ] for up in unmet_dependencies ])))
112+ util .warning (mctx , "Following dependencies could not be resolved for %s: %s" % (constraint ["name" ], "," .join ([up [0 ] for up in unmet_dependencies ])))
99113
100114 lockf .add_package (package )
101115
@@ -110,15 +124,15 @@ def _distroless_extension(module_ctx):
110124 arch_set [lockfile .short_package_key (package )] = package ["Version" ]
111125
112126 # For cases where architecture for the package is not specified we need
113- # to first find out which source contains the package. and in order to do
127+ # to first find out which source contains the package. in order to do
114128 # that we first need to resolve the package for amd64 architecture.
115129 # Once the repository is found, then resolve the package for all the
116130 # architectures the repository supports.
117131 if not constraint ["arch" ] and arch == "amd64" :
118132 source = sources [package ["Dist" ]]
119133 architectures = [a for a in source ["architectures" ] if a != "amd64" ]
120134
121- module_ctx .report_progress ("Resolved %d packages for %s" % (resolved_count , arch ))
135+ mctx .report_progress ("Resolved %d packages for %s" % (resolved_count , arch ))
122136
123137 # Generate a hub repo for every dependency set
124138 lock_content = lockf .as_json ()
@@ -131,23 +145,36 @@ def _distroless_extension(module_ctx):
131145
132146 # Generate a repo per package which will be aliased by hub repo.
133147 for (package_key , package ) in lockf .packages ().items ():
148+ # dependent_packages = None
149+ # if package["name"].endswith("-dev")
150+ # packages = lockf.packages()
151+ # dependent_packages = json.encode([
152+
153+ # ])
154+
134155 deb_import (
135156 name = util .sanitize (package_key ),
157+ target_name = util .sanitize (package_key ),
136158 urls = [
137159 uri + "/" + package ["filename" ]
138160 for uri in sources [package ["suite" ]]["uris" ]
139161 ],
140162 sha256 = package ["sha256" ],
141163 mergedusr = False ,
142- depends_on = ["@" + util .sanitize (dep_key ) for dep_key in package ["depends_on" ]],
164+ depends_on = package ["depends_on" ],
165+ package_name = package ["name" ]
143166 )
144167
145- lock_tmp = module_ctx .path ("apt.lock.json" )
146- lockf .write (lock_tmp )
147- lockf_wksp = module_ctx .path (Label ("@//:apt.lock.json" ))
148- module_ctx .execute (
149- ["mv" , lock_tmp , lockf_wksp ],
150- )
168+
169+
170+
171+ for lock in mod .tags .lock :
172+ lock_tmp = mctx .path ("apt.lock.json" )
173+ lockf .write (lock_tmp )
174+ lockf_wksp = mctx .path (lock .into )
175+ mctx .execute (
176+ ["cp" , "-f" , lock_tmp , lockf_wksp ],
177+ )
151178
152179_doc = """
153180Module extension to create Debian repositories.
@@ -261,11 +288,21 @@ install = tag_class(
261288 },
262289)
263290
291+
292+ lock = tag_class (
293+ attrs = {
294+ "into" : attr .label (
295+ mandatory = True ,
296+ ),
297+ },
298+ )
299+
264300apt = module_extension (
265301 doc = _doc ,
266302 implementation = _distroless_extension ,
267303 tag_classes = {
268304 "install" : install ,
269305 "sources_list" : sources_list ,
306+ "lock" : lock ,
270307 },
271308)
0 commit comments