@@ -10,68 +10,6 @@ def distinct(lst):
1010 d [i ] = True
1111 return d .keys ()
1212
13- def paths (resources , resource_strip_prefix ):
14- """Return a list of path tuples (target, source) where:
15- target - is a path in the archive (with given prefix stripped off)
16- source - is an absolute path of the resource file
17-
18- Tuple ordering is aligned with zipper format ie zip_path=file
19-
20- Args:
21- resources: list of file objects
22- resource_strip_prefix: string to strip from resource path
23- """
24- return [(_target_path (resource , resource_strip_prefix ), resource .path ) for resource in resources ]
25-
26- def _strip_prefix (path , prefix ):
27- return path [len (prefix ):] if path .startswith (prefix ) else path
28-
29- def _target_path (resource , resource_strip_prefix ):
30- path = _target_path_by_strip_prefix (resource , resource_strip_prefix ) if resource_strip_prefix else _target_path_by_default_prefixes (resource )
31- return _strip_prefix (path , "/" )
32-
33- def _target_path_by_strip_prefix (resource , resource_strip_prefix ):
34- # Start from absolute resource path and then strip roots so we get to correct short path
35- # resource.short_path sometimes give weird results ie '../' prefix
36- path = resource .path
37- if resource_strip_prefix != resource .owner .workspace_root :
38- path = _strip_prefix (path , resource .owner .workspace_root + "/" )
39- path = _strip_prefix (path , resource .root .path + "/" )
40-
41- # proto_library translates strip_import_prefix to proto_source_root which includes root so we have to strip it
42- prefix = _strip_prefix (resource_strip_prefix , resource .root .path + "/" )
43- if not path .startswith (prefix ):
44- fail ("Resource file %s is not under the specified prefix %s to strip" % (path , prefix ))
45- return path [len (prefix ):]
46-
47- def _target_path_by_default_prefixes (resource ):
48- path = resource .path
49-
50- # Here we are looking to find out the offset of this resource inside
51- # any resources folder. We want to return the root to the resources folder
52- # and then the sub path inside it
53- dir_1 , dir_2 , rel_path = path .partition ("resources" )
54- if rel_path :
55- return rel_path
56-
57- # The same as the above but just looking for java
58- (dir_1 , dir_2 , rel_path ) = path .partition ("java" )
59- if rel_path :
60- return rel_path
61-
62- # Both short_path and path have quirks we wish to avoid, in short_path there are times where
63- # it is prefixed by `../` instead of `external/`. And in .path it will instead return the entire
64- # bazel-out/... path, which is also wanting to be avoided. So instead, we return the short-path if
65- # path starts with bazel-out and the entire path if it does not.
66- return resource .short_path if path .startswith ("bazel-out" ) else path
67-
68- def restore_prefix (src , stripped ):
69- """opposite of _target_path. Given a source and stripped file, return the prefix """
70- if src .path .endswith (stripped ):
71- return src .path [:len (src .path )- len (stripped )]
72- else :
73- fail ("Resource file %s is not under the specified prefix %s to strip" % (src , stripped ))
74-
7513def argsfile_name (label ):
7614 return str (label ).replace ("@" ,"_" ).replace ("/" ,"_" ) + "_args"
7715
@@ -122,55 +60,51 @@ def clojure_jar_impl(ctx):
12260
12361 input_files = ctx .files .srcs + ctx .files .resources
12462
125- if len (input_files ):
126- src_dir = restore_prefix (input_files [0 ], _target_path (input_files [0 ], ctx .attr .resource_strip_prefix ))
127- else :
128- src_dir = None
129-
130- compile_classpath = compile_info .transitive_runtime_jars .to_list () + ctx .files .compiledeps + [classes_dir ]
131- compile_classpath = [f .path for f in compile_classpath ]
132- compile_classpath = compile_classpath + [p for p in [src_dir ] if p ]
63+ compile_classpath = depset (
64+ ctx .files .compiledeps + [classes_dir ],
65+ transitive = [compile_info .transitive_runtime_jars ],
66+ )
13367
13468 native_libs = []
135- for f in runfiles .files .to_list ():
136- ## Bazel on mac sticks weird looking directories in runfiles, like _solib_darwin/_U_S_Snative_C_Ulibsodium___Unative_Slibsodium_Slib. filter them out
137- if (f .path .endswith (".dylib" ) or f .path .endswith (".so" )) and (f .path .rfind ("solib_darwin" ) == - 1 ):
138- native_libs .append (f )
13969
14070 aot_nses = distinct (aot_nses )
14171
14272 javaopts_str = " " .join (ctx .attr .javacopts )
14373
144- compile_args = {"classes-dir" : classes_dir .path ,
145- "output-jar" : output_jar .path ,
146- "src-dir" : src_dir ,
147- "srcs" : [_target_path (s , ctx .attr .resource_strip_prefix ) for s in ctx .files .srcs ],
148- "resources" : [_target_path (s , ctx .attr .resource_strip_prefix ) for s in ctx .files .resources ],
149- "aot-nses" : aot_nses ,
150- "classpath" : compile_classpath }
74+ compile_args = ctx .actions .args ()
75+ compile_args .use_param_file ("@%s" , use_always = True )
76+
77+ compile_args .add_all ([classes_dir ], before_each = "--classes-dir" , expand_directories = False )
78+ compile_args .add_all ([output_jar ], before_each = "--output-jar" , expand_directories = False )
15179
152- args_file = ctx .actions .declare_file (argsfile_name (ctx .label ))
153- ctx .actions .write (
154- output = args_file ,
155- content = json .encode (compile_args ))
80+ if ctx .attr .resource_strip_prefix != "" :
81+ compile_args .add ("--resource-strip-prefix" )
82+ compile_args .add (ctx .attr .resource_strip_prefix )
15683
157- inputs = ctx .files .srcs + ctx .files .resources + compile_info .transitive_runtime_jars .to_list () + native_libs + [args_file ] + worker_classpath_depset .to_list ()
84+ compile_args .add_all (ctx .files .srcs , before_each = "--src" )
85+ compile_args .add_all (ctx .files .resources , before_each = "--resource" )
86+ compile_args .add_all (aot_nses , before_each = "--aot-nses" )
87+ compile_args .add ("--classpath" )
88+ compile_args .add_joined (compile_classpath , join_with = ":" )
15889
159- worker_classpath_str = ":" .join ([d .path for d in worker_classpath_depset .to_list ()])
90+ inputs = depset (
91+ ctx .files .srcs + ctx .files .resources + native_libs ,
92+ transitive = [compile_info .transitive_runtime_jars , worker_classpath_depset ],
93+ )
16094
16195 ctx .actions .run (
16296 executable = ctx .executable ._clojureworker_binary ,
16397 arguments =
16498 ["--jvm_flags=" + f for f in ctx .attr .jvm_flags ] +
165- ["-m" , "rules-clojure.worker" ,
166- "@%s" % args_file .path ],
99+ ["-m" , "rules-clojure.worker" ] + [compile_args ],
167100 outputs = [output_jar , classes_dir ],
168101 inputs = inputs ,
169102 mnemonic = "ClojureCompile" ,
170103 progress_message = "Compiling %s" % ctx .label ,
171104 execution_requirements = {"supports-workers" : "1" ,
172105 "supports-multiplex-workers" : "1" ,
173- "requires-worker-protocol" : "json" })
106+ "requires-worker-protocol" : "json" ,
107+ "supports-path-mapping" : "1" })
174108
175109 return [
176110 default_info ,
0 commit comments