This is an archive of the discontinued LLVM Phabricator instance.

llvm-mt: implement simple merging of manifests, not factoring namespaces.
ClosedPublic

Authored by ecbeckmann on Jul 21 2017, 6:01 PM.

Details

Summary

Does a simple merge, where mergeable elements are combined, all others
are appended. Does not apply trickly namespace rules.

Diff Detail

Repository
rL LLVM

Event Timeline

ecbeckmann created this revision.Jul 21 2017, 6:01 PM

added additional test.

ruiu added inline comments.Jul 24 2017, 3:06 PM
llvm/include/llvm/Support/WindowsManifestMerger.h
38 ↗(On Diff #107974)

Even if C++11 allows this style, I think inserting = like this is more common.

MT_String[] = {
70 ↗(On Diff #107974)

Conditionally defining a dtor seems tricky. It is probably better to define this regardless of the presence of libxml and do nothing if libxml is not available.

84 ↗(On Diff #107974)

Likewise, always define this variable and don't use it if libxml is not available.

llvm/lib/Support/WindowsManifestMerger.cpp
29 ↗(On Diff #107974)

Prefix + Message?

34 ↗(On Diff #107974)

I think a better way of writing this without a global variable is this.

for (StringRef S : {"application",         "assembly",  "assemblyIdentity",
                    "compatibility",       "noInherit", "requestedExecutionLevel",
                    "requestedPrivileges", "security",  "trustInfo"}) {
  if (S == ElementName)
    return true;
}
return false;
ecbeckmann marked 4 inline comments as done.

Don't conditionally define destructor, remove global.

llvm/include/llvm/Support/WindowsManifestMerger.h
84 ↗(On Diff #107974)

Unfortunately this will cause the sanitizer to complain that "CombinedDoc is never used".

ruiu added inline comments.Jul 24 2017, 4:28 PM
llvm/include/llvm/Support/WindowsManifestMerger.h
52 ↗(On Diff #107988)

Why do you need this? Looks like you can just concatenate a string before passing it to the ctor.

llvm/lib/Support/WindowsManifestMerger.cpp
34 ↗(On Diff #107988)

Format

99 ↗(On Diff #107988)

Do you need this reinterpret_cast? It looks like Child->name is of xmlChar * which is a typedef to unsigned char *.

99 ↗(On Diff #107988)

Reverse the condition so that you can continue early.

110–111 ↗(On Diff #107988)

else if instead of else { if ... }.

126 ↗(On Diff #107988)

Format

ecbeckmann marked 4 inline comments as done.

Take away extraneous error constructor. Some format changes.

ecbeckmann added inline comments.Jul 24 2017, 5:06 PM
llvm/lib/Support/WindowsManifestMerger.cpp
99 ↗(On Diff #107988)

unfortunately const char * and const unsigned char * are technically not related types, and must be casted back and forth to each other.

126 ↗(On Diff #107988)

where is format error here?

ruiu added inline comments.Jul 25 2017, 12:37 PM
llvm/lib/Support/WindowsManifestMerger.cpp
33 ↗(On Diff #107995)

I think you can remove explicit instantiation of StringRef.

99 ↗(On Diff #107988)

Is it done?

126 ↗(On Diff #107988)

There wasn't a space between for and (. Now you have it. It is probably worth reviewing your patch yourself on Phabricator after you upload a new one, as I could easily find multiple trivial errors such as indentation errors, and it is easy to find errors on Phab rather than on an editor for some reason. :)

ecbeckmann marked an inline comment as done.

Early return, remove explicit StringRef

llvm/lib/Support/WindowsManifestMerger.cpp
99 ↗(On Diff #107988)

Oh sorry I assumed you meant the isMergeableElement should be checked first.

Remove logging.

ruiu added inline comments.Jul 25 2017, 1:02 PM
llvm/lib/Support/WindowsManifestMerger.cpp
39 ↗(On Diff #108136)

has -> get

51 ↗(On Diff #108136)

Since this function returns not a boolean value but a value itself, get is a better prefix than has.

77–79 ↗(On Diff #108136)

The memory you allocate using strdup needs to be freed somewhere using free(). Does your patch do that?

106 ↗(On Diff #108136)

Remove Twine from the second expression

113 ↗(On Diff #108136)

I don't think you need an explicit instantiation of Twine for the second expression.

114 ↗(On Diff #108136)

Add {}.

Usual convention is, if one statement is a block (e.g. enclosed in {})) all statements in the same if ~ else if ~ else ~ should be enclosed with {} as well. E.g. this is fine

if (foo)
  bar;
else
  baz;

and this is also fine

if (foo) {
  bar
} else if (bar) {
  baz
}

but this isn't okay.

if (foo) {
  bar
} else
  baz
143–145 ↗(On Diff #108136)

Fix style

148–149 ↗(On Diff #108136)

I think we have too many occurrences of this pattern. Can you add a function that compares two xmlStrings?

Readability improvements.

ecbeckmann marked 6 inline comments as done.

Readability improvements.

llvm/lib/Support/WindowsManifestMerger.cpp
77–79 ↗(On Diff #108136)

Yes, these strings become part of the node tree structure of the xml document. When xmlFreeDoc() is called by the class destructor these strings should also be freed.

148–149 ↗(On Diff #108136)

All the function would do is abstract away the reinterpret_cast. I think with the macro I added for cast it isn't that bad.

Strip all comment and text nodes, not just in elements being merged.

ruiu added inline comments.Jul 25 2017, 2:34 PM
llvm/lib/Support/WindowsManifestMerger.cpp
148–149 ↗(On Diff #108136)

What I was suggesting is adding something like this

static bool streq(const unsigned char *A, const unsigned char B) {
  return strcmp((char *)A, (char *)B) == 0;
}
19–20 ↗(On Diff #108155)

In C++ it is not a very good practice to use a C macro where you can avoid it. I'd probably keep the original reinterpret_casts, but if you like this, I think I'm fine with it.

add string compare helper function.

llvm/lib/Support/WindowsManifestMerger.cpp
19–20 ↗(On Diff #108155)

I really prefer this, having the entire reinterpret_cast written out every time clutters the code IMO

ruiu accepted this revision.Jul 25 2017, 3:46 PM

LGTM

llvm/test/tools/llvm-mt/simple_merge.test
8–39 ↗(On Diff #108170)

Please indent the expected result for the sake of readability.

This revision is now accepted and ready to land.Jul 25 2017, 3:46 PM
ecbeckmann marked an inline comment as done.

Indent in test.

This revision was automatically updated to reflect the committed changes.