-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shading #108
Shading #108
Conversation
Some comments:
|
I am not aware of how this issue interacts with C#. Java is the primary language I can think of where groups of packages are loaded as modules at once, and don't allow or resolve conflicts.
Gradle and Maven are provided Java source, and the source is modified during the built process.
Agreed.
I can't think of one, honestly. Maybe if you want to give a class a name that is a reserved word in the target language?
I'm not sure about the current solution for dealing with multiple JARs with different Haxe versions (if there even is one), but with shading (I agree, need a better, unambiguous name) you can simply shade one JAR's Haxe implementation into one package and the other JAR's implementation into another, with the result being there are now two sets of Haxe packages loaded, essentially including the specific version of the Haxe libs as a dependency. |
Hmm. Sounds like this could be accomplished with |
I don't know how @:native behaves with non-extern Haxe classes, but this definitely doesn't work if you need to shade the |
Here's a rough sketch of how one would apply it across a package: import haxe.macro.Context.*;
import haxe.macro.Type;
using StringTools;
function apply(from:String, to:String) {
function dotPad(s:String)
return if (s.endsWith('.')) s else '$s.';
from = dotPad(from);
to = dotPad(to);
onGenerate(types -> {
function applyTo<T:BaseType>(r:Ref<T>)
switch r.toString() {
case _.startsWith(from) => false:
case match:
r.get().meta.add(':native', [macro $v{to + match.substr(from.length)}], (macro null).pos);
}
for (t in types)
switch t {
case TInst(r, _): applyTo(r);
case TEnum(r, _): applyTo(r);
default:
}
});
} Then execute it like this: -main haxe.Main
-java .
-D jvm
-dce full
--macro Shade.apply('haxe', 'my.shaded.hx') Which will work like so: package haxe;
function main() {
trace(Foo); // class my.shaded.hx.Foo
trace(Bar); // class my.shaded.hx._Main.Bar
trace(haxe.ds.StringMap); // class my.shaded.hx.ds.StringMap
}
class Foo {}
private class Bar {} |
Apparently my argument against Haxe's omissions is invalid because MACROS! I think that having this as a standalone HaxeLib would be great, if you want to clean it up and publish it let me know, and if not I can do it. How does this interact with abstracts btw? Does it properly move the private implementation class over? |
Depends very much on the omissions. But for customizing output, I think you'll find that when it's doable via macros, it's the most customizable solution.
Yes. Those implementation classes make it into the
Please feel free to go ahead. I have no need for such a library and would thus make for a lousy maintainer. |
An update on this proposal: As far as I'm aware, this issue of duplicate classpaths only occurs on the Java platform (and other targets do not experience these issues), thus the necessity for a shading functionality which is applied to all languages is greatly diminished. However, when experimenting with the code provided by back2dos, I determined that using I have thus been developing a library which provides macros to calculate and apply the Of note, however, is the fact that using a macro to apply Once that is done, the library linked above should be fully capable of performing everything I needed from this proposal. Therefore it is redundant, and I will mark this as closed. It can be reopened in the future if there are other issues or a valid use case arises that is not already covered by existing functionality. |
Provide the ability to rename and transform package and class names of types during compilation.
Rendered proposal