Skip to content

Commit

Permalink
latest from coda-oss and nitro
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Aug 29, 2022
1 parent 1d196c7 commit b524480
Show file tree
Hide file tree
Showing 14 changed files with 298 additions and 140 deletions.
58 changes: 57 additions & 1 deletion externals/coda-oss/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
from makewheel import makewheel
from package import package


try:
import hashlib
hashlib.md5()
except ValueError:
Logs.error('MD5 error - you are likely trying to use an old python on a new machine to run waf. '
'If you run into a fatal FIPS error try finding a newer version of python.')


COMMON_EXCLUDES = '.bzr .bzrignore .git .gitignore .svn CVS .cvsignore .arch-ids {arch} SCCS BitKeeper .hg _MTN _darcs Makefile Makefile.in config.log'.split()
COMMON_EXCLUDES_EXT ='~ .rej .orig .pyc .pyo .bak .tar.bz2 tar.gz .zip .swp'.split()

Expand Down Expand Up @@ -790,6 +799,9 @@ def options(opt):
help='Specify a prebuilt modules config file (created from dumpconfig)')
opt.add_option('--disable-swig-silent-leak', action='store_false', dest='swig_silent_leak',
default=True, help='Allow swig to print memory leaks it detects')
opt.add_option('--junit-report', action='store', default=None,
help='Generates a junit formmated report file for unit test'
'results. NOOP if junit_xml cannot be imported')


def ensureCpp11Support(self):
Expand Down Expand Up @@ -1750,6 +1762,41 @@ def addSourceTargets(bld, env, path, target):

target.targets_to_add += wscriptTargets

def junitUnitTestResults(bld):
'''
Summary calback function to generate JUnit formatted XML
'''
import junit_xml

# we also want a logged summary still
waf_unit_test.summary(bld)

# now generate a report
lst = getattr(bld,'utest_results',[])
test_cases = []
for name, retcode, stdout, stderr in lst:
so = stdout.decode()
se = stderr.decode()
tc = junit_xml.TestCase(name=name,
status=retcode,
stdout=so,
stderr=se)
if retcode:
messages = []
lines = se.split('\n')
for line in lines:
if 'FAILED' in line:
messages.append(line)
if len(messages) == 0:
messages = ['Unknown error occured that caused non-zero return code']

tc.add_failure_info('\n'.join(messages))
test_cases.append(tc)
ts = junit_xml.TestSuite('unit tests', test_cases)
with open(bld.options.junit_report, 'w') as fh:
fh.write(junit_xml.TestSuite.to_xml_string([ts]))


def enableWafUnitTests(bld, set_exit_code=True):
"""
If called, run all C++ unit tests after building
Expand All @@ -1758,7 +1805,16 @@ def enableWafUnitTests(bld, set_exit_code=True):
# TODO: This does not work for Python files.
# The "nice" way to handle this is possibly not
# supported in this version of Waf.
bld.add_post_fun(waf_unit_test.summary)
if bld.options.junit_report is not None:
try:
import junit_xml
bld.add_post_fun(junitUnitTestResults)
except ImportError:
Logs.pprint('RED', 'Cannot generate requested junit report because we can\'t import junit-xml')
bld.add_post_fun(waf_unit_test.summary)
else:
bld.add_post_fun(waf_unit_test.summary)

if set_exit_code:
bld.add_post_fun(waf_unit_test.set_exit_code)

Expand Down
12 changes: 8 additions & 4 deletions externals/coda-oss/modules/c++/str/include/str/EncodedString.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class CODA_OSS_API EncodedString final

// No "public" operator=() for these; this class is mostly for storage and/or conversion,
// not extensive manipulation. Create a new instance and assign/move that.
void assign(coda_oss::u8string::const_pointer);
void assign(str::W1252string::const_pointer);

public:
EncodedString();
Expand All @@ -65,12 +63,18 @@ class CODA_OSS_API EncodedString final
EncodedString(EncodedString&&);
EncodedString& operator=(EncodedString&&);

EncodedString(coda_oss::u8string::const_pointer, coda_oss::u8string::size_type);
explicit EncodedString(coda_oss::u8string::const_pointer);
explicit EncodedString(const coda_oss::u8string& s);
explicit EncodedString(const str::W1252string&);

EncodedString(str::W1252string::const_pointer, str::W1252string::size_type);
explicit EncodedString(str::W1252string::const_pointer);
explicit EncodedString(const std::string&); // Assume platform native encoding: UTF-8 on Linux, Windows-1252 on Windows
explicit EncodedString(const str::W1252string&);

EncodedString(std::string::const_pointer, std::string::size_type);
explicit EncodedString(std::string::const_pointer); // Assume platform native encoding: UTF-8 on Linux, Windows-1252 on Windows
explicit EncodedString(const std::string&); // Assume platform native encoding: UTF-8 on Linux, Windows-1252 on Windows

explicit EncodedString(const std::u16string&); // converted to UTF-8 for storage
explicit EncodedString(const std::u32string&); // converted to UTF-8 for storage
explicit EncodedString(const std::wstring&); // Assume platform native encoding: UTF-32 on Linux, UTF-16 on Windows
Expand Down
16 changes: 12 additions & 4 deletions externals/coda-oss/modules/c++/str/include/str/EncodedStringView.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ class CODA_OSS_API EncodedStringView final
// Since we only support two encodings--UTF-8 (native on Linux) and Windows-1252
// (native on Windows)--both of which are 8-bits, a simple "bool" flag will do.
coda_oss::span<const char> mString;
#if _WIN32
explicit EncodedStringView(coda_oss::span<const coda_oss::u8string::value_type>);
explicit EncodedStringView(coda_oss::span<const str::W1252string::value_type>);

#if _WIN32
static constexpr bool mNativeIsUtf8 = false; // Windows-1252
#else
static constexpr bool mNativeIsUtf8 = true; // !_WIN32, assume Linux
#endif
bool mIsUtf8 = mNativeIsUtf8;

// Want to create an EncodedString from EncodedStringView. The public interface
// doesn't expose "mIsUtf8" so there's (intentinally) no way for clients to know the encoding.
friend EncodedString;
Expand All @@ -76,10 +79,15 @@ class CODA_OSS_API EncodedStringView final
// Need the const char* overloads to avoid creating temporary std::basic_string<> instances.
// Routnes always return a copy, never a reference, so there's no additional overhead
// with storing a raw pointer rather than a pointer to std::basic_string<>.
EncodedStringView(coda_oss::u8string::const_pointer, coda_oss::u8string::size_type);
explicit EncodedStringView(coda_oss::u8string::const_pointer);
explicit EncodedStringView(const coda_oss::u8string&);

EncodedStringView(str::W1252string::const_pointer, str::W1252string::size_type);
explicit EncodedStringView(str::W1252string::const_pointer);
explicit EncodedStringView(const str::W1252string&);

EncodedStringView(std::string::const_pointer, std::string::size_type);
explicit EncodedStringView(std::string::const_pointer); // Assume platform native encoding: UTF-8 on Linux, Windows-1252 on Windows
explicit EncodedStringView(const std::string&); // Assume platform native encoding: UTF-8 on Linux, Windows-1252 on Windows

Expand Down Expand Up @@ -126,15 +134,15 @@ class CODA_OSS_API EncodedStringView final
// Input is encoded as specified on all platforms.
static EncodedStringView fromUtf8(const std::string& utf8)
{
return EncodedStringView(str::c_str<coda_oss::u8string>(utf8));
return EncodedStringView(str::c_str<coda_oss::u8string>(utf8), utf8.length());
}
static EncodedStringView fromUtf8(std::string::const_pointer pUtf8)
{
return EncodedStringView(str::cast<coda_oss::u8string::const_pointer>(pUtf8));
}
static EncodedStringView fromWindows1252(const std::string& w1252)
{
return EncodedStringView(str::c_str<str::W1252string>(w1252));
return EncodedStringView(str::c_str<str::W1252string>(w1252), w1252.length());
}
static EncodedStringView fromWindows1252(std::string::const_pointer pW1252)
{
Expand Down
55 changes: 32 additions & 23 deletions externals/coda-oss/modules/c++/str/source/EncodedString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,57 @@

#include <type_traits>

void str::EncodedString::assign(coda_oss::u8string::const_pointer s)
template<typename CharT>
inline void assign_(const CharT* p, size_t c, std::string& s_, str::EncodedStringView& v_)
{
using char_t = std::remove_pointer<decltype(s)>::type; // avoid copy-paste error
using string_t = std::basic_string<std::remove_const<char_t>::type>;
s_ = cast<std::string::const_pointer>(s); // copy
v_ = EncodedStringView(str::c_str<string_t>(s_));
using string_t = std::basic_string<CharT>;
s_.assign(str::cast<std::string::const_pointer>(p), c); // copy
v_ = str::EncodedStringView(str::c_str<string_t>(s_), c);
}

void str::EncodedString::assign(str::W1252string::const_pointer s)
template<typename CharT>
inline void assign_(const CharT* p, std::string& s_, str::EncodedStringView& v_)
{
using char_t = std::remove_pointer<decltype(s)>::type; // avoid copy-paste error
using string_t = std::basic_string<std::remove_const<char_t>::type>;
s_ = cast<std::string::const_pointer>(s); // copy
v_ = EncodedStringView(str::c_str<string_t>(s_)); // avoid copy-paste error
using string_t = std::basic_string<CharT>;
s_ = str::cast<std::string::const_pointer>(p); // copy
v_ = str::EncodedStringView(str::c_str<string_t>(s_), s_.length());
}

static str::EncodedStringView make_EncodedStringView(const std::string& s, bool isUtf8)
{
if (isUtf8)
{
return str::EncodedStringView(str::c_str<coda_oss::u8string>(s));
return str::EncodedStringView(str::c_str<coda_oss::u8string>(s), s.length());
}

// not UTF-8, assume Windows-1252
return str::EncodedStringView(str::c_str<str::W1252string>(s));
return str::EncodedStringView(str::c_str<str::W1252string>(s), s.length());
}

str::EncodedString::EncodedString(std::string::const_pointer s) : s_(s) /*copy*/, v_(s_) { }
str::EncodedString::EncodedString(std::string::const_pointer p, std::string::size_type c) : s_(p, c) /*copy*/, v_(s_) { }
str::EncodedString::EncodedString(std::string::const_pointer p) : s_(p) /*copy*/, v_(s_) { }
str::EncodedString::EncodedString(const std::string& s) : s_(s) /*copy*/, v_(s_) { }

str::EncodedString::EncodedString() : EncodedString(""){ }

str::EncodedString::EncodedString(coda_oss::u8string::const_pointer s)
str::EncodedString::EncodedString(coda_oss::u8string::const_pointer p, coda_oss::u8string::size_type c)
{
assign_(p, c, s_, v_);
}
str::EncodedString::EncodedString(coda_oss::u8string::const_pointer p)
{
assign(s);
assign_(p, s_, v_);
}
str::EncodedString::EncodedString(const coda_oss::u8string& s) : EncodedString(s.c_str()) { }
str::EncodedString::EncodedString(const coda_oss::u8string& s) : EncodedString(s.c_str(), s.size()) { }

str::EncodedString::EncodedString(str::W1252string::const_pointer s)
str::EncodedString::EncodedString(str::W1252string::const_pointer p, str::W1252string::size_type c)
{
assign_(p, c, s_, v_);
}
str::EncodedString::EncodedString(str::W1252string::const_pointer p)
{
assign(s);
assign_(p, s_, v_);
}
str::EncodedString::EncodedString(const str::W1252string& s) : EncodedString(s.c_str()) { }
str::EncodedString::EncodedString(const str::W1252string& s) : EncodedString(s.c_str(), s.size()) { }

str::EncodedString::EncodedString(const std::u16string& s) : EncodedString(to_u8string(s)) { }
str::EncodedString::EncodedString(const std::u32string& s) : EncodedString(to_u8string(s)) { }
Expand All @@ -91,13 +100,13 @@ str::EncodedString& str::EncodedString::operator=(const EncodedStringView& v)
{
if (v.mIsUtf8)
{
assign(v.c_u8str());
assign_(v.c_u8str(), v.size(), s_, v_);
}
else
{
// not UTF-8, assume Windows-1252
auto p = cast<W1252string::const_pointer>(v.mString.data());
assign(p);
auto p = cast<W1252string::const_pointer>(v.c_str());
assign_(p, v.size(), s_, v_);
}

return *this;
Expand Down
35 changes: 26 additions & 9 deletions externals/coda-oss/modules/c++/str/source/EncodedStringView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,41 @@ static std::string to_native(str::W1252string::const_pointer p, size_t sz)
}

template <typename CharT>
inline coda_oss::span<const char> make_span(const CharT* s)
inline coda_oss::span<const CharT> make_span(const CharT* s, size_t c)
{
return coda_oss::span<const CharT>(s, c);
}
template <typename CharT>
inline coda_oss::span<const CharT> make_span(const CharT* s)
{
auto s_ = str::cast<const char*>(s);
return coda_oss::span<const char>(s_, strlen(s_));
return make_span(s, strlen(s_));
}

template<typename CharT>
inline coda_oss::span<const char> make_span(const std::basic_string<CharT>& s)
inline coda_oss::span<const CharT> make_span(const std::basic_string<CharT>& s)
{
return coda_oss::span<const char>(str::c_str<std::string>(s), s.size());
return make_span(s.c_str(), s.size());
}
template <typename CharT>
inline coda_oss::span<const char> make_span(coda_oss::span<const CharT> s)
{
auto s_ = str::cast<const char*>(s.data());
return coda_oss::span<const char>(s_, s.size());
}

str::EncodedStringView::EncodedStringView(std::string::const_pointer p, std::string::size_type c) : mString(make_span(p, c)) { }
str::EncodedStringView::EncodedStringView(std::string::const_pointer p) : mString(make_span(p)) { }
str::EncodedStringView::EncodedStringView(coda_oss::u8string::const_pointer p) : mString(make_span(p)), mIsUtf8(true) { }
str::EncodedStringView::EncodedStringView(str::W1252string::const_pointer p) : mString(make_span(p)), mIsUtf8(false) { }
str::EncodedStringView::EncodedStringView(const std::string& s) : mString(make_span(s)){ }
str::EncodedStringView::EncodedStringView(const coda_oss::u8string& s) : mString(make_span(s)), mIsUtf8(true) { }
str::EncodedStringView::EncodedStringView(const str::W1252string& s) : mString(make_span(s)), mIsUtf8(false) { }

str::EncodedStringView::EncodedStringView(coda_oss::span<const coda_oss::u8string::value_type> s) : mString(make_span(s)), mIsUtf8(true) {}
str::EncodedStringView::EncodedStringView(coda_oss::u8string::const_pointer p, coda_oss::u8string::size_type c) : EncodedStringView(make_span(p, c)) { }
str::EncodedStringView::EncodedStringView(coda_oss::u8string::const_pointer p) : EncodedStringView(make_span(p)) { }
str::EncodedStringView::EncodedStringView(const coda_oss::u8string& s) : EncodedStringView(make_span(s)) { }

str::EncodedStringView::EncodedStringView(coda_oss::span<const str::W1252string::value_type> s) : mString(make_span(s)), mIsUtf8(false) {}
str::EncodedStringView::EncodedStringView(str::W1252string::const_pointer p, str::W1252string::size_type c) : EncodedStringView(make_span(p, c)) { }
str::EncodedStringView::EncodedStringView(str::W1252string::const_pointer p) : EncodedStringView(make_span(p)) { }
str::EncodedStringView::EncodedStringView(const str::W1252string& s) : EncodedStringView(make_span(s)) { }

std::string str::EncodedStringView::native() const
{
Expand Down
Loading

0 comments on commit b524480

Please sign in to comment.