google / bazel-common

Common functionality for Google's open-source libraries that are built with bazel.
Apache License 2.0
84 stars 40 forks source link

Issue running jarjar with a rule file #150

Closed christian-lefty closed 2 years ago

christian-lefty commented 2 years ago

I tried to do this:

jarjar_library(
    name = "shaded_" + name + "_deploy",
    rules = ["shade_rules_hadoop"],
)

But got an error:

find: 'META-INF': No such file or directory rm: cannot remove 'build-data.properties': No such file or directory rm: cannot remove 'META-INF/MANIFEST.MF': No such file or directory find: '*': No such file or directory

Do you have any example of running jarjar with a rules file?

Best,

chaoren commented 2 years ago

Rules file refers to this: https://code.google.com/archive/p/jarjar/wikis/CommandLineDocs.wiki

Rules file format

The rules file is a text file, one rule per line. Leading and trailing whitespace is ignored. There are three types of rules:

rule <pattern> <result> zap <pattern> keep <pattern>

The standard rule (rule) is used to rename classes. All references to the renamed classes will also be updated. If a class name is matched by more than one rule, only the first one will apply.

<pattern> is a class name with optional wildcards. ** will match against any valid class name substring. To match a single package component (by excluding . from the match), a single * may be used instead.

<result> is a class name which can optionally reference the substrings matched by the wildcards. A numbered reference is available for every * or ** in the <pattern>, starting from left to right: @1, @2, etc. A special @0 reference contains the entire matched class name.

The zap rule causes any matched class to be removed from the resulting jar file. All zap rules are processed before renaming rules.

The keep rule marks all matched classes as "roots". If any keep rules are defined all classes which are not reachable from the roots via dependency analysis are discarded when writing the output jar. This is the last step in the process, after renaming and zapping.

I'm assuming you have it confused with a bazel rule? It's a text file (usually .txt) and you still need jars on which to apply the rules.

christian-lefty commented 2 years ago

It just doesn't seem that rules = ["shade_rules_hadoop"], is passed to the jarjar command correctly so I was wondering if there is any test of example for setting the rules?

chaoren commented 2 years ago

Could you share the definition/contents of this shade_rules_hadoop? Can't really help you if you don't provide more details.