This is an archive of the discontinued LLVM Phabricator instance.

Implement parsing and writing of a single xml manifest file.
ClosedPublic

Authored by ecbeckmann on Jul 14 2017, 11:09 AM.

Event Timeline

ecbeckmann created this revision.Jul 14 2017, 11:09 AM
ecbeckmann added inline comments.Jul 14 2017, 2:20 PM
llvm/lib/Support/WindowsManifestMerger.cpp
47

remove

llvm/test/CMakeLists.txt
141

remove

llvm/tools/llvm-mt/llvm-mt.cpp
147

remove

153

remove

156

remove

ecbeckmann marked 5 inline comments as done.

Removed logging.

Tests will not be run without libxml2.

Also ensure that the libary actually exists...

a couple test fixes.

Added newline

ruiu added inline comments.Jul 17 2017, 7:29 PM
llvm/cmake/config-ix.cmake
604

Does it make sense to not do this on Windows?

llvm/include/llvm/Support/WindowsManifestMerger.h
33

You can use #ifdef

52

const Twine &Msg?

llvm/lib/Support/WindowsManifestMerger.cpp
29

Use #ifdef throughout this patch.

42

This function returns something non-empty even if you dont' have libxml2, but I don't think that makes sense. Just like above function which just returns Error::success(), I think it is better to return {} from this function if libxml is not available.

42

Looks like it is more straightforward to return an std::vector<uint8_t> from this function instead of a MemoryBuffer. MemoryBuffer is usually used to represent something you've read from files. In this case, this function just construct an in-memory data structure which can easily be represented as std::vector.

llvm/test/CMakeLists.txt
60–61

Is this intentional?

llvm/tools/llvm-mt/llvm-mt.cpp
68

Remove a full stop.

77–79

nit: since the real function body is just one line, this is simpler

if (EC)
  reportError
83–87

Ditto

110

Remove a full stop and \n.

Error messages should start with lowercase letter.

122

Ditto

129

Ditto

133

Ditto

149

Ditto

ecbeckmann marked 6 inline comments as done.

Some syntax and return value changes.

ruiu edited edge metadata.Jul 18 2017, 3:08 PM

Is this ready for another round of review?

Rebase

llvm/cmake/config-ix.cmake
604

Yes, apparently the version of libxml2 on Windows uses different headers than what we expect and linking it in would cause a problem. Besides, if we are on windows we can just continue to shell out to the original mt.exe tool.

llvm/lib/Support/WindowsManifestMerger.cpp
42

In this case I feel it is more convenient to use MemoryBuffer because it directly takes ownership of the underlying data allocated by xmlDocDumpMemory(). For using a vector we would need an additional copy, and then explicitly delete the allocated memory. Though perhaps this is okay for clarity?

llvm/test/CMakeLists.txt
60–61

Yes down below I only add the test depends if libxml2 is found.

llvm/tools/llvm-mt/llvm-mt.cpp
68

When I rebase the previous patch these mistakes will go away.

ruiu added inline comments.Jul 18 2017, 3:25 PM
llvm/include/llvm/Support/WindowsManifestMerger.h
29

This include guard is not correct. #endif should be at end of the file.

61–62

Do you need this? Since you didn't define any other ctors, this is defined as a default ctor. Isn't it enough?

llvm/lib/Support/WindowsManifestMerger.cpp
43–46

I think you'll get a compiler warning if you compile it in an environment that doesn't have libxml, as BufferSize and XmlBuff will be unused.

A better way of doing it is to completely separate two conditions:

std::unique_ptr<MemoryBuffer> WindowsManifestMerger::getMergedManifest() {
#ifdef LIBXML2_ENABLED
  ...
  return OutputBuffer;
#else
  return nullptr;
#endif
}
69

Remove else after return.

llvm/tools/llvm-mt/llvm-mt.cpp
78

Indentation.

83

Indentation.

ecbeckmann marked 6 inline comments as done.

update

More elegant linking of the xml2 library in the build system.

ruiu added inline comments.Jul 19 2017, 12:01 PM
llvm/include/llvm/Support/WindowsManifestMerger.h
75

Fix this. (It doesn't say that you need a blank line at end of a file, but it says that your last line doesn't end with '\n'.)

llvm/lib/Support/WindowsManifestMerger.cpp
52–55

You can eliminate OutputBuffer by doing this:

if (BufferSize == 0)
  return nullptr;  
return MemoryBuffer::getMemBuffer(
      StringRef(reinterpret_cast<const char *>(XmlBuff), (size_t)BufferSize));
llvm/tools/llvm-mt/llvm-mt.cpp
146

Isn't this an error? Looks like this program exits with 0 in this case.

ecbeckmann marked 3 inline comments as done.

some reformats

ruiu added inline comments.Jul 19 2017, 1:56 PM
llvm/lib/Support/WindowsManifestMerger.cpp
44

This is dead now.

llvm/tools/llvm-mt/llvm-mt.cpp
146

How about this?

ecbeckmann marked an inline comment as done.

Remove vestigal variable.

ecbeckmann added inline comments.Jul 19 2017, 2:35 PM
llvm/tools/llvm-mt/llvm-mt.cpp
146

check most recent patch.

ruiu added inline comments.Jul 19 2017, 2:44 PM
llvm/tools/llvm-mt/llvm-mt.cpp
147

Since reportError is a noreturn function, remove else.

Remove else block after error.

ecbeckmann marked an inline comment as done.Jul 19 2017, 3:04 PM
ruiu accepted this revision.Jul 19 2017, 3:14 PM

LGTM

Please make sure that this patch works with/without libxml2 before committing.

This revision is now accepted and ready to land.Jul 19 2017, 3:14 PM

Final changes to the build system.

This revision was automatically updated to reflect the committed changes.
orivej added a subscriber: orivej.Sep 14 2017, 12:08 PM

WindowsManifestMerger.h should not include llvm/Config/config.h: https://bugs.llvm.org/show_bug.cgi?id=34608