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.

Diff Detail

Repository
rL LLVM

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
46 ↗(On Diff #106670)

remove

llvm/test/CMakeLists.txt
141 ↗(On Diff #106670)

remove

llvm/tools/llvm-mt/llvm-mt.cpp
147 ↗(On Diff #106670)

remove

153 ↗(On Diff #106670)

remove

156 ↗(On Diff #106670)

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 ↗(On Diff #106733)

Does it make sense to not do this on Windows?

llvm/include/llvm/Support/WindowsManifestMerger.h
32 ↗(On Diff #106733)

You can use #ifdef

51 ↗(On Diff #106733)

const Twine &Msg?

llvm/lib/Support/WindowsManifestMerger.cpp
28 ↗(On Diff #106733)

Use #ifdef throughout this patch.

41 ↗(On Diff #106733)

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.

41 ↗(On Diff #106733)

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
61 ↗(On Diff #106733)

Is this intentional?

llvm/tools/llvm-mt/llvm-mt.cpp
68 ↗(On Diff #106733)

Remove a full stop.

77–79 ↗(On Diff #106733)

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

if (EC)
  reportError
83–87 ↗(On Diff #106733)

Ditto

110 ↗(On Diff #106733)

Remove a full stop and \n.

Error messages should start with lowercase letter.

122 ↗(On Diff #106733)

Ditto

129 ↗(On Diff #106733)

Ditto

133 ↗(On Diff #106733)

Ditto

149 ↗(On Diff #106733)

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 ↗(On Diff #106733)

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
41 ↗(On Diff #106733)

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
61 ↗(On Diff #106733)

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

llvm/tools/llvm-mt/llvm-mt.cpp
68 ↗(On Diff #106733)

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
28 ↗(On Diff #107188)

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

60–61 ↗(On Diff #107188)

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
42–45 ↗(On Diff #107188)

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
}
68 ↗(On Diff #107188)

Remove else after return.

llvm/tools/llvm-mt/llvm-mt.cpp
78 ↗(On Diff #107188)

Indentation.

83 ↗(On Diff #107188)

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
76 ↗(On Diff #107351)

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
51–54 ↗(On Diff #107351)

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 ↗(On Diff #107351)

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
43 ↗(On Diff #107362)

This is dead now.

llvm/tools/llvm-mt/llvm-mt.cpp
146 ↗(On Diff #107351)

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 ↗(On Diff #107351)

check most recent patch.

ruiu added inline comments.Jul 19 2017, 2:44 PM
llvm/tools/llvm-mt/llvm-mt.cpp
147 ↗(On Diff #107383)

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