Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • applications/calamares
  • Chrysostomus/calamares
  • codesardine/calamares
  • boredland/calamares
4 results
Show changes
Showing
with 8633 additions and 351 deletions
/*
pybind11/pytypes.h: Convenience wrapper classes for basic Python types
Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.
*/
#pragma once
#include "detail/common.h"
#include "buffer_info.h"
#include <assert.h>
#include <cstddef>
#include <exception>
#include <frameobject.h>
#include <iterator>
#include <memory>
#include <string>
#include <type_traits>
#include <typeinfo>
#include <utility>
#if defined(PYBIND11_HAS_OPTIONAL)
# include <optional>
#endif
#ifdef PYBIND11_HAS_STRING_VIEW
# include <string_view>
#endif
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_WARNING_DISABLE_MSVC(4127)
/* A few forward declarations */
class handle;
class object;
class str;
class iterator;
class type;
struct arg;
struct arg_v;
PYBIND11_NAMESPACE_BEGIN(detail)
class args_proxy;
bool isinstance_generic(handle obj, const std::type_info &tp);
// Accessor forward declarations
template <typename Policy>
class accessor;
namespace accessor_policies {
struct obj_attr;
struct str_attr;
struct generic_item;
struct sequence_item;
struct list_item;
struct tuple_item;
} // namespace accessor_policies
using obj_attr_accessor = accessor<accessor_policies::obj_attr>;
using str_attr_accessor = accessor<accessor_policies::str_attr>;
using item_accessor = accessor<accessor_policies::generic_item>;
using sequence_accessor = accessor<accessor_policies::sequence_item>;
using list_accessor = accessor<accessor_policies::list_item>;
using tuple_accessor = accessor<accessor_policies::tuple_item>;
/// Tag and check to identify a class which implements the Python object API
class pyobject_tag {};
template <typename T>
using is_pyobject = std::is_base_of<pyobject_tag, remove_reference_t<T>>;
/** \rst
A mixin class which adds common functions to `handle`, `object` and various accessors.
The only requirement for `Derived` is to implement ``PyObject *Derived::ptr() const``.
\endrst */
template <typename Derived>
class object_api : public pyobject_tag {
const Derived &derived() const { return static_cast<const Derived &>(*this); }
public:
/** \rst
Return an iterator equivalent to calling ``iter()`` in Python. The object
must be a collection which supports the iteration protocol.
\endrst */
iterator begin() const;
/// Return a sentinel which ends iteration.
iterator end() const;
/** \rst
Return an internal functor to invoke the object's sequence protocol. Casting
the returned ``detail::item_accessor`` instance to a `handle` or `object`
subclass causes a corresponding call to ``__getitem__``. Assigning a `handle`
or `object` subclass causes a call to ``__setitem__``.
\endrst */
item_accessor operator[](handle key) const;
/// See above (the only difference is that the key's reference is stolen)
item_accessor operator[](object &&key) const;
/// See above (the only difference is that the key is provided as a string literal)
item_accessor operator[](const char *key) const;
/** \rst
Return an internal functor to access the object's attributes. Casting the
returned ``detail::obj_attr_accessor`` instance to a `handle` or `object`
subclass causes a corresponding call to ``getattr``. Assigning a `handle`
or `object` subclass causes a call to ``setattr``.
\endrst */
obj_attr_accessor attr(handle key) const;
/// See above (the only difference is that the key's reference is stolen)
obj_attr_accessor attr(object &&key) const;
/// See above (the only difference is that the key is provided as a string literal)
str_attr_accessor attr(const char *key) const;
/** \rst
Matches * unpacking in Python, e.g. to unpack arguments out of a ``tuple``
or ``list`` for a function call. Applying another * to the result yields
** unpacking, e.g. to unpack a dict as function keyword arguments.
See :ref:`calling_python_functions`.
\endrst */
args_proxy operator*() const;
/// Check if the given item is contained within this object, i.e. ``item in obj``.
template <typename T>
bool contains(T &&item) const;
/** \rst
Assuming the Python object is a function or implements the ``__call__``
protocol, ``operator()`` invokes the underlying function, passing an
arbitrary set of parameters. The result is returned as a `object` and
may need to be converted back into a Python object using `handle::cast()`.
When some of the arguments cannot be converted to Python objects, the
function will throw a `cast_error` exception. When the Python function
call fails, a `error_already_set` exception is thrown.
\endrst */
template <return_value_policy policy = return_value_policy::automatic_reference,
typename... Args>
object operator()(Args &&...args) const;
template <return_value_policy policy = return_value_policy::automatic_reference,
typename... Args>
PYBIND11_DEPRECATED("call(...) was deprecated in favor of operator()(...)")
object call(Args &&...args) const;
/// Equivalent to ``obj is other`` in Python.
bool is(object_api const &other) const { return derived().ptr() == other.derived().ptr(); }
/// Equivalent to ``obj is None`` in Python.
bool is_none() const { return derived().ptr() == Py_None; }
/// Equivalent to obj == other in Python
bool equal(object_api const &other) const { return rich_compare(other, Py_EQ); }
bool not_equal(object_api const &other) const { return rich_compare(other, Py_NE); }
bool operator<(object_api const &other) const { return rich_compare(other, Py_LT); }
bool operator<=(object_api const &other) const { return rich_compare(other, Py_LE); }
bool operator>(object_api const &other) const { return rich_compare(other, Py_GT); }
bool operator>=(object_api const &other) const { return rich_compare(other, Py_GE); }
object operator-() const;
object operator~() const;
object operator+(object_api const &other) const;
object operator+=(object_api const &other);
object operator-(object_api const &other) const;
object operator-=(object_api const &other);
object operator*(object_api const &other) const;
object operator*=(object_api const &other);
object operator/(object_api const &other) const;
object operator/=(object_api const &other);
object operator|(object_api const &other) const;
object operator|=(object_api const &other);
object operator&(object_api const &other) const;
object operator&=(object_api const &other);
object operator^(object_api const &other) const;
object operator^=(object_api const &other);
object operator<<(object_api const &other) const;
object operator<<=(object_api const &other);
object operator>>(object_api const &other) const;
object operator>>=(object_api const &other);
PYBIND11_DEPRECATED("Use py::str(obj) instead")
pybind11::str str() const;
/// Get or set the object's docstring, i.e. ``obj.__doc__``.
str_attr_accessor doc() const;
/// Return the object's current reference count
int ref_count() const { return static_cast<int>(Py_REFCNT(derived().ptr())); }
// TODO PYBIND11_DEPRECATED(
// "Call py::type::handle_of(h) or py::type::of(h) instead of h.get_type()")
handle get_type() const;
private:
bool rich_compare(object_api const &other, int value) const;
};
template <typename T>
using is_pyobj_ptr_or_nullptr_t = detail::any_of<std::is_same<T, PyObject *>,
std::is_same<T, PyObject *const>,
std::is_same<T, std::nullptr_t>>;
PYBIND11_NAMESPACE_END(detail)
#if !defined(PYBIND11_HANDLE_REF_DEBUG) && !defined(NDEBUG)
# define PYBIND11_HANDLE_REF_DEBUG
#endif
/** \rst
Holds a reference to a Python object (no reference counting)
The `handle` class is a thin wrapper around an arbitrary Python object (i.e. a
``PyObject *`` in Python's C API). It does not perform any automatic reference
counting and merely provides a basic C++ interface to various Python API functions.
.. seealso::
The `object` class inherits from `handle` and adds automatic reference
counting features.
\endrst */
class handle : public detail::object_api<handle> {
public:
/// The default constructor creates a handle with a ``nullptr``-valued pointer
handle() = default;
/// Enable implicit conversion from ``PyObject *`` and ``nullptr``.
/// Not using ``handle(PyObject *ptr)`` to avoid implicit conversion from ``0``.
template <typename T,
detail::enable_if_t<detail::is_pyobj_ptr_or_nullptr_t<T>::value, int> = 0>
// NOLINTNEXTLINE(google-explicit-constructor)
handle(T ptr) : m_ptr(ptr) {}
/// Enable implicit conversion through ``T::operator PyObject *()``.
template <
typename T,
detail::enable_if_t<detail::all_of<detail::none_of<std::is_base_of<handle, T>,
detail::is_pyobj_ptr_or_nullptr_t<T>>,
std::is_convertible<T, PyObject *>>::value,
int>
= 0>
// NOLINTNEXTLINE(google-explicit-constructor)
handle(T &obj) : m_ptr(obj) {}
/// Return the underlying ``PyObject *`` pointer
PyObject *ptr() const { return m_ptr; }
PyObject *&ptr() { return m_ptr; }
/** \rst
Manually increase the reference count of the Python object. Usually, it is
preferable to use the `object` class which derives from `handle` and calls
this function automatically. Returns a reference to itself.
\endrst */
const handle &inc_ref() const & {
#ifdef PYBIND11_HANDLE_REF_DEBUG
inc_ref_counter(1);
#endif
#ifdef PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
if (m_ptr != nullptr && !PyGILState_Check()) {
throw_gilstate_error("pybind11::handle::inc_ref()");
}
#endif
Py_XINCREF(m_ptr);
return *this;
}
/** \rst
Manually decrease the reference count of the Python object. Usually, it is
preferable to use the `object` class which derives from `handle` and calls
this function automatically. Returns a reference to itself.
\endrst */
const handle &dec_ref() const & {
#ifdef PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
if (m_ptr != nullptr && !PyGILState_Check()) {
throw_gilstate_error("pybind11::handle::dec_ref()");
}
#endif
Py_XDECREF(m_ptr);
return *this;
}
/** \rst
Attempt to cast the Python object into the given C++ type. A `cast_error`
will be throw upon failure.
\endrst */
template <typename T>
T cast() const;
/// Return ``true`` when the `handle` wraps a valid Python object
explicit operator bool() const { return m_ptr != nullptr; }
/** \rst
Deprecated: Check that the underlying pointers are the same.
Equivalent to ``obj1 is obj2`` in Python.
\endrst */
PYBIND11_DEPRECATED("Use obj1.is(obj2) instead")
bool operator==(const handle &h) const { return m_ptr == h.m_ptr; }
PYBIND11_DEPRECATED("Use !obj1.is(obj2) instead")
bool operator!=(const handle &h) const { return m_ptr != h.m_ptr; }
PYBIND11_DEPRECATED("Use handle::operator bool() instead")
bool check() const { return m_ptr != nullptr; }
protected:
PyObject *m_ptr = nullptr;
private:
#ifdef PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
void throw_gilstate_error(const std::string &function_name) const {
fprintf(
stderr,
"%s is being called while the GIL is either not held or invalid. Please see "
"https://pybind11.readthedocs.io/en/stable/advanced/"
"misc.html#common-sources-of-global-interpreter-lock-errors for debugging advice.\n"
"If you are convinced there is no bug in your code, you can #define "
"PYBIND11_NO_ASSERT_GIL_HELD_INCREF_DECREF"
"to disable this check. In that case you have to ensure this #define is consistently "
"used for all translation units linked into a given pybind11 extension, otherwise "
"there will be ODR violations.",
function_name.c_str());
fflush(stderr);
if (Py_TYPE(m_ptr)->tp_name != nullptr) {
fprintf(stderr,
"The failing %s call was triggered on a %s object.\n",
function_name.c_str(),
Py_TYPE(m_ptr)->tp_name);
fflush(stderr);
}
throw std::runtime_error(function_name + " PyGILState_Check() failure.");
}
#endif
#ifdef PYBIND11_HANDLE_REF_DEBUG
static std::size_t inc_ref_counter(std::size_t add) {
thread_local std::size_t counter = 0;
counter += add;
return counter;
}
public:
static std::size_t inc_ref_counter() { return inc_ref_counter(0); }
#endif
};
/** \rst
Holds a reference to a Python object (with reference counting)
Like `handle`, the `object` class is a thin wrapper around an arbitrary Python
object (i.e. a ``PyObject *`` in Python's C API). In contrast to `handle`, it
optionally increases the object's reference count upon construction, and it
*always* decreases the reference count when the `object` instance goes out of
scope and is destructed. When using `object` instances consistently, it is much
easier to get reference counting right at the first attempt.
\endrst */
class object : public handle {
public:
object() = default;
PYBIND11_DEPRECATED("Use reinterpret_borrow<object>() or reinterpret_steal<object>()")
object(handle h, bool is_borrowed) : handle(h) {
if (is_borrowed) {
inc_ref();
}
}
/// Copy constructor; always increases the reference count
object(const object &o) : handle(o) { inc_ref(); }
/// Move constructor; steals the object from ``other`` and preserves its reference count
object(object &&other) noexcept : handle(other) { other.m_ptr = nullptr; }
/// Destructor; automatically calls `handle::dec_ref()`
~object() { dec_ref(); }
/** \rst
Resets the internal pointer to ``nullptr`` without decreasing the
object's reference count. The function returns a raw handle to the original
Python object.
\endrst */
handle release() {
PyObject *tmp = m_ptr;
m_ptr = nullptr;
return handle(tmp);
}
object &operator=(const object &other) {
// Skip inc_ref and dec_ref if both objects are the same
if (!this->is(other)) {
other.inc_ref();
// Use temporary variable to ensure `*this` remains valid while
// `Py_XDECREF` executes, in case `*this` is accessible from Python.
handle temp(m_ptr);
m_ptr = other.m_ptr;
temp.dec_ref();
}
return *this;
}
object &operator=(object &&other) noexcept {
if (this != &other) {
handle temp(m_ptr);
m_ptr = other.m_ptr;
other.m_ptr = nullptr;
temp.dec_ref();
}
return *this;
}
#define PYBIND11_INPLACE_OP(iop) \
object iop(object_api const &other) { return operator=(handle::iop(other)); }
PYBIND11_INPLACE_OP(operator+=)
PYBIND11_INPLACE_OP(operator-=)
PYBIND11_INPLACE_OP(operator*=)
PYBIND11_INPLACE_OP(operator/=)
PYBIND11_INPLACE_OP(operator|=)
PYBIND11_INPLACE_OP(operator&=)
PYBIND11_INPLACE_OP(operator^=)
PYBIND11_INPLACE_OP(operator<<=)
PYBIND11_INPLACE_OP(operator>>=)
#undef PYBIND11_INPLACE_OP
// Calling cast() on an object lvalue just copies (via handle::cast)
template <typename T>
T cast() const &;
// Calling on an object rvalue does a move, if needed and/or possible
template <typename T>
T cast() &&;
protected:
// Tags for choosing constructors from raw PyObject *
struct borrowed_t {};
struct stolen_t {};
/// @cond BROKEN
template <typename T>
friend T reinterpret_borrow(handle);
template <typename T>
friend T reinterpret_steal(handle);
/// @endcond
public:
// Only accessible from derived classes and the reinterpret_* functions
object(handle h, borrowed_t) : handle(h) { inc_ref(); }
object(handle h, stolen_t) : handle(h) {}
};
/** \rst
Declare that a `handle` or ``PyObject *`` is a certain type and borrow the reference.
The target type ``T`` must be `object` or one of its derived classes. The function
doesn't do any conversions or checks. It's up to the user to make sure that the
target type is correct.
.. code-block:: cpp
PyObject *p = PyList_GetItem(obj, index);
py::object o = reinterpret_borrow<py::object>(p);
// or
py::tuple t = reinterpret_borrow<py::tuple>(p); // <-- `p` must be already be a `tuple`
\endrst */
template <typename T>
T reinterpret_borrow(handle h) {
return {h, object::borrowed_t{}};
}
/** \rst
Like `reinterpret_borrow`, but steals the reference.
.. code-block:: cpp
PyObject *p = PyObject_Str(obj);
py::str s = reinterpret_steal<py::str>(p); // <-- `p` must be already be a `str`
\endrst */
template <typename T>
T reinterpret_steal(handle h) {
return {h, object::stolen_t{}};
}
PYBIND11_NAMESPACE_BEGIN(detail)
// Equivalent to obj.__class__.__name__ (or obj.__name__ if obj is a class).
inline const char *obj_class_name(PyObject *obj) {
if (PyType_Check(obj)) {
return reinterpret_cast<PyTypeObject *>(obj)->tp_name;
}
return Py_TYPE(obj)->tp_name;
}
std::string error_string();
// The code in this struct is very unusual, to minimize the chances of
// masking bugs (elsewhere) by errors during the error handling (here).
// This is meant to be a lifeline for troubleshooting long-running processes
// that crash under conditions that are virtually impossible to reproduce.
// Low-level implementation alternatives are preferred to higher-level ones
// that might raise cascading exceptions. Last-ditch-kind-of attempts are made
// to report as much of the original error as possible, even if there are
// secondary issues obtaining some of the details.
struct error_fetch_and_normalize {
// This comment only applies to Python <= 3.11:
// Immediate normalization is long-established behavior (starting with
// https://github.com/pybind/pybind11/commit/135ba8deafb8bf64a15b24d1513899eb600e2011
// from Sep 2016) and safest. Normalization could be deferred, but this could mask
// errors elsewhere, the performance gain is very minor in typical situations
// (usually the dominant bottleneck is EH unwinding), and the implementation here
// would be more complex.
// Starting with Python 3.12, PyErr_Fetch() normalizes exceptions immediately.
// Any errors during normalization are tracked under __notes__.
explicit error_fetch_and_normalize(const char *called) {
PyErr_Fetch(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr());
if (!m_type) {
pybind11_fail("Internal error: " + std::string(called)
+ " called while "
"Python error indicator not set.");
}
const char *exc_type_name_orig = detail::obj_class_name(m_type.ptr());
if (exc_type_name_orig == nullptr) {
pybind11_fail("Internal error: " + std::string(called)
+ " failed to obtain the name "
"of the original active exception type.");
}
m_lazy_error_string = exc_type_name_orig;
#if PY_VERSION_HEX >= 0x030C0000
// The presence of __notes__ is likely due to exception normalization
// errors, although that is not necessarily true, therefore insert a
// hint only:
if (PyObject_HasAttrString(m_value.ptr(), "__notes__")) {
m_lazy_error_string += "[WITH __notes__]";
}
#else
// PyErr_NormalizeException() may change the exception type if there are cascading
// failures. This can potentially be extremely confusing.
PyErr_NormalizeException(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr());
if (m_type.ptr() == nullptr) {
pybind11_fail("Internal error: " + std::string(called)
+ " failed to normalize the "
"active exception.");
}
const char *exc_type_name_norm = detail::obj_class_name(m_type.ptr());
if (exc_type_name_norm == nullptr) {
pybind11_fail("Internal error: " + std::string(called)
+ " failed to obtain the name "
"of the normalized active exception type.");
}
# if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x07030a00
// This behavior runs the risk of masking errors in the error handling, but avoids a
// conflict with PyPy, which relies on the normalization here to change OSError to
// FileNotFoundError (https://github.com/pybind/pybind11/issues/4075).
m_lazy_error_string = exc_type_name_norm;
# else
if (exc_type_name_norm != m_lazy_error_string) {
std::string msg = std::string(called)
+ ": MISMATCH of original and normalized "
"active exception types: ";
msg += "ORIGINAL ";
msg += m_lazy_error_string;
msg += " REPLACED BY ";
msg += exc_type_name_norm;
msg += ": " + format_value_and_trace();
pybind11_fail(msg);
}
# endif
#endif
}
error_fetch_and_normalize(const error_fetch_and_normalize &) = delete;
error_fetch_and_normalize(error_fetch_and_normalize &&) = delete;
std::string format_value_and_trace() const {
std::string result;
std::string message_error_string;
if (m_value) {
auto value_str = reinterpret_steal<object>(PyObject_Str(m_value.ptr()));
constexpr const char *message_unavailable_exc
= "<MESSAGE UNAVAILABLE DUE TO ANOTHER EXCEPTION>";
if (!value_str) {
message_error_string = detail::error_string();
result = message_unavailable_exc;
} else {
// Not using `value_str.cast<std::string>()`, to not potentially throw a secondary
// error_already_set that will then result in process termination (#4288).
auto value_bytes = reinterpret_steal<object>(
PyUnicode_AsEncodedString(value_str.ptr(), "utf-8", "backslashreplace"));
if (!value_bytes) {
message_error_string = detail::error_string();
result = message_unavailable_exc;
} else {
char *buffer = nullptr;
Py_ssize_t length = 0;
if (PyBytes_AsStringAndSize(value_bytes.ptr(), &buffer, &length) == -1) {
message_error_string = detail::error_string();
result = message_unavailable_exc;
} else {
result = std::string(buffer, static_cast<std::size_t>(length));
}
}
}
#if PY_VERSION_HEX >= 0x030B0000
auto notes
= reinterpret_steal<object>(PyObject_GetAttrString(m_value.ptr(), "__notes__"));
if (!notes) {
PyErr_Clear(); // No notes is good news.
} else {
auto len_notes = PyList_Size(notes.ptr());
if (len_notes < 0) {
result += "\nFAILURE obtaining len(__notes__): " + detail::error_string();
} else {
result += "\n__notes__ (len=" + std::to_string(len_notes) + "):";
for (ssize_t i = 0; i < len_notes; i++) {
PyObject *note = PyList_GET_ITEM(notes.ptr(), i);
auto note_bytes = reinterpret_steal<object>(
PyUnicode_AsEncodedString(note, "utf-8", "backslashreplace"));
if (!note_bytes) {
result += "\nFAILURE obtaining __notes__[" + std::to_string(i)
+ "]: " + detail::error_string();
} else {
char *buffer = nullptr;
Py_ssize_t length = 0;
if (PyBytes_AsStringAndSize(note_bytes.ptr(), &buffer, &length)
== -1) {
result += "\nFAILURE formatting __notes__[" + std::to_string(i)
+ "]: " + detail::error_string();
} else {
result += '\n';
result += std::string(buffer, static_cast<std::size_t>(length));
}
}
}
}
}
#endif
} else {
result = "<MESSAGE UNAVAILABLE>";
}
if (result.empty()) {
result = "<EMPTY MESSAGE>";
}
bool have_trace = false;
if (m_trace) {
#if !defined(PYPY_VERSION)
auto *tb = reinterpret_cast<PyTracebackObject *>(m_trace.ptr());
// Get the deepest trace possible.
while (tb->tb_next) {
tb = tb->tb_next;
}
PyFrameObject *frame = tb->tb_frame;
Py_XINCREF(frame);
result += "\n\nAt:\n";
while (frame) {
# if PY_VERSION_HEX >= 0x030900B1
PyCodeObject *f_code = PyFrame_GetCode(frame);
# else
PyCodeObject *f_code = frame->f_code;
Py_INCREF(f_code);
# endif
int lineno = PyFrame_GetLineNumber(frame);
result += " ";
result += handle(f_code->co_filename).cast<std::string>();
result += '(';
result += std::to_string(lineno);
result += "): ";
result += handle(f_code->co_name).cast<std::string>();
result += '\n';
Py_DECREF(f_code);
# if PY_VERSION_HEX >= 0x030900B1
auto *b_frame = PyFrame_GetBack(frame);
# else
auto *b_frame = frame->f_back;
Py_XINCREF(b_frame);
# endif
Py_DECREF(frame);
frame = b_frame;
}
have_trace = true;
#endif //! defined(PYPY_VERSION)
}
if (!message_error_string.empty()) {
if (!have_trace) {
result += '\n';
}
result += "\nMESSAGE UNAVAILABLE DUE TO EXCEPTION: " + message_error_string;
}
return result;
}
std::string const &error_string() const {
if (!m_lazy_error_string_completed) {
m_lazy_error_string += ": " + format_value_and_trace();
m_lazy_error_string_completed = true;
}
return m_lazy_error_string;
}
void restore() {
if (m_restore_called) {
pybind11_fail("Internal error: pybind11::detail::error_fetch_and_normalize::restore() "
"called a second time. ORIGINAL ERROR: "
+ error_string());
}
PyErr_Restore(m_type.inc_ref().ptr(), m_value.inc_ref().ptr(), m_trace.inc_ref().ptr());
m_restore_called = true;
}
bool matches(handle exc) const {
return (PyErr_GivenExceptionMatches(m_type.ptr(), exc.ptr()) != 0);
}
// Not protecting these for simplicity.
object m_type, m_value, m_trace;
private:
// Only protecting invariants.
mutable std::string m_lazy_error_string;
mutable bool m_lazy_error_string_completed = false;
mutable bool m_restore_called = false;
};
inline std::string error_string() {
return error_fetch_and_normalize("pybind11::detail::error_string").error_string();
}
PYBIND11_NAMESPACE_END(detail)
/// Fetch and hold an error which was already set in Python. An instance of this is typically
/// thrown to propagate python-side errors back through C++ which can either be caught manually or
/// else falls back to the function dispatcher (which then raises the captured error back to
/// python).
class PYBIND11_EXPORT_EXCEPTION error_already_set : public std::exception {
public:
/// Fetches the current Python exception (using PyErr_Fetch()), which will clear the
/// current Python error indicator.
error_already_set()
: m_fetched_error{new detail::error_fetch_and_normalize("pybind11::error_already_set"),
m_fetched_error_deleter} {}
/// The what() result is built lazily on demand.
/// WARNING: This member function needs to acquire the Python GIL. This can lead to
/// crashes (undefined behavior) if the Python interpreter is finalizing.
const char *what() const noexcept override;
/// Restores the currently-held Python error (which will clear the Python error indicator first
/// if already set).
/// NOTE: This member function will always restore the normalized exception, which may or may
/// not be the original Python exception.
/// WARNING: The GIL must be held when this member function is called!
void restore() { m_fetched_error->restore(); }
/// If it is impossible to raise the currently-held error, such as in a destructor, we can
/// write it out using Python's unraisable hook (`sys.unraisablehook`). The error context
/// should be some object whose `repr()` helps identify the location of the error. Python
/// already knows the type and value of the error, so there is no need to repeat that.
void discard_as_unraisable(object err_context) {
restore();
PyErr_WriteUnraisable(err_context.ptr());
}
/// An alternate version of `discard_as_unraisable()`, where a string provides information on
/// the location of the error. For example, `__func__` could be helpful.
/// WARNING: The GIL must be held when this member function is called!
void discard_as_unraisable(const char *err_context) {
discard_as_unraisable(reinterpret_steal<object>(PYBIND11_FROM_STRING(err_context)));
}
// Does nothing; provided for backwards compatibility.
PYBIND11_DEPRECATED("Use of error_already_set.clear() is deprecated")
void clear() {}
/// Check if the currently trapped error type matches the given Python exception class (or a
/// subclass thereof). May also be passed a tuple to search for any exception class matches in
/// the given tuple.
bool matches(handle exc) const { return m_fetched_error->matches(exc); }
const object &type() const { return m_fetched_error->m_type; }
const object &value() const { return m_fetched_error->m_value; }
const object &trace() const { return m_fetched_error->m_trace; }
private:
std::shared_ptr<detail::error_fetch_and_normalize> m_fetched_error;
/// WARNING: This custom deleter needs to acquire the Python GIL. This can lead to
/// crashes (undefined behavior) if the Python interpreter is finalizing.
static void m_fetched_error_deleter(detail::error_fetch_and_normalize *raw_ptr);
};
/// Replaces the current Python error indicator with the chosen error, performing a
/// 'raise from' to indicate that the chosen error was caused by the original error.
inline void raise_from(PyObject *type, const char *message) {
// Based on _PyErr_FormatVFromCause:
// https://github.com/python/cpython/blob/467ab194fc6189d9f7310c89937c51abeac56839/Python/errors.c#L405
// See https://github.com/pybind/pybind11/pull/2112 for details.
PyObject *exc = nullptr, *val = nullptr, *val2 = nullptr, *tb = nullptr;
assert(PyErr_Occurred());
PyErr_Fetch(&exc, &val, &tb);
PyErr_NormalizeException(&exc, &val, &tb);
if (tb != nullptr) {
PyException_SetTraceback(val, tb);
Py_DECREF(tb);
}
Py_DECREF(exc);
assert(!PyErr_Occurred());
PyErr_SetString(type, message);
PyErr_Fetch(&exc, &val2, &tb);
PyErr_NormalizeException(&exc, &val2, &tb);
Py_INCREF(val);
PyException_SetCause(val2, val);
PyException_SetContext(val2, val);
PyErr_Restore(exc, val2, tb);
}
/// Sets the current Python error indicator with the chosen error, performing a 'raise from'
/// from the error contained in error_already_set to indicate that the chosen error was
/// caused by the original error.
inline void raise_from(error_already_set &err, PyObject *type, const char *message) {
err.restore();
raise_from(type, message);
}
/** \defgroup python_builtins const_name
Unless stated otherwise, the following C++ functions behave the same
as their Python counterparts.
*/
/** \ingroup python_builtins
\rst
Return true if ``obj`` is an instance of ``T``. Type ``T`` must be a subclass of
`object` or a class which was exposed to Python as ``py::class_<T>``.
\endrst */
template <typename T, detail::enable_if_t<std::is_base_of<object, T>::value, int> = 0>
bool isinstance(handle obj) {
return T::check_(obj);
}
template <typename T, detail::enable_if_t<!std::is_base_of<object, T>::value, int> = 0>
bool isinstance(handle obj) {
return detail::isinstance_generic(obj, typeid(T));
}
template <>
inline bool isinstance<handle>(handle) = delete;
template <>
inline bool isinstance<object>(handle obj) {
return obj.ptr() != nullptr;
}
/// \ingroup python_builtins
/// Return true if ``obj`` is an instance of the ``type``.
inline bool isinstance(handle obj, handle type) {
const auto result = PyObject_IsInstance(obj.ptr(), type.ptr());
if (result == -1) {
throw error_already_set();
}
return result != 0;
}
/// \addtogroup python_builtins
/// @{
inline bool hasattr(handle obj, handle name) {
return PyObject_HasAttr(obj.ptr(), name.ptr()) == 1;
}
inline bool hasattr(handle obj, const char *name) {
return PyObject_HasAttrString(obj.ptr(), name) == 1;
}
inline void delattr(handle obj, handle name) {
if (PyObject_DelAttr(obj.ptr(), name.ptr()) != 0) {
throw error_already_set();
}
}
inline void delattr(handle obj, const char *name) {
if (PyObject_DelAttrString(obj.ptr(), name) != 0) {
throw error_already_set();
}
}
inline object getattr(handle obj, handle name) {
PyObject *result = PyObject_GetAttr(obj.ptr(), name.ptr());
if (!result) {
throw error_already_set();
}
return reinterpret_steal<object>(result);
}
inline object getattr(handle obj, const char *name) {
PyObject *result = PyObject_GetAttrString(obj.ptr(), name);
if (!result) {
throw error_already_set();
}
return reinterpret_steal<object>(result);
}
inline object getattr(handle obj, handle name, handle default_) {
if (PyObject *result = PyObject_GetAttr(obj.ptr(), name.ptr())) {
return reinterpret_steal<object>(result);
}
PyErr_Clear();
return reinterpret_borrow<object>(default_);
}
inline object getattr(handle obj, const char *name, handle default_) {
if (PyObject *result = PyObject_GetAttrString(obj.ptr(), name)) {
return reinterpret_steal<object>(result);
}
PyErr_Clear();
return reinterpret_borrow<object>(default_);
}
inline void setattr(handle obj, handle name, handle value) {
if (PyObject_SetAttr(obj.ptr(), name.ptr(), value.ptr()) != 0) {
throw error_already_set();
}
}
inline void setattr(handle obj, const char *name, handle value) {
if (PyObject_SetAttrString(obj.ptr(), name, value.ptr()) != 0) {
throw error_already_set();
}
}
inline ssize_t hash(handle obj) {
auto h = PyObject_Hash(obj.ptr());
if (h == -1) {
throw error_already_set();
}
return h;
}
/// @} python_builtins
PYBIND11_NAMESPACE_BEGIN(detail)
inline handle get_function(handle value) {
if (value) {
if (PyInstanceMethod_Check(value.ptr())) {
value = PyInstanceMethod_GET_FUNCTION(value.ptr());
} else if (PyMethod_Check(value.ptr())) {
value = PyMethod_GET_FUNCTION(value.ptr());
}
}
return value;
}
// Reimplementation of python's dict helper functions to ensure that exceptions
// aren't swallowed (see #2862)
// copied from cpython _PyDict_GetItemStringWithError
inline PyObject *dict_getitemstring(PyObject *v, const char *key) {
PyObject *kv = nullptr, *rv = nullptr;
kv = PyUnicode_FromString(key);
if (kv == nullptr) {
throw error_already_set();
}
rv = PyDict_GetItemWithError(v, kv);
Py_DECREF(kv);
if (rv == nullptr && PyErr_Occurred()) {
throw error_already_set();
}
return rv;
}
inline PyObject *dict_getitem(PyObject *v, PyObject *key) {
PyObject *rv = PyDict_GetItemWithError(v, key);
if (rv == nullptr && PyErr_Occurred()) {
throw error_already_set();
}
return rv;
}
// Helper aliases/functions to support implicit casting of values given to python
// accessors/methods. When given a pyobject, this simply returns the pyobject as-is; for other C++
// type, the value goes through pybind11::cast(obj) to convert it to an `object`.
template <typename T, enable_if_t<is_pyobject<T>::value, int> = 0>
auto object_or_cast(T &&o) -> decltype(std::forward<T>(o)) {
return std::forward<T>(o);
}
// The following casting version is implemented in cast.h:
template <typename T, enable_if_t<!is_pyobject<T>::value, int> = 0>
object object_or_cast(T &&o);
// Match a PyObject*, which we want to convert directly to handle via its converting constructor
inline handle object_or_cast(PyObject *ptr) { return ptr; }
PYBIND11_WARNING_PUSH
PYBIND11_WARNING_DISABLE_MSVC(4522) // warning C4522: multiple assignment operators specified
template <typename Policy>
class accessor : public object_api<accessor<Policy>> {
using key_type = typename Policy::key_type;
public:
accessor(handle obj, key_type key) : obj(obj), key(std::move(key)) {}
accessor(const accessor &) = default;
accessor(accessor &&) noexcept = default;
// accessor overload required to override default assignment operator (templates are not
// allowed to replace default compiler-generated assignments).
void operator=(const accessor &a) && { std::move(*this).operator=(handle(a)); }
void operator=(const accessor &a) & { operator=(handle(a)); }
template <typename T>
void operator=(T &&value) && {
Policy::set(obj, key, object_or_cast(std::forward<T>(value)));
}
template <typename T>
void operator=(T &&value) & {
get_cache() = ensure_object(object_or_cast(std::forward<T>(value)));
}
template <typename T = Policy>
PYBIND11_DEPRECATED(
"Use of obj.attr(...) as bool is deprecated in favor of pybind11::hasattr(obj, ...)")
explicit
operator enable_if_t<std::is_same<T, accessor_policies::str_attr>::value
|| std::is_same<T, accessor_policies::obj_attr>::value,
bool>() const {
return hasattr(obj, key);
}
template <typename T = Policy>
PYBIND11_DEPRECATED("Use of obj[key] as bool is deprecated in favor of obj.contains(key)")
explicit
operator enable_if_t<std::is_same<T, accessor_policies::generic_item>::value, bool>() const {
return obj.contains(key);
}
// NOLINTNEXTLINE(google-explicit-constructor)
operator object() const { return get_cache(); }
PyObject *ptr() const { return get_cache().ptr(); }
template <typename T>
T cast() const {
return get_cache().template cast<T>();
}
private:
static object ensure_object(object &&o) { return std::move(o); }
static object ensure_object(handle h) { return reinterpret_borrow<object>(h); }
object &get_cache() const {
if (!cache) {
cache = Policy::get(obj, key);
}
return cache;
}
private:
handle obj;
key_type key;
mutable object cache;
};
PYBIND11_WARNING_POP
PYBIND11_NAMESPACE_BEGIN(accessor_policies)
struct obj_attr {
using key_type = object;
static object get(handle obj, handle key) { return getattr(obj, key); }
static void set(handle obj, handle key, handle val) { setattr(obj, key, val); }
};
struct str_attr {
using key_type = const char *;
static object get(handle obj, const char *key) { return getattr(obj, key); }
static void set(handle obj, const char *key, handle val) { setattr(obj, key, val); }
};
struct generic_item {
using key_type = object;
static object get(handle obj, handle key) {
PyObject *result = PyObject_GetItem(obj.ptr(), key.ptr());
if (!result) {
throw error_already_set();
}
return reinterpret_steal<object>(result);
}
static void set(handle obj, handle key, handle val) {
if (PyObject_SetItem(obj.ptr(), key.ptr(), val.ptr()) != 0) {
throw error_already_set();
}
}
};
struct sequence_item {
using key_type = size_t;
template <typename IdxType, detail::enable_if_t<std::is_integral<IdxType>::value, int> = 0>
static object get(handle obj, const IdxType &index) {
PyObject *result = PySequence_GetItem(obj.ptr(), ssize_t_cast(index));
if (!result) {
throw error_already_set();
}
return reinterpret_steal<object>(result);
}
template <typename IdxType, detail::enable_if_t<std::is_integral<IdxType>::value, int> = 0>
static void set(handle obj, const IdxType &index, handle val) {
// PySequence_SetItem does not steal a reference to 'val'
if (PySequence_SetItem(obj.ptr(), ssize_t_cast(index), val.ptr()) != 0) {
throw error_already_set();
}
}
};
struct list_item {
using key_type = size_t;
template <typename IdxType, detail::enable_if_t<std::is_integral<IdxType>::value, int> = 0>
static object get(handle obj, const IdxType &index) {
PyObject *result = PyList_GetItem(obj.ptr(), ssize_t_cast(index));
if (!result) {
throw error_already_set();
}
return reinterpret_borrow<object>(result);
}
template <typename IdxType, detail::enable_if_t<std::is_integral<IdxType>::value, int> = 0>
static void set(handle obj, const IdxType &index, handle val) {
// PyList_SetItem steals a reference to 'val'
if (PyList_SetItem(obj.ptr(), ssize_t_cast(index), val.inc_ref().ptr()) != 0) {
throw error_already_set();
}
}
};
struct tuple_item {
using key_type = size_t;
template <typename IdxType, detail::enable_if_t<std::is_integral<IdxType>::value, int> = 0>
static object get(handle obj, const IdxType &index) {
PyObject *result = PyTuple_GetItem(obj.ptr(), ssize_t_cast(index));
if (!result) {
throw error_already_set();
}
return reinterpret_borrow<object>(result);
}
template <typename IdxType, detail::enable_if_t<std::is_integral<IdxType>::value, int> = 0>
static void set(handle obj, const IdxType &index, handle val) {
// PyTuple_SetItem steals a reference to 'val'
if (PyTuple_SetItem(obj.ptr(), ssize_t_cast(index), val.inc_ref().ptr()) != 0) {
throw error_already_set();
}
}
};
PYBIND11_NAMESPACE_END(accessor_policies)
/// STL iterator template used for tuple, list, sequence and dict
template <typename Policy>
class generic_iterator : public Policy {
using It = generic_iterator;
public:
using difference_type = ssize_t;
using iterator_category = typename Policy::iterator_category;
using value_type = typename Policy::value_type;
using reference = typename Policy::reference;
using pointer = typename Policy::pointer;
generic_iterator() = default;
generic_iterator(handle seq, ssize_t index) : Policy(seq, index) {}
// NOLINTNEXTLINE(readability-const-return-type) // PR #3263
reference operator*() const { return Policy::dereference(); }
// NOLINTNEXTLINE(readability-const-return-type) // PR #3263
reference operator[](difference_type n) const { return *(*this + n); }
pointer operator->() const { return **this; }
It &operator++() {
Policy::increment();
return *this;
}
It operator++(int) {
auto copy = *this;
Policy::increment();
return copy;
}
It &operator--() {
Policy::decrement();
return *this;
}
It operator--(int) {
auto copy = *this;
Policy::decrement();
return copy;
}
It &operator+=(difference_type n) {
Policy::advance(n);
return *this;
}
It &operator-=(difference_type n) {
Policy::advance(-n);
return *this;
}
friend It operator+(const It &a, difference_type n) {
auto copy = a;
return copy += n;
}
friend It operator+(difference_type n, const It &b) { return b + n; }
friend It operator-(const It &a, difference_type n) {
auto copy = a;
return copy -= n;
}
friend difference_type operator-(const It &a, const It &b) { return a.distance_to(b); }
friend bool operator==(const It &a, const It &b) { return a.equal(b); }
friend bool operator!=(const It &a, const It &b) { return !(a == b); }
friend bool operator<(const It &a, const It &b) { return b - a > 0; }
friend bool operator>(const It &a, const It &b) { return b < a; }
friend bool operator>=(const It &a, const It &b) { return !(a < b); }
friend bool operator<=(const It &a, const It &b) { return !(a > b); }
};
PYBIND11_NAMESPACE_BEGIN(iterator_policies)
/// Quick proxy class needed to implement ``operator->`` for iterators which can't return pointers
template <typename T>
struct arrow_proxy {
T value;
// NOLINTNEXTLINE(google-explicit-constructor)
arrow_proxy(T &&value) noexcept : value(std::move(value)) {}
T *operator->() const { return &value; }
};
/// Lightweight iterator policy using just a simple pointer: see ``PySequence_Fast_ITEMS``
class sequence_fast_readonly {
protected:
using iterator_category = std::random_access_iterator_tag;
using value_type = handle;
using reference = const handle; // PR #3263
using pointer = arrow_proxy<const handle>;
sequence_fast_readonly(handle obj, ssize_t n) : ptr(PySequence_Fast_ITEMS(obj.ptr()) + n) {}
// NOLINTNEXTLINE(readability-const-return-type) // PR #3263
reference dereference() const { return *ptr; }
void increment() { ++ptr; }
void decrement() { --ptr; }
void advance(ssize_t n) { ptr += n; }
bool equal(const sequence_fast_readonly &b) const { return ptr == b.ptr; }
ssize_t distance_to(const sequence_fast_readonly &b) const { return ptr - b.ptr; }
private:
PyObject **ptr;
};
/// Full read and write access using the sequence protocol: see ``detail::sequence_accessor``
class sequence_slow_readwrite {
protected:
using iterator_category = std::random_access_iterator_tag;
using value_type = object;
using reference = sequence_accessor;
using pointer = arrow_proxy<const sequence_accessor>;
sequence_slow_readwrite(handle obj, ssize_t index) : obj(obj), index(index) {}
reference dereference() const { return {obj, static_cast<size_t>(index)}; }
void increment() { ++index; }
void decrement() { --index; }
void advance(ssize_t n) { index += n; }
bool equal(const sequence_slow_readwrite &b) const { return index == b.index; }
ssize_t distance_to(const sequence_slow_readwrite &b) const { return index - b.index; }
private:
handle obj;
ssize_t index;
};
/// Python's dictionary protocol permits this to be a forward iterator
class dict_readonly {
protected:
using iterator_category = std::forward_iterator_tag;
using value_type = std::pair<handle, handle>;
using reference = const value_type; // PR #3263
using pointer = arrow_proxy<const value_type>;
dict_readonly() = default;
dict_readonly(handle obj, ssize_t pos) : obj(obj), pos(pos) { increment(); }
// NOLINTNEXTLINE(readability-const-return-type) // PR #3263
reference dereference() const { return {key, value}; }
void increment() {
if (PyDict_Next(obj.ptr(), &pos, &key, &value) == 0) {
pos = -1;
}
}
bool equal(const dict_readonly &b) const { return pos == b.pos; }
private:
handle obj;
PyObject *key = nullptr, *value = nullptr;
ssize_t pos = -1;
};
PYBIND11_NAMESPACE_END(iterator_policies)
#if !defined(PYPY_VERSION)
using tuple_iterator = generic_iterator<iterator_policies::sequence_fast_readonly>;
using list_iterator = generic_iterator<iterator_policies::sequence_fast_readonly>;
#else
using tuple_iterator = generic_iterator<iterator_policies::sequence_slow_readwrite>;
using list_iterator = generic_iterator<iterator_policies::sequence_slow_readwrite>;
#endif
using sequence_iterator = generic_iterator<iterator_policies::sequence_slow_readwrite>;
using dict_iterator = generic_iterator<iterator_policies::dict_readonly>;
inline bool PyIterable_Check(PyObject *obj) {
PyObject *iter = PyObject_GetIter(obj);
if (iter) {
Py_DECREF(iter);
return true;
}
PyErr_Clear();
return false;
}
inline bool PyNone_Check(PyObject *o) { return o == Py_None; }
inline bool PyEllipsis_Check(PyObject *o) { return o == Py_Ellipsis; }
#ifdef PYBIND11_STR_LEGACY_PERMISSIVE
inline bool PyUnicode_Check_Permissive(PyObject *o) {
return PyUnicode_Check(o) || PYBIND11_BYTES_CHECK(o);
}
# define PYBIND11_STR_CHECK_FUN detail::PyUnicode_Check_Permissive
#else
# define PYBIND11_STR_CHECK_FUN PyUnicode_Check
#endif
inline bool PyStaticMethod_Check(PyObject *o) { return o->ob_type == &PyStaticMethod_Type; }
class kwargs_proxy : public handle {
public:
explicit kwargs_proxy(handle h) : handle(h) {}
};
class args_proxy : public handle {
public:
explicit args_proxy(handle h) : handle(h) {}
kwargs_proxy operator*() const { return kwargs_proxy(*this); }
};
/// Python argument categories (using PEP 448 terms)
template <typename T>
using is_keyword = std::is_base_of<arg, T>;
template <typename T>
using is_s_unpacking = std::is_same<args_proxy, T>; // * unpacking
template <typename T>
using is_ds_unpacking = std::is_same<kwargs_proxy, T>; // ** unpacking
template <typename T>
using is_positional = satisfies_none_of<T, is_keyword, is_s_unpacking, is_ds_unpacking>;
template <typename T>
using is_keyword_or_ds = satisfies_any_of<T, is_keyword, is_ds_unpacking>;
// Call argument collector forward declarations
template <return_value_policy policy = return_value_policy::automatic_reference>
class simple_collector;
template <return_value_policy policy = return_value_policy::automatic_reference>
class unpacking_collector;
PYBIND11_NAMESPACE_END(detail)
// TODO: After the deprecated constructors are removed, this macro can be simplified by
// inheriting ctors: `using Parent::Parent`. It's not an option right now because
// the `using` statement triggers the parent deprecation warning even if the ctor
// isn't even used.
#define PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \
public: \
PYBIND11_DEPRECATED("Use reinterpret_borrow<" #Name ">() or reinterpret_steal<" #Name ">()") \
Name(handle h, bool is_borrowed) \
: Parent(is_borrowed ? Parent(h, borrowed_t{}) : Parent(h, stolen_t{})) {} \
Name(handle h, borrowed_t) : Parent(h, borrowed_t{}) {} \
Name(handle h, stolen_t) : Parent(h, stolen_t{}) {} \
PYBIND11_DEPRECATED("Use py::isinstance<py::python_type>(obj) instead") \
bool check() const { return m_ptr != nullptr && (CheckFun(m_ptr) != 0); } \
static bool check_(handle h) { return h.ptr() != nullptr && CheckFun(h.ptr()); } \
template <typename Policy_> /* NOLINTNEXTLINE(google-explicit-constructor) */ \
Name(const ::pybind11::detail::accessor<Policy_> &a) : Name(object(a)) {}
#define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun) \
PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \
/* This is deliberately not 'explicit' to allow implicit conversion from object: */ \
/* NOLINTNEXTLINE(google-explicit-constructor) */ \
Name(const object &o) \
: Parent(check_(o) ? o.inc_ref().ptr() : ConvertFun(o.ptr()), stolen_t{}) { \
if (!m_ptr) \
throw ::pybind11::error_already_set(); \
} \
/* NOLINTNEXTLINE(google-explicit-constructor) */ \
Name(object &&o) : Parent(check_(o) ? o.release().ptr() : ConvertFun(o.ptr()), stolen_t{}) { \
if (!m_ptr) \
throw ::pybind11::error_already_set(); \
}
#define PYBIND11_OBJECT_CVT_DEFAULT(Name, Parent, CheckFun, ConvertFun) \
PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun) \
Name() = default;
#define PYBIND11_OBJECT_CHECK_FAILED(Name, o_ptr) \
::pybind11::type_error("Object of type '" \
+ ::pybind11::detail::get_fully_qualified_tp_name(Py_TYPE(o_ptr)) \
+ "' is not an instance of '" #Name "'")
#define PYBIND11_OBJECT(Name, Parent, CheckFun) \
PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \
/* This is deliberately not 'explicit' to allow implicit conversion from object: */ \
/* NOLINTNEXTLINE(google-explicit-constructor) */ \
Name(const object &o) : Parent(o) { \
if (m_ptr && !check_(m_ptr)) \
throw PYBIND11_OBJECT_CHECK_FAILED(Name, m_ptr); \
} \
/* NOLINTNEXTLINE(google-explicit-constructor) */ \
Name(object &&o) : Parent(std::move(o)) { \
if (m_ptr && !check_(m_ptr)) \
throw PYBIND11_OBJECT_CHECK_FAILED(Name, m_ptr); \
}
#define PYBIND11_OBJECT_DEFAULT(Name, Parent, CheckFun) \
PYBIND11_OBJECT(Name, Parent, CheckFun) \
Name() = default;
/// \addtogroup pytypes
/// @{
/** \rst
Wraps a Python iterator so that it can also be used as a C++ input iterator
Caveat: copying an iterator does not (and cannot) clone the internal
state of the Python iterable. This also applies to the post-increment
operator. This iterator should only be used to retrieve the current
value using ``operator*()``.
\endrst */
class iterator : public object {
public:
using iterator_category = std::input_iterator_tag;
using difference_type = ssize_t;
using value_type = handle;
using reference = const handle; // PR #3263
using pointer = const handle *;
PYBIND11_OBJECT_DEFAULT(iterator, object, PyIter_Check)
iterator &operator++() {
advance();
return *this;
}
iterator operator++(int) {
auto rv = *this;
advance();
return rv;
}
// NOLINTNEXTLINE(readability-const-return-type) // PR #3263
reference operator*() const {
if (m_ptr && !value.ptr()) {
auto &self = const_cast<iterator &>(*this);
self.advance();
}
return value;
}
pointer operator->() const {
operator*();
return &value;
}
/** \rst
The value which marks the end of the iteration. ``it == iterator::sentinel()``
is equivalent to catching ``StopIteration`` in Python.
.. code-block:: cpp
void foo(py::iterator it) {
while (it != py::iterator::sentinel()) {
// use `*it`
++it;
}
}
\endrst */
static iterator sentinel() { return {}; }
friend bool operator==(const iterator &a, const iterator &b) { return a->ptr() == b->ptr(); }
friend bool operator!=(const iterator &a, const iterator &b) { return a->ptr() != b->ptr(); }
private:
void advance() {
value = reinterpret_steal<object>(PyIter_Next(m_ptr));
if (value.ptr() == nullptr && PyErr_Occurred()) {
throw error_already_set();
}
}
private:
object value = {};
};
class type : public object {
public:
PYBIND11_OBJECT(type, object, PyType_Check)
/// Return a type handle from a handle or an object
static handle handle_of(handle h) { return handle((PyObject *) Py_TYPE(h.ptr())); }
/// Return a type object from a handle or an object
static type of(handle h) { return type(type::handle_of(h), borrowed_t{}); }
// Defined in pybind11/cast.h
/// Convert C++ type to handle if previously registered. Does not convert
/// standard types, like int, float. etc. yet.
/// See https://github.com/pybind/pybind11/issues/2486
template <typename T>
static handle handle_of();
/// Convert C++ type to type if previously registered. Does not convert
/// standard types, like int, float. etc. yet.
/// See https://github.com/pybind/pybind11/issues/2486
template <typename T>
static type of() {
return type(type::handle_of<T>(), borrowed_t{});
}
};
class iterable : public object {
public:
PYBIND11_OBJECT_DEFAULT(iterable, object, detail::PyIterable_Check)
};
class bytes;
class str : public object {
public:
PYBIND11_OBJECT_CVT(str, object, PYBIND11_STR_CHECK_FUN, raw_str)
template <typename SzType, detail::enable_if_t<std::is_integral<SzType>::value, int> = 0>
str(const char *c, const SzType &n)
: object(PyUnicode_FromStringAndSize(c, ssize_t_cast(n)), stolen_t{}) {
if (!m_ptr) {
if (PyErr_Occurred()) {
throw error_already_set();
}
pybind11_fail("Could not allocate string object!");
}
}
// 'explicit' is explicitly omitted from the following constructors to allow implicit
// conversion to py::str from C++ string-like objects
// NOLINTNEXTLINE(google-explicit-constructor)
str(const char *c = "") : object(PyUnicode_FromString(c), stolen_t{}) {
if (!m_ptr) {
if (PyErr_Occurred()) {
throw error_already_set();
}
pybind11_fail("Could not allocate string object!");
}
}
// NOLINTNEXTLINE(google-explicit-constructor)
str(const std::string &s) : str(s.data(), s.size()) {}
#ifdef PYBIND11_HAS_STRING_VIEW
// enable_if is needed to avoid "ambiguous conversion" errors (see PR #3521).
template <typename T, detail::enable_if_t<std::is_same<T, std::string_view>::value, int> = 0>
// NOLINTNEXTLINE(google-explicit-constructor)
str(T s) : str(s.data(), s.size()) {}
# ifdef PYBIND11_HAS_U8STRING
// reinterpret_cast here is safe (C++20 guarantees char8_t has the same size/alignment as char)
// NOLINTNEXTLINE(google-explicit-constructor)
str(std::u8string_view s) : str(reinterpret_cast<const char *>(s.data()), s.size()) {}
# endif
#endif
explicit str(const bytes &b);
/** \rst
Return a string representation of the object. This is analogous to
the ``str()`` function in Python.
\endrst */
explicit str(handle h) : object(raw_str(h.ptr()), stolen_t{}) {
if (!m_ptr) {
throw error_already_set();
}
}
// NOLINTNEXTLINE(google-explicit-constructor)
operator std::string() const {
object temp = *this;
if (PyUnicode_Check(m_ptr)) {
temp = reinterpret_steal<object>(PyUnicode_AsUTF8String(m_ptr));
if (!temp) {
throw error_already_set();
}
}
char *buffer = nullptr;
ssize_t length = 0;
if (PyBytes_AsStringAndSize(temp.ptr(), &buffer, &length) != 0) {
throw error_already_set();
}
return std::string(buffer, (size_t) length);
}
template <typename... Args>
str format(Args &&...args) const {
return attr("format")(std::forward<Args>(args)...);
}
private:
/// Return string representation -- always returns a new reference, even if already a str
static PyObject *raw_str(PyObject *op) {
PyObject *str_value = PyObject_Str(op);
return str_value;
}
};
/// @} pytypes
inline namespace literals {
/** \rst
String literal version of `str`
\endrst */
inline str operator"" _s(const char *s, size_t size) { return {s, size}; }
} // namespace literals
/// \addtogroup pytypes
/// @{
class bytes : public object {
public:
PYBIND11_OBJECT(bytes, object, PYBIND11_BYTES_CHECK)
// Allow implicit conversion:
// NOLINTNEXTLINE(google-explicit-constructor)
bytes(const char *c = "") : object(PYBIND11_BYTES_FROM_STRING(c), stolen_t{}) {
if (!m_ptr) {
pybind11_fail("Could not allocate bytes object!");
}
}
template <typename SzType, detail::enable_if_t<std::is_integral<SzType>::value, int> = 0>
bytes(const char *c, const SzType &n)
: object(PYBIND11_BYTES_FROM_STRING_AND_SIZE(c, ssize_t_cast(n)), stolen_t{}) {
if (!m_ptr) {
pybind11_fail("Could not allocate bytes object!");
}
}
// Allow implicit conversion:
// NOLINTNEXTLINE(google-explicit-constructor)
bytes(const std::string &s) : bytes(s.data(), s.size()) {}
explicit bytes(const pybind11::str &s);
// NOLINTNEXTLINE(google-explicit-constructor)
operator std::string() const { return string_op<std::string>(); }
#ifdef PYBIND11_HAS_STRING_VIEW
// enable_if is needed to avoid "ambiguous conversion" errors (see PR #3521).
template <typename T, detail::enable_if_t<std::is_same<T, std::string_view>::value, int> = 0>
// NOLINTNEXTLINE(google-explicit-constructor)
bytes(T s) : bytes(s.data(), s.size()) {}
// Obtain a string view that views the current `bytes` buffer value. Note that this is only
// valid so long as the `bytes` instance remains alive and so generally should not outlive the
// lifetime of the `bytes` instance.
// NOLINTNEXTLINE(google-explicit-constructor)
operator std::string_view() const { return string_op<std::string_view>(); }
#endif
private:
template <typename T>
T string_op() const {
char *buffer = nullptr;
ssize_t length = 0;
if (PyBytes_AsStringAndSize(m_ptr, &buffer, &length) != 0) {
throw error_already_set();
}
return {buffer, static_cast<size_t>(length)};
}
};
// Note: breathe >= 4.17.0 will fail to build docs if the below two constructors
// are included in the doxygen group; close here and reopen after as a workaround
/// @} pytypes
inline bytes::bytes(const pybind11::str &s) {
object temp = s;
if (PyUnicode_Check(s.ptr())) {
temp = reinterpret_steal<object>(PyUnicode_AsUTF8String(s.ptr()));
if (!temp) {
throw error_already_set();
}
}
char *buffer = nullptr;
ssize_t length = 0;
if (PyBytes_AsStringAndSize(temp.ptr(), &buffer, &length) != 0) {
throw error_already_set();
}
auto obj = reinterpret_steal<object>(PYBIND11_BYTES_FROM_STRING_AND_SIZE(buffer, length));
if (!obj) {
pybind11_fail("Could not allocate bytes object!");
}
m_ptr = obj.release().ptr();
}
inline str::str(const bytes &b) {
char *buffer = nullptr;
ssize_t length = 0;
if (PyBytes_AsStringAndSize(b.ptr(), &buffer, &length) != 0) {
throw error_already_set();
}
auto obj = reinterpret_steal<object>(PyUnicode_FromStringAndSize(buffer, length));
if (!obj) {
if (PyErr_Occurred()) {
throw error_already_set();
}
pybind11_fail("Could not allocate string object!");
}
m_ptr = obj.release().ptr();
}
/// \addtogroup pytypes
/// @{
class bytearray : public object {
public:
PYBIND11_OBJECT_CVT(bytearray, object, PyByteArray_Check, PyByteArray_FromObject)
template <typename SzType, detail::enable_if_t<std::is_integral<SzType>::value, int> = 0>
bytearray(const char *c, const SzType &n)
: object(PyByteArray_FromStringAndSize(c, ssize_t_cast(n)), stolen_t{}) {
if (!m_ptr) {
pybind11_fail("Could not allocate bytearray object!");
}
}
bytearray() : bytearray("", 0) {}
explicit bytearray(const std::string &s) : bytearray(s.data(), s.size()) {}
size_t size() const { return static_cast<size_t>(PyByteArray_Size(m_ptr)); }
explicit operator std::string() const {
char *buffer = PyByteArray_AS_STRING(m_ptr);
ssize_t size = PyByteArray_GET_SIZE(m_ptr);
return std::string(buffer, static_cast<size_t>(size));
}
};
// Note: breathe >= 4.17.0 will fail to build docs if the below two constructors
// are included in the doxygen group; close here and reopen after as a workaround
/// @} pytypes
/// \addtogroup pytypes
/// @{
class none : public object {
public:
PYBIND11_OBJECT(none, object, detail::PyNone_Check)
none() : object(Py_None, borrowed_t{}) {}
};
class ellipsis : public object {
public:
PYBIND11_OBJECT(ellipsis, object, detail::PyEllipsis_Check)
ellipsis() : object(Py_Ellipsis, borrowed_t{}) {}
};
class bool_ : public object {
public:
PYBIND11_OBJECT_CVT(bool_, object, PyBool_Check, raw_bool)
bool_() : object(Py_False, borrowed_t{}) {}
// Allow implicit conversion from and to `bool`:
// NOLINTNEXTLINE(google-explicit-constructor)
bool_(bool value) : object(value ? Py_True : Py_False, borrowed_t{}) {}
// NOLINTNEXTLINE(google-explicit-constructor)
operator bool() const { return (m_ptr != nullptr) && PyLong_AsLong(m_ptr) != 0; }
private:
/// Return the truth value of an object -- always returns a new reference
static PyObject *raw_bool(PyObject *op) {
const auto value = PyObject_IsTrue(op);
if (value == -1) {
return nullptr;
}
return handle(value != 0 ? Py_True : Py_False).inc_ref().ptr();
}
};
PYBIND11_NAMESPACE_BEGIN(detail)
// Converts a value to the given unsigned type. If an error occurs, you get back (Unsigned) -1;
// otherwise you get back the unsigned long or unsigned long long value cast to (Unsigned).
// (The distinction is critically important when casting a returned -1 error value to some other
// unsigned type: (A)-1 != (B)-1 when A and B are unsigned types of different sizes).
template <typename Unsigned>
Unsigned as_unsigned(PyObject *o) {
if (sizeof(Unsigned) <= sizeof(unsigned long)) {
unsigned long v = PyLong_AsUnsignedLong(o);
return v == (unsigned long) -1 && PyErr_Occurred() ? (Unsigned) -1 : (Unsigned) v;
}
unsigned long long v = PyLong_AsUnsignedLongLong(o);
return v == (unsigned long long) -1 && PyErr_Occurred() ? (Unsigned) -1 : (Unsigned) v;
}
PYBIND11_NAMESPACE_END(detail)
class int_ : public object {
public:
PYBIND11_OBJECT_CVT(int_, object, PYBIND11_LONG_CHECK, PyNumber_Long)
int_() : object(PyLong_FromLong(0), stolen_t{}) {}
// Allow implicit conversion from C++ integral types:
template <typename T, detail::enable_if_t<std::is_integral<T>::value, int> = 0>
// NOLINTNEXTLINE(google-explicit-constructor)
int_(T value) {
if (sizeof(T) <= sizeof(long)) {
if (std::is_signed<T>::value) {
m_ptr = PyLong_FromLong((long) value);
} else {
m_ptr = PyLong_FromUnsignedLong((unsigned long) value);
}
} else {
if (std::is_signed<T>::value) {
m_ptr = PyLong_FromLongLong((long long) value);
} else {
m_ptr = PyLong_FromUnsignedLongLong((unsigned long long) value);
}
}
if (!m_ptr) {
pybind11_fail("Could not allocate int object!");
}
}
template <typename T, detail::enable_if_t<std::is_integral<T>::value, int> = 0>
// NOLINTNEXTLINE(google-explicit-constructor)
operator T() const {
return std::is_unsigned<T>::value ? detail::as_unsigned<T>(m_ptr)
: sizeof(T) <= sizeof(long) ? (T) PyLong_AsLong(m_ptr)
: (T) PYBIND11_LONG_AS_LONGLONG(m_ptr);
}
};
class float_ : public object {
public:
PYBIND11_OBJECT_CVT(float_, object, PyFloat_Check, PyNumber_Float)
// Allow implicit conversion from float/double:
// NOLINTNEXTLINE(google-explicit-constructor)
float_(float value) : object(PyFloat_FromDouble((double) value), stolen_t{}) {
if (!m_ptr) {
pybind11_fail("Could not allocate float object!");
}
}
// NOLINTNEXTLINE(google-explicit-constructor)
float_(double value = .0) : object(PyFloat_FromDouble((double) value), stolen_t{}) {
if (!m_ptr) {
pybind11_fail("Could not allocate float object!");
}
}
// NOLINTNEXTLINE(google-explicit-constructor)
operator float() const { return (float) PyFloat_AsDouble(m_ptr); }
// NOLINTNEXTLINE(google-explicit-constructor)
operator double() const { return (double) PyFloat_AsDouble(m_ptr); }
};
class weakref : public object {
public:
PYBIND11_OBJECT_CVT_DEFAULT(weakref, object, PyWeakref_Check, raw_weakref)
explicit weakref(handle obj, handle callback = {})
: object(PyWeakref_NewRef(obj.ptr(), callback.ptr()), stolen_t{}) {
if (!m_ptr) {
if (PyErr_Occurred()) {
throw error_already_set();
}
pybind11_fail("Could not allocate weak reference!");
}
}
private:
static PyObject *raw_weakref(PyObject *o) { return PyWeakref_NewRef(o, nullptr); }
};
class slice : public object {
public:
PYBIND11_OBJECT_DEFAULT(slice, object, PySlice_Check)
slice(handle start, handle stop, handle step)
: object(PySlice_New(start.ptr(), stop.ptr(), step.ptr()), stolen_t{}) {
if (!m_ptr) {
pybind11_fail("Could not allocate slice object!");
}
}
#ifdef PYBIND11_HAS_OPTIONAL
slice(std::optional<ssize_t> start, std::optional<ssize_t> stop, std::optional<ssize_t> step)
: slice(index_to_object(start), index_to_object(stop), index_to_object(step)) {}
#else
slice(ssize_t start_, ssize_t stop_, ssize_t step_)
: slice(int_(start_), int_(stop_), int_(step_)) {}
#endif
bool
compute(size_t length, size_t *start, size_t *stop, size_t *step, size_t *slicelength) const {
return PySlice_GetIndicesEx((PYBIND11_SLICE_OBJECT *) m_ptr,
(ssize_t) length,
(ssize_t *) start,
(ssize_t *) stop,
(ssize_t *) step,
(ssize_t *) slicelength)
== 0;
}
bool compute(
ssize_t length, ssize_t *start, ssize_t *stop, ssize_t *step, ssize_t *slicelength) const {
return PySlice_GetIndicesEx(
(PYBIND11_SLICE_OBJECT *) m_ptr, length, start, stop, step, slicelength)
== 0;
}
private:
template <typename T>
static object index_to_object(T index) {
return index ? object(int_(*index)) : object(none());
}
};
class capsule : public object {
public:
PYBIND11_OBJECT_DEFAULT(capsule, object, PyCapsule_CheckExact)
PYBIND11_DEPRECATED("Use reinterpret_borrow<capsule>() or reinterpret_steal<capsule>()")
capsule(PyObject *ptr, bool is_borrowed)
: object(is_borrowed ? object(ptr, borrowed_t{}) : object(ptr, stolen_t{})) {}
explicit capsule(const void *value,
const char *name = nullptr,
PyCapsule_Destructor destructor = nullptr)
: object(PyCapsule_New(const_cast<void *>(value), name, destructor), stolen_t{}) {
if (!m_ptr) {
throw error_already_set();
}
}
PYBIND11_DEPRECATED("Please use the ctor with value, name, destructor args")
capsule(const void *value, PyCapsule_Destructor destructor)
: object(PyCapsule_New(const_cast<void *>(value), nullptr, destructor), stolen_t{}) {
if (!m_ptr) {
throw error_already_set();
}
}
/// Capsule name is nullptr.
capsule(const void *value, void (*destructor)(void *)) {
initialize_with_void_ptr_destructor(value, nullptr, destructor);
}
capsule(const void *value, const char *name, void (*destructor)(void *)) {
initialize_with_void_ptr_destructor(value, name, destructor);
}
explicit capsule(void (*destructor)()) {
m_ptr = PyCapsule_New(reinterpret_cast<void *>(destructor), nullptr, [](PyObject *o) {
const char *name = get_name_in_error_scope(o);
auto destructor = reinterpret_cast<void (*)()>(PyCapsule_GetPointer(o, name));
if (destructor == nullptr) {
throw error_already_set();
}
destructor();
});
if (!m_ptr) {
throw error_already_set();
}
}
template <typename T>
operator T *() const { // NOLINT(google-explicit-constructor)
return get_pointer<T>();
}
/// Get the pointer the capsule holds.
template <typename T = void>
T *get_pointer() const {
const auto *name = this->name();
T *result = static_cast<T *>(PyCapsule_GetPointer(m_ptr, name));
if (!result) {
throw error_already_set();
}
return result;
}
/// Replaces a capsule's pointer *without* calling the destructor on the existing one.
void set_pointer(const void *value) {
if (PyCapsule_SetPointer(m_ptr, const_cast<void *>(value)) != 0) {
throw error_already_set();
}
}
const char *name() const {
const char *name = PyCapsule_GetName(m_ptr);
if ((name == nullptr) && PyErr_Occurred()) {
throw error_already_set();
}
return name;
}
/// Replaces a capsule's name *without* calling the destructor on the existing one.
void set_name(const char *new_name) {
if (PyCapsule_SetName(m_ptr, new_name) != 0) {
throw error_already_set();
}
}
private:
static const char *get_name_in_error_scope(PyObject *o) {
error_scope error_guard;
const char *name = PyCapsule_GetName(o);
if ((name == nullptr) && PyErr_Occurred()) {
// write out and consume error raised by call to PyCapsule_GetName
PyErr_WriteUnraisable(o);
}
return name;
}
void initialize_with_void_ptr_destructor(const void *value,
const char *name,
void (*destructor)(void *)) {
m_ptr = PyCapsule_New(const_cast<void *>(value), name, [](PyObject *o) {
// guard if destructor called while err indicator is set
error_scope error_guard;
auto destructor = reinterpret_cast<void (*)(void *)>(PyCapsule_GetContext(o));
if (destructor == nullptr && PyErr_Occurred()) {
throw error_already_set();
}
const char *name = get_name_in_error_scope(o);
void *ptr = PyCapsule_GetPointer(o, name);
if (ptr == nullptr) {
throw error_already_set();
}
if (destructor != nullptr) {
destructor(ptr);
}
});
if (!m_ptr || PyCapsule_SetContext(m_ptr, reinterpret_cast<void *>(destructor)) != 0) {
throw error_already_set();
}
}
};
class tuple : public object {
public:
PYBIND11_OBJECT_CVT(tuple, object, PyTuple_Check, PySequence_Tuple)
template <typename SzType = ssize_t,
detail::enable_if_t<std::is_integral<SzType>::value, int> = 0>
// Some compilers generate link errors when using `const SzType &` here:
explicit tuple(SzType size = 0) : object(PyTuple_New(ssize_t_cast(size)), stolen_t{}) {
if (!m_ptr) {
pybind11_fail("Could not allocate tuple object!");
}
}
size_t size() const { return (size_t) PyTuple_Size(m_ptr); }
bool empty() const { return size() == 0; }
detail::tuple_accessor operator[](size_t index) const { return {*this, index}; }
template <typename T, detail::enable_if_t<detail::is_pyobject<T>::value, int> = 0>
detail::item_accessor operator[](T &&o) const {
return object::operator[](std::forward<T>(o));
}
detail::tuple_iterator begin() const { return {*this, 0}; }
detail::tuple_iterator end() const { return {*this, PyTuple_GET_SIZE(m_ptr)}; }
};
// We need to put this into a separate function because the Intel compiler
// fails to compile enable_if_t<all_of<is_keyword_or_ds<Args>...>::value> part below
// (tested with ICC 2021.1 Beta 20200827).
template <typename... Args>
constexpr bool args_are_all_keyword_or_ds() {
return detail::all_of<detail::is_keyword_or_ds<Args>...>::value;
}
class dict : public object {
public:
PYBIND11_OBJECT_CVT(dict, object, PyDict_Check, raw_dict)
dict() : object(PyDict_New(), stolen_t{}) {
if (!m_ptr) {
pybind11_fail("Could not allocate dict object!");
}
}
template <typename... Args,
typename = detail::enable_if_t<args_are_all_keyword_or_ds<Args...>()>,
// MSVC workaround: it can't compile an out-of-line definition, so defer the
// collector
typename collector = detail::deferred_t<detail::unpacking_collector<>, Args...>>
explicit dict(Args &&...args) : dict(collector(std::forward<Args>(args)...).kwargs()) {}
size_t size() const { return (size_t) PyDict_Size(m_ptr); }
bool empty() const { return size() == 0; }
detail::dict_iterator begin() const { return {*this, 0}; }
detail::dict_iterator end() const { return {}; }
void clear() /* py-non-const */ { PyDict_Clear(ptr()); }
template <typename T>
bool contains(T &&key) const {
auto result = PyDict_Contains(m_ptr, detail::object_or_cast(std::forward<T>(key)).ptr());
if (result == -1) {
throw error_already_set();
}
return result == 1;
}
private:
/// Call the `dict` Python type -- always returns a new reference
static PyObject *raw_dict(PyObject *op) {
if (PyDict_Check(op)) {
return handle(op).inc_ref().ptr();
}
return PyObject_CallFunctionObjArgs((PyObject *) &PyDict_Type, op, nullptr);
}
};
class sequence : public object {
public:
PYBIND11_OBJECT_DEFAULT(sequence, object, PySequence_Check)
size_t size() const {
ssize_t result = PySequence_Size(m_ptr);
if (result == -1) {
throw error_already_set();
}
return (size_t) result;
}
bool empty() const { return size() == 0; }
detail::sequence_accessor operator[](size_t index) const { return {*this, index}; }
template <typename T, detail::enable_if_t<detail::is_pyobject<T>::value, int> = 0>
detail::item_accessor operator[](T &&o) const {
return object::operator[](std::forward<T>(o));
}
detail::sequence_iterator begin() const { return {*this, 0}; }
detail::sequence_iterator end() const { return {*this, PySequence_Size(m_ptr)}; }
};
class list : public object {
public:
PYBIND11_OBJECT_CVT(list, object, PyList_Check, PySequence_List)
template <typename SzType = ssize_t,
detail::enable_if_t<std::is_integral<SzType>::value, int> = 0>
// Some compilers generate link errors when using `const SzType &` here:
explicit list(SzType size = 0) : object(PyList_New(ssize_t_cast(size)), stolen_t{}) {
if (!m_ptr) {
pybind11_fail("Could not allocate list object!");
}
}
size_t size() const { return (size_t) PyList_Size(m_ptr); }
bool empty() const { return size() == 0; }
detail::list_accessor operator[](size_t index) const { return {*this, index}; }
template <typename T, detail::enable_if_t<detail::is_pyobject<T>::value, int> = 0>
detail::item_accessor operator[](T &&o) const {
return object::operator[](std::forward<T>(o));
}
detail::list_iterator begin() const { return {*this, 0}; }
detail::list_iterator end() const { return {*this, PyList_GET_SIZE(m_ptr)}; }
template <typename T>
void append(T &&val) /* py-non-const */ {
if (PyList_Append(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr()) != 0) {
throw error_already_set();
}
}
template <typename IdxType,
typename ValType,
detail::enable_if_t<std::is_integral<IdxType>::value, int> = 0>
void insert(const IdxType &index, ValType &&val) /* py-non-const */ {
if (PyList_Insert(m_ptr,
ssize_t_cast(index),
detail::object_or_cast(std::forward<ValType>(val)).ptr())
!= 0) {
throw error_already_set();
}
}
};
class args : public tuple {
PYBIND11_OBJECT_DEFAULT(args, tuple, PyTuple_Check)
};
class kwargs : public dict {
PYBIND11_OBJECT_DEFAULT(kwargs, dict, PyDict_Check)
};
class anyset : public object {
public:
PYBIND11_OBJECT(anyset, object, PyAnySet_Check)
size_t size() const { return static_cast<size_t>(PySet_Size(m_ptr)); }
bool empty() const { return size() == 0; }
template <typename T>
bool contains(T &&val) const {
auto result = PySet_Contains(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr());
if (result == -1) {
throw error_already_set();
}
return result == 1;
}
};
class set : public anyset {
public:
PYBIND11_OBJECT_CVT(set, anyset, PySet_Check, PySet_New)
set() : anyset(PySet_New(nullptr), stolen_t{}) {
if (!m_ptr) {
pybind11_fail("Could not allocate set object!");
}
}
template <typename T>
bool add(T &&val) /* py-non-const */ {
return PySet_Add(m_ptr, detail::object_or_cast(std::forward<T>(val)).ptr()) == 0;
}
void clear() /* py-non-const */ { PySet_Clear(m_ptr); }
};
class frozenset : public anyset {
public:
PYBIND11_OBJECT_CVT(frozenset, anyset, PyFrozenSet_Check, PyFrozenSet_New)
};
class function : public object {
public:
PYBIND11_OBJECT_DEFAULT(function, object, PyCallable_Check)
handle cpp_function() const {
handle fun = detail::get_function(m_ptr);
if (fun && PyCFunction_Check(fun.ptr())) {
return fun;
}
return handle();
}
bool is_cpp_function() const { return (bool) cpp_function(); }
};
class staticmethod : public object {
public:
PYBIND11_OBJECT_CVT(staticmethod, object, detail::PyStaticMethod_Check, PyStaticMethod_New)
};
class buffer : public object {
public:
PYBIND11_OBJECT_DEFAULT(buffer, object, PyObject_CheckBuffer)
buffer_info request(bool writable = false) const {
int flags = PyBUF_STRIDES | PyBUF_FORMAT;
if (writable) {
flags |= PyBUF_WRITABLE;
}
auto *view = new Py_buffer();
if (PyObject_GetBuffer(m_ptr, view, flags) != 0) {
delete view;
throw error_already_set();
}
return buffer_info(view);
}
};
class memoryview : public object {
public:
PYBIND11_OBJECT_CVT(memoryview, object, PyMemoryView_Check, PyMemoryView_FromObject)
/** \rst
Creates ``memoryview`` from ``buffer_info``.
``buffer_info`` must be created from ``buffer::request()``. Otherwise
throws an exception.
For creating a ``memoryview`` from objects that support buffer protocol,
use ``memoryview(const object& obj)`` instead of this constructor.
\endrst */
explicit memoryview(const buffer_info &info) {
if (!info.view()) {
pybind11_fail("Prohibited to create memoryview without Py_buffer");
}
// Note: PyMemoryView_FromBuffer never increments obj reference.
m_ptr = (info.view()->obj) ? PyMemoryView_FromObject(info.view()->obj)
: PyMemoryView_FromBuffer(info.view());
if (!m_ptr) {
pybind11_fail("Unable to create memoryview from buffer descriptor");
}
}
/** \rst
Creates ``memoryview`` from static buffer.
This method is meant for providing a ``memoryview`` for C/C++ buffer not
managed by Python. The caller is responsible for managing the lifetime
of ``ptr`` and ``format``, which MUST outlive the memoryview constructed
here.
See also: Python C API documentation for `PyMemoryView_FromBuffer`_.
.. _PyMemoryView_FromBuffer:
https://docs.python.org/c-api/memoryview.html#c.PyMemoryView_FromBuffer
:param ptr: Pointer to the buffer.
:param itemsize: Byte size of an element.
:param format: Pointer to the null-terminated format string. For
homogeneous Buffers, this should be set to
``format_descriptor<T>::value``.
:param shape: Shape of the tensor (1 entry per dimension).
:param strides: Number of bytes between adjacent entries (for each
per dimension).
:param readonly: Flag to indicate if the underlying storage may be
written to.
\endrst */
static memoryview from_buffer(void *ptr,
ssize_t itemsize,
const char *format,
detail::any_container<ssize_t> shape,
detail::any_container<ssize_t> strides,
bool readonly = false);
static memoryview from_buffer(const void *ptr,
ssize_t itemsize,
const char *format,
detail::any_container<ssize_t> shape,
detail::any_container<ssize_t> strides) {
return memoryview::from_buffer(
const_cast<void *>(ptr), itemsize, format, std::move(shape), std::move(strides), true);
}
template <typename T>
static memoryview from_buffer(T *ptr,
detail::any_container<ssize_t> shape,
detail::any_container<ssize_t> strides,
bool readonly = false) {
return memoryview::from_buffer(reinterpret_cast<void *>(ptr),
sizeof(T),
format_descriptor<T>::value,
std::move(shape),
std::move(strides),
readonly);
}
template <typename T>
static memoryview from_buffer(const T *ptr,
detail::any_container<ssize_t> shape,
detail::any_container<ssize_t> strides) {
return memoryview::from_buffer(
const_cast<T *>(ptr), std::move(shape), std::move(strides), true);
}
/** \rst
Creates ``memoryview`` from static memory.
This method is meant for providing a ``memoryview`` for C/C++ buffer not
managed by Python. The caller is responsible for managing the lifetime
of ``mem``, which MUST outlive the memoryview constructed here.
See also: Python C API documentation for `PyMemoryView_FromBuffer`_.
.. _PyMemoryView_FromMemory:
https://docs.python.org/c-api/memoryview.html#c.PyMemoryView_FromMemory
\endrst */
static memoryview from_memory(void *mem, ssize_t size, bool readonly = false) {
PyObject *ptr = PyMemoryView_FromMemory(
reinterpret_cast<char *>(mem), size, (readonly) ? PyBUF_READ : PyBUF_WRITE);
if (!ptr) {
pybind11_fail("Could not allocate memoryview object!");
}
return memoryview(object(ptr, stolen_t{}));
}
static memoryview from_memory(const void *mem, ssize_t size) {
return memoryview::from_memory(const_cast<void *>(mem), size, true);
}
#ifdef PYBIND11_HAS_STRING_VIEW
static memoryview from_memory(std::string_view mem) {
return from_memory(const_cast<char *>(mem.data()), static_cast<ssize_t>(mem.size()), true);
}
#endif
};
/// @cond DUPLICATE
inline memoryview memoryview::from_buffer(void *ptr,
ssize_t itemsize,
const char *format,
detail::any_container<ssize_t> shape,
detail::any_container<ssize_t> strides,
bool readonly) {
size_t ndim = shape->size();
if (ndim != strides->size()) {
pybind11_fail("memoryview: shape length doesn't match strides length");
}
ssize_t size = ndim != 0u ? 1 : 0;
for (size_t i = 0; i < ndim; ++i) {
size *= (*shape)[i];
}
Py_buffer view;
view.buf = ptr;
view.obj = nullptr;
view.len = size * itemsize;
view.readonly = static_cast<int>(readonly);
view.itemsize = itemsize;
view.format = const_cast<char *>(format);
view.ndim = static_cast<int>(ndim);
view.shape = shape->data();
view.strides = strides->data();
view.suboffsets = nullptr;
view.internal = nullptr;
PyObject *obj = PyMemoryView_FromBuffer(&view);
if (!obj) {
throw error_already_set();
}
return memoryview(object(obj, stolen_t{}));
}
/// @endcond
/// @} pytypes
/// \addtogroup python_builtins
/// @{
/// Get the length of a Python object.
inline size_t len(handle h) {
ssize_t result = PyObject_Length(h.ptr());
if (result < 0) {
throw error_already_set();
}
return (size_t) result;
}
/// Get the length hint of a Python object.
/// Returns 0 when this cannot be determined.
inline size_t len_hint(handle h) {
ssize_t result = PyObject_LengthHint(h.ptr(), 0);
if (result < 0) {
// Sometimes a length can't be determined at all (eg generators)
// In which case simply return 0
PyErr_Clear();
return 0;
}
return (size_t) result;
}
inline str repr(handle h) {
PyObject *str_value = PyObject_Repr(h.ptr());
if (!str_value) {
throw error_already_set();
}
return reinterpret_steal<str>(str_value);
}
inline iterator iter(handle obj) {
PyObject *result = PyObject_GetIter(obj.ptr());
if (!result) {
throw error_already_set();
}
return reinterpret_steal<iterator>(result);
}
/// @} python_builtins
PYBIND11_NAMESPACE_BEGIN(detail)
template <typename D>
iterator object_api<D>::begin() const {
return iter(derived());
}
template <typename D>
iterator object_api<D>::end() const {
return iterator::sentinel();
}
template <typename D>
item_accessor object_api<D>::operator[](handle key) const {
return {derived(), reinterpret_borrow<object>(key)};
}
template <typename D>
item_accessor object_api<D>::operator[](object &&key) const {
return {derived(), std::move(key)};
}
template <typename D>
item_accessor object_api<D>::operator[](const char *key) const {
return {derived(), pybind11::str(key)};
}
template <typename D>
obj_attr_accessor object_api<D>::attr(handle key) const {
return {derived(), reinterpret_borrow<object>(key)};
}
template <typename D>
obj_attr_accessor object_api<D>::attr(object &&key) const {
return {derived(), std::move(key)};
}
template <typename D>
str_attr_accessor object_api<D>::attr(const char *key) const {
return {derived(), key};
}
template <typename D>
args_proxy object_api<D>::operator*() const {
return args_proxy(derived().ptr());
}
template <typename D>
template <typename T>
bool object_api<D>::contains(T &&item) const {
return attr("__contains__")(std::forward<T>(item)).template cast<bool>();
}
template <typename D>
pybind11::str object_api<D>::str() const {
return pybind11::str(derived());
}
template <typename D>
str_attr_accessor object_api<D>::doc() const {
return attr("__doc__");
}
template <typename D>
handle object_api<D>::get_type() const {
return type::handle_of(derived());
}
template <typename D>
bool object_api<D>::rich_compare(object_api const &other, int value) const {
int rv = PyObject_RichCompareBool(derived().ptr(), other.derived().ptr(), value);
if (rv == -1) {
throw error_already_set();
}
return rv == 1;
}
#define PYBIND11_MATH_OPERATOR_UNARY(op, fn) \
template <typename D> \
object object_api<D>::op() const { \
object result = reinterpret_steal<object>(fn(derived().ptr())); \
if (!result.ptr()) \
throw error_already_set(); \
return result; \
}
#define PYBIND11_MATH_OPERATOR_BINARY(op, fn) \
template <typename D> \
object object_api<D>::op(object_api const &other) const { \
object result = reinterpret_steal<object>(fn(derived().ptr(), other.derived().ptr())); \
if (!result.ptr()) \
throw error_already_set(); \
return result; \
}
#define PYBIND11_MATH_OPERATOR_BINARY_INPLACE(iop, fn) \
template <typename D> \
object object_api<D>::iop(object_api const &other) { \
object result = reinterpret_steal<object>(fn(derived().ptr(), other.derived().ptr())); \
if (!result.ptr()) \
throw error_already_set(); \
return result; \
}
PYBIND11_MATH_OPERATOR_UNARY(operator~, PyNumber_Invert)
PYBIND11_MATH_OPERATOR_UNARY(operator-, PyNumber_Negative)
PYBIND11_MATH_OPERATOR_BINARY(operator+, PyNumber_Add)
PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator+=, PyNumber_InPlaceAdd)
PYBIND11_MATH_OPERATOR_BINARY(operator-, PyNumber_Subtract)
PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator-=, PyNumber_InPlaceSubtract)
PYBIND11_MATH_OPERATOR_BINARY(operator*, PyNumber_Multiply)
PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator*=, PyNumber_InPlaceMultiply)
PYBIND11_MATH_OPERATOR_BINARY(operator/, PyNumber_TrueDivide)
PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator/=, PyNumber_InPlaceTrueDivide)
PYBIND11_MATH_OPERATOR_BINARY(operator|, PyNumber_Or)
PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator|=, PyNumber_InPlaceOr)
PYBIND11_MATH_OPERATOR_BINARY(operator&, PyNumber_And)
PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator&=, PyNumber_InPlaceAnd)
PYBIND11_MATH_OPERATOR_BINARY(operator^, PyNumber_Xor)
PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator^=, PyNumber_InPlaceXor)
PYBIND11_MATH_OPERATOR_BINARY(operator<<, PyNumber_Lshift)
PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator<<=, PyNumber_InPlaceLshift)
PYBIND11_MATH_OPERATOR_BINARY(operator>>, PyNumber_Rshift)
PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator>>=, PyNumber_InPlaceRshift)
#undef PYBIND11_MATH_OPERATOR_UNARY
#undef PYBIND11_MATH_OPERATOR_BINARY
#undef PYBIND11_MATH_OPERATOR_BINARY_INPLACE
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
/*
pybind11/stl.h: Transparent conversion for STL data types
Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.
*/
#pragma once
#include "pybind11.h"
#include "detail/common.h"
#include <deque>
#include <list>
#include <map>
#include <ostream>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
// See `detail/common.h` for implementation of these guards.
#if defined(PYBIND11_HAS_OPTIONAL)
# include <optional>
#elif defined(PYBIND11_HAS_EXP_OPTIONAL)
# include <experimental/optional>
#endif
#if defined(PYBIND11_HAS_VARIANT)
# include <variant>
#endif
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(detail)
/// Extracts an const lvalue reference or rvalue reference for U based on the type of T (e.g. for
/// forwarding a container element). Typically used indirect via forwarded_type(), below.
template <typename T, typename U>
using forwarded_type = conditional_t<std::is_lvalue_reference<T>::value,
remove_reference_t<U> &,
remove_reference_t<U> &&>;
/// Forwards a value U as rvalue or lvalue according to whether T is rvalue or lvalue; typically
/// used for forwarding a container's elements.
template <typename T, typename U>
constexpr forwarded_type<T, U> forward_like(U &&u) {
return std::forward<detail::forwarded_type<T, U>>(std::forward<U>(u));
}
// Checks if a container has a STL style reserve method.
// This will only return true for a `reserve()` with a `void` return.
template <typename C>
using has_reserve_method = std::is_same<decltype(std::declval<C>().reserve(0)), void>;
template <typename Type, typename Key>
struct set_caster {
using type = Type;
using key_conv = make_caster<Key>;
private:
template <typename T = Type, enable_if_t<has_reserve_method<T>::value, int> = 0>
void reserve_maybe(const anyset &s, Type *) {
value.reserve(s.size());
}
void reserve_maybe(const anyset &, void *) {}
public:
bool load(handle src, bool convert) {
if (!isinstance<anyset>(src)) {
return false;
}
auto s = reinterpret_borrow<anyset>(src);
value.clear();
reserve_maybe(s, &value);
for (auto entry : s) {
key_conv conv;
if (!conv.load(entry, convert)) {
return false;
}
value.insert(cast_op<Key &&>(std::move(conv)));
}
return true;
}
template <typename T>
static handle cast(T &&src, return_value_policy policy, handle parent) {
if (!std::is_lvalue_reference<T>::value) {
policy = return_value_policy_override<Key>::policy(policy);
}
pybind11::set s;
for (auto &&value : src) {
auto value_ = reinterpret_steal<object>(
key_conv::cast(detail::forward_like<T>(value), policy, parent));
if (!value_ || !s.add(std::move(value_))) {
return handle();
}
}
return s.release();
}
PYBIND11_TYPE_CASTER(type, const_name("Set[") + key_conv::name + const_name("]"));
};
template <typename Type, typename Key, typename Value>
struct map_caster {
using key_conv = make_caster<Key>;
using value_conv = make_caster<Value>;
private:
template <typename T = Type, enable_if_t<has_reserve_method<T>::value, int> = 0>
void reserve_maybe(const dict &d, Type *) {
value.reserve(d.size());
}
void reserve_maybe(const dict &, void *) {}
public:
bool load(handle src, bool convert) {
if (!isinstance<dict>(src)) {
return false;
}
auto d = reinterpret_borrow<dict>(src);
value.clear();
reserve_maybe(d, &value);
for (auto it : d) {
key_conv kconv;
value_conv vconv;
if (!kconv.load(it.first.ptr(), convert) || !vconv.load(it.second.ptr(), convert)) {
return false;
}
value.emplace(cast_op<Key &&>(std::move(kconv)), cast_op<Value &&>(std::move(vconv)));
}
return true;
}
template <typename T>
static handle cast(T &&src, return_value_policy policy, handle parent) {
dict d;
return_value_policy policy_key = policy;
return_value_policy policy_value = policy;
if (!std::is_lvalue_reference<T>::value) {
policy_key = return_value_policy_override<Key>::policy(policy_key);
policy_value = return_value_policy_override<Value>::policy(policy_value);
}
for (auto &&kv : src) {
auto key = reinterpret_steal<object>(
key_conv::cast(detail::forward_like<T>(kv.first), policy_key, parent));
auto value = reinterpret_steal<object>(
value_conv::cast(detail::forward_like<T>(kv.second), policy_value, parent));
if (!key || !value) {
return handle();
}
d[std::move(key)] = std::move(value);
}
return d.release();
}
PYBIND11_TYPE_CASTER(Type,
const_name("Dict[") + key_conv::name + const_name(", ") + value_conv::name
+ const_name("]"));
};
template <typename Type, typename Value>
struct list_caster {
using value_conv = make_caster<Value>;
bool load(handle src, bool convert) {
if (!isinstance<sequence>(src) || isinstance<bytes>(src) || isinstance<str>(src)) {
return false;
}
auto s = reinterpret_borrow<sequence>(src);
value.clear();
reserve_maybe(s, &value);
for (auto it : s) {
value_conv conv;
if (!conv.load(it, convert)) {
return false;
}
value.push_back(cast_op<Value &&>(std::move(conv)));
}
return true;
}
private:
template <typename T = Type, enable_if_t<has_reserve_method<T>::value, int> = 0>
void reserve_maybe(const sequence &s, Type *) {
value.reserve(s.size());
}
void reserve_maybe(const sequence &, void *) {}
public:
template <typename T>
static handle cast(T &&src, return_value_policy policy, handle parent) {
if (!std::is_lvalue_reference<T>::value) {
policy = return_value_policy_override<Value>::policy(policy);
}
list l(src.size());
ssize_t index = 0;
for (auto &&value : src) {
auto value_ = reinterpret_steal<object>(
value_conv::cast(detail::forward_like<T>(value), policy, parent));
if (!value_) {
return handle();
}
PyList_SET_ITEM(l.ptr(), index++, value_.release().ptr()); // steals a reference
}
return l.release();
}
PYBIND11_TYPE_CASTER(Type, const_name("List[") + value_conv::name + const_name("]"));
};
template <typename Type, typename Alloc>
struct type_caster<std::vector<Type, Alloc>> : list_caster<std::vector<Type, Alloc>, Type> {};
template <typename Type, typename Alloc>
struct type_caster<std::deque<Type, Alloc>> : list_caster<std::deque<Type, Alloc>, Type> {};
template <typename Type, typename Alloc>
struct type_caster<std::list<Type, Alloc>> : list_caster<std::list<Type, Alloc>, Type> {};
template <typename ArrayType, typename Value, bool Resizable, size_t Size = 0>
struct array_caster {
using value_conv = make_caster<Value>;
private:
template <bool R = Resizable>
bool require_size(enable_if_t<R, size_t> size) {
if (value.size() != size) {
value.resize(size);
}
return true;
}
template <bool R = Resizable>
bool require_size(enable_if_t<!R, size_t> size) {
return size == Size;
}
public:
bool load(handle src, bool convert) {
if (!isinstance<sequence>(src)) {
return false;
}
auto l = reinterpret_borrow<sequence>(src);
if (!require_size(l.size())) {
return false;
}
size_t ctr = 0;
for (auto it : l) {
value_conv conv;
if (!conv.load(it, convert)) {
return false;
}
value[ctr++] = cast_op<Value &&>(std::move(conv));
}
return true;
}
template <typename T>
static handle cast(T &&src, return_value_policy policy, handle parent) {
list l(src.size());
ssize_t index = 0;
for (auto &&value : src) {
auto value_ = reinterpret_steal<object>(
value_conv::cast(detail::forward_like<T>(value), policy, parent));
if (!value_) {
return handle();
}
PyList_SET_ITEM(l.ptr(), index++, value_.release().ptr()); // steals a reference
}
return l.release();
}
PYBIND11_TYPE_CASTER(ArrayType,
const_name<Resizable>(const_name(""), const_name("Annotated["))
+ const_name("List[") + value_conv::name + const_name("]")
+ const_name<Resizable>(const_name(""),
const_name(", FixedSize(")
+ const_name<Size>() + const_name(")]")));
};
template <typename Type, size_t Size>
struct type_caster<std::array<Type, Size>>
: array_caster<std::array<Type, Size>, Type, false, Size> {};
template <typename Type>
struct type_caster<std::valarray<Type>> : array_caster<std::valarray<Type>, Type, true> {};
template <typename Key, typename Compare, typename Alloc>
struct type_caster<std::set<Key, Compare, Alloc>>
: set_caster<std::set<Key, Compare, Alloc>, Key> {};
template <typename Key, typename Hash, typename Equal, typename Alloc>
struct type_caster<std::unordered_set<Key, Hash, Equal, Alloc>>
: set_caster<std::unordered_set<Key, Hash, Equal, Alloc>, Key> {};
template <typename Key, typename Value, typename Compare, typename Alloc>
struct type_caster<std::map<Key, Value, Compare, Alloc>>
: map_caster<std::map<Key, Value, Compare, Alloc>, Key, Value> {};
template <typename Key, typename Value, typename Hash, typename Equal, typename Alloc>
struct type_caster<std::unordered_map<Key, Value, Hash, Equal, Alloc>>
: map_caster<std::unordered_map<Key, Value, Hash, Equal, Alloc>, Key, Value> {};
// This type caster is intended to be used for std::optional and std::experimental::optional
template <typename Type, typename Value = typename Type::value_type>
struct optional_caster {
using value_conv = make_caster<Value>;
template <typename T>
static handle cast(T &&src, return_value_policy policy, handle parent) {
if (!src) {
return none().release();
}
if (!std::is_lvalue_reference<T>::value) {
policy = return_value_policy_override<Value>::policy(policy);
}
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
return value_conv::cast(*std::forward<T>(src), policy, parent);
}
bool load(handle src, bool convert) {
if (!src) {
return false;
}
if (src.is_none()) {
return true; // default-constructed value is already empty
}
value_conv inner_caster;
if (!inner_caster.load(src, convert)) {
return false;
}
value.emplace(cast_op<Value &&>(std::move(inner_caster)));
return true;
}
PYBIND11_TYPE_CASTER(Type, const_name("Optional[") + value_conv::name + const_name("]"));
};
#if defined(PYBIND11_HAS_OPTIONAL)
template <typename T>
struct type_caster<std::optional<T>> : public optional_caster<std::optional<T>> {};
template <>
struct type_caster<std::nullopt_t> : public void_caster<std::nullopt_t> {};
#endif
#if defined(PYBIND11_HAS_EXP_OPTIONAL)
template <typename T>
struct type_caster<std::experimental::optional<T>>
: public optional_caster<std::experimental::optional<T>> {};
template <>
struct type_caster<std::experimental::nullopt_t>
: public void_caster<std::experimental::nullopt_t> {};
#endif
/// Visit a variant and cast any found type to Python
struct variant_caster_visitor {
return_value_policy policy;
handle parent;
using result_type = handle; // required by boost::variant in C++11
template <typename T>
result_type operator()(T &&src) const {
return make_caster<T>::cast(std::forward<T>(src), policy, parent);
}
};
/// Helper class which abstracts away variant's `visit` function. `std::variant` and similar
/// `namespace::variant` types which provide a `namespace::visit()` function are handled here
/// automatically using argument-dependent lookup. Users can provide specializations for other
/// variant-like classes, e.g. `boost::variant` and `boost::apply_visitor`.
template <template <typename...> class Variant>
struct visit_helper {
template <typename... Args>
static auto call(Args &&...args) -> decltype(visit(std::forward<Args>(args)...)) {
return visit(std::forward<Args>(args)...);
}
};
/// Generic variant caster
template <typename Variant>
struct variant_caster;
template <template <typename...> class V, typename... Ts>
struct variant_caster<V<Ts...>> {
static_assert(sizeof...(Ts) > 0, "Variant must consist of at least one alternative.");
template <typename U, typename... Us>
bool load_alternative(handle src, bool convert, type_list<U, Us...>) {
auto caster = make_caster<U>();
if (caster.load(src, convert)) {
value = cast_op<U>(std::move(caster));
return true;
}
return load_alternative(src, convert, type_list<Us...>{});
}
bool load_alternative(handle, bool, type_list<>) { return false; }
bool load(handle src, bool convert) {
// Do a first pass without conversions to improve constructor resolution.
// E.g. `py::int_(1).cast<variant<double, int>>()` needs to fill the `int`
// slot of the variant. Without two-pass loading `double` would be filled
// because it appears first and a conversion is possible.
if (convert && load_alternative(src, false, type_list<Ts...>{})) {
return true;
}
return load_alternative(src, convert, type_list<Ts...>{});
}
template <typename Variant>
static handle cast(Variant &&src, return_value_policy policy, handle parent) {
return visit_helper<V>::call(variant_caster_visitor{policy, parent},
std::forward<Variant>(src));
}
using Type = V<Ts...>;
PYBIND11_TYPE_CASTER(Type,
const_name("Union[") + detail::concat(make_caster<Ts>::name...)
+ const_name("]"));
};
#if defined(PYBIND11_HAS_VARIANT)
template <typename... Ts>
struct type_caster<std::variant<Ts...>> : variant_caster<std::variant<Ts...>> {};
template <>
struct type_caster<std::monostate> : public void_caster<std::monostate> {};
#endif
PYBIND11_NAMESPACE_END(detail)
inline std::ostream &operator<<(std::ostream &os, const handle &obj) {
#ifdef PYBIND11_HAS_STRING_VIEW
os << str(obj).cast<std::string_view>();
#else
os << (std::string) str(obj);
#endif
return os;
}
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
// Copyright (c) 2021 The Pybind Development Team.
// All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#pragma once
#include "../pybind11.h"
#include "../detail/common.h"
#include "../detail/descr.h"
#include "../cast.h"
#include "../pytypes.h"
#include <string>
#ifdef __has_include
# if defined(PYBIND11_CPP17)
# if __has_include(<filesystem>) && \
PY_VERSION_HEX >= 0x03060000
# include <filesystem>
# define PYBIND11_HAS_FILESYSTEM 1
# elif __has_include(<experimental/filesystem>)
# include <experimental/filesystem>
# define PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM 1
# endif
# endif
#endif
#if !defined(PYBIND11_HAS_FILESYSTEM) && !defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM) \
&& !defined(PYBIND11_HAS_FILESYSTEM_IS_OPTIONAL)
# error \
"Neither #include <filesystem> nor #include <experimental/filesystem is available. (Use -DPYBIND11_HAS_FILESYSTEM_IS_OPTIONAL to ignore.)"
#endif
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(detail)
#if defined(PYBIND11_HAS_FILESYSTEM) || defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM)
template <typename T>
struct path_caster {
private:
static PyObject *unicode_from_fs_native(const std::string &w) {
# if !defined(PYPY_VERSION)
return PyUnicode_DecodeFSDefaultAndSize(w.c_str(), ssize_t(w.size()));
# else
// PyPy mistakenly declares the first parameter as non-const.
return PyUnicode_DecodeFSDefaultAndSize(const_cast<char *>(w.c_str()), ssize_t(w.size()));
# endif
}
static PyObject *unicode_from_fs_native(const std::wstring &w) {
return PyUnicode_FromWideChar(w.c_str(), ssize_t(w.size()));
}
public:
static handle cast(const T &path, return_value_policy, handle) {
if (auto py_str = unicode_from_fs_native(path.native())) {
return module_::import("pathlib")
.attr("Path")(reinterpret_steal<object>(py_str))
.release();
}
return nullptr;
}
bool load(handle handle, bool) {
// PyUnicode_FSConverter and PyUnicode_FSDecoder normally take care of
// calling PyOS_FSPath themselves, but that's broken on PyPy (PyPy
// issue #3168) so we do it ourselves instead.
PyObject *buf = PyOS_FSPath(handle.ptr());
if (!buf) {
PyErr_Clear();
return false;
}
PyObject *native = nullptr;
if constexpr (std::is_same_v<typename T::value_type, char>) {
if (PyUnicode_FSConverter(buf, &native) != 0) {
if (auto *c_str = PyBytes_AsString(native)) {
// AsString returns a pointer to the internal buffer, which
// must not be free'd.
value = c_str;
}
}
} else if constexpr (std::is_same_v<typename T::value_type, wchar_t>) {
if (PyUnicode_FSDecoder(buf, &native) != 0) {
if (auto *c_str = PyUnicode_AsWideCharString(native, nullptr)) {
// AsWideCharString returns a new string that must be free'd.
value = c_str; // Copies the string.
PyMem_Free(c_str);
}
}
}
Py_XDECREF(native);
Py_DECREF(buf);
if (PyErr_Occurred()) {
PyErr_Clear();
return false;
}
return true;
}
PYBIND11_TYPE_CASTER(T, const_name("os.PathLike"));
};
#endif // PYBIND11_HAS_FILESYSTEM || defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM)
#if defined(PYBIND11_HAS_FILESYSTEM)
template <>
struct type_caster<std::filesystem::path> : public path_caster<std::filesystem::path> {};
#elif defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM)
template <>
struct type_caster<std::experimental::filesystem::path>
: public path_caster<std::experimental::filesystem::path> {};
#endif
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
/*
pybind11/std_bind.h: Binding generators for STL data types
Copyright (c) 2016 Sergey Lyskov and Wenzel Jakob
All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.
*/
#pragma once
#include "detail/common.h"
#include "detail/type_caster_base.h"
#include "cast.h"
#include "operators.h"
#include <algorithm>
#include <sstream>
#include <type_traits>
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(detail)
/* SFINAE helper class used by 'is_comparable */
template <typename T>
struct container_traits {
template <typename T2>
static std::true_type
test_comparable(decltype(std::declval<const T2 &>() == std::declval<const T2 &>()) *);
template <typename T2>
static std::false_type test_comparable(...);
template <typename T2>
static std::true_type test_value(typename T2::value_type *);
template <typename T2>
static std::false_type test_value(...);
template <typename T2>
static std::true_type test_pair(typename T2::first_type *, typename T2::second_type *);
template <typename T2>
static std::false_type test_pair(...);
static constexpr const bool is_comparable
= std::is_same<std::true_type, decltype(test_comparable<T>(nullptr))>::value;
static constexpr const bool is_pair
= std::is_same<std::true_type, decltype(test_pair<T>(nullptr, nullptr))>::value;
static constexpr const bool is_vector
= std::is_same<std::true_type, decltype(test_value<T>(nullptr))>::value;
static constexpr const bool is_element = !is_pair && !is_vector;
};
/* Default: is_comparable -> std::false_type */
template <typename T, typename SFINAE = void>
struct is_comparable : std::false_type {};
/* For non-map data structures, check whether operator== can be instantiated */
template <typename T>
struct is_comparable<
T,
enable_if_t<container_traits<T>::is_element && container_traits<T>::is_comparable>>
: std::true_type {};
/* For a vector/map data structure, recursively check the value type
(which is std::pair for maps) */
template <typename T>
struct is_comparable<T, enable_if_t<container_traits<T>::is_vector>>
: is_comparable<typename recursive_container_traits<T>::type_to_check_recursively> {};
template <>
struct is_comparable<recursive_bottom> : std::true_type {};
/* For pairs, recursively check the two data types */
template <typename T>
struct is_comparable<T, enable_if_t<container_traits<T>::is_pair>> {
static constexpr const bool value = is_comparable<typename T::first_type>::value
&& is_comparable<typename T::second_type>::value;
};
/* Fallback functions */
template <typename, typename, typename... Args>
void vector_if_copy_constructible(const Args &...) {}
template <typename, typename, typename... Args>
void vector_if_equal_operator(const Args &...) {}
template <typename, typename, typename... Args>
void vector_if_insertion_operator(const Args &...) {}
template <typename, typename, typename... Args>
void vector_modifiers(const Args &...) {}
template <typename Vector, typename Class_>
void vector_if_copy_constructible(enable_if_t<is_copy_constructible<Vector>::value, Class_> &cl) {
cl.def(init<const Vector &>(), "Copy constructor");
}
template <typename Vector, typename Class_>
void vector_if_equal_operator(enable_if_t<is_comparable<Vector>::value, Class_> &cl) {
using T = typename Vector::value_type;
cl.def(self == self);
cl.def(self != self);
cl.def(
"count",
[](const Vector &v, const T &x) { return std::count(v.begin(), v.end(), x); },
arg("x"),
"Return the number of times ``x`` appears in the list");
cl.def(
"remove",
[](Vector &v, const T &x) {
auto p = std::find(v.begin(), v.end(), x);
if (p != v.end()) {
v.erase(p);
} else {
throw value_error();
}
},
arg("x"),
"Remove the first item from the list whose value is x. "
"It is an error if there is no such item.");
cl.def(
"__contains__",
[](const Vector &v, const T &x) { return std::find(v.begin(), v.end(), x) != v.end(); },
arg("x"),
"Return true the container contains ``x``");
}
// Vector modifiers -- requires a copyable vector_type:
// (Technically, some of these (pop and __delitem__) don't actually require copyability, but it
// seems silly to allow deletion but not insertion, so include them here too.)
template <typename Vector, typename Class_>
void vector_modifiers(
enable_if_t<is_copy_constructible<typename Vector::value_type>::value, Class_> &cl) {
using T = typename Vector::value_type;
using SizeType = typename Vector::size_type;
using DiffType = typename Vector::difference_type;
auto wrap_i = [](DiffType i, SizeType n) {
if (i < 0) {
i += n;
}
if (i < 0 || (SizeType) i >= n) {
throw index_error();
}
return i;
};
cl.def(
"append",
[](Vector &v, const T &value) { v.push_back(value); },
arg("x"),
"Add an item to the end of the list");
cl.def(init([](const iterable &it) {
auto v = std::unique_ptr<Vector>(new Vector());
v->reserve(len_hint(it));
for (handle h : it) {
v->push_back(h.cast<T>());
}
return v.release();
}));
cl.def(
"clear", [](Vector &v) { v.clear(); }, "Clear the contents");
cl.def(
"extend",
[](Vector &v, const Vector &src) { v.insert(v.end(), src.begin(), src.end()); },
arg("L"),
"Extend the list by appending all the items in the given list");
cl.def(
"extend",
[](Vector &v, const iterable &it) {
const size_t old_size = v.size();
v.reserve(old_size + len_hint(it));
try {
for (handle h : it) {
v.push_back(h.cast<T>());
}
} catch (const cast_error &) {
v.erase(v.begin() + static_cast<typename Vector::difference_type>(old_size),
v.end());
try {
v.shrink_to_fit();
} catch (const std::exception &) {
// Do nothing
}
throw;
}
},
arg("L"),
"Extend the list by appending all the items in the given list");
cl.def(
"insert",
[](Vector &v, DiffType i, const T &x) {
// Can't use wrap_i; i == v.size() is OK
if (i < 0) {
i += v.size();
}
if (i < 0 || (SizeType) i > v.size()) {
throw index_error();
}
v.insert(v.begin() + i, x);
},
arg("i"),
arg("x"),
"Insert an item at a given position.");
cl.def(
"pop",
[](Vector &v) {
if (v.empty()) {
throw index_error();
}
T t = std::move(v.back());
v.pop_back();
return t;
},
"Remove and return the last item");
cl.def(
"pop",
[wrap_i](Vector &v, DiffType i) {
i = wrap_i(i, v.size());
T t = std::move(v[(SizeType) i]);
v.erase(std::next(v.begin(), i));
return t;
},
arg("i"),
"Remove and return the item at index ``i``");
cl.def("__setitem__", [wrap_i](Vector &v, DiffType i, const T &t) {
i = wrap_i(i, v.size());
v[(SizeType) i] = t;
});
/// Slicing protocol
cl.def(
"__getitem__",
[](const Vector &v, const slice &slice) -> Vector * {
size_t start = 0, stop = 0, step = 0, slicelength = 0;
if (!slice.compute(v.size(), &start, &stop, &step, &slicelength)) {
throw error_already_set();
}
auto *seq = new Vector();
seq->reserve((size_t) slicelength);
for (size_t i = 0; i < slicelength; ++i) {
seq->push_back(v[start]);
start += step;
}
return seq;
},
arg("s"),
"Retrieve list elements using a slice object");
cl.def(
"__setitem__",
[](Vector &v, const slice &slice, const Vector &value) {
size_t start = 0, stop = 0, step = 0, slicelength = 0;
if (!slice.compute(v.size(), &start, &stop, &step, &slicelength)) {
throw error_already_set();
}
if (slicelength != value.size()) {
throw std::runtime_error(
"Left and right hand size of slice assignment have different sizes!");
}
for (size_t i = 0; i < slicelength; ++i) {
v[start] = value[i];
start += step;
}
},
"Assign list elements using a slice object");
cl.def(
"__delitem__",
[wrap_i](Vector &v, DiffType i) {
i = wrap_i(i, v.size());
v.erase(v.begin() + i);
},
"Delete the list elements at index ``i``");
cl.def(
"__delitem__",
[](Vector &v, const slice &slice) {
size_t start = 0, stop = 0, step = 0, slicelength = 0;
if (!slice.compute(v.size(), &start, &stop, &step, &slicelength)) {
throw error_already_set();
}
if (step == 1 && false) {
v.erase(v.begin() + (DiffType) start, v.begin() + DiffType(start + slicelength));
} else {
for (size_t i = 0; i < slicelength; ++i) {
v.erase(v.begin() + DiffType(start));
start += step - 1;
}
}
},
"Delete list elements using a slice object");
}
// If the type has an operator[] that doesn't return a reference (most notably std::vector<bool>),
// we have to access by copying; otherwise we return by reference.
template <typename Vector>
using vector_needs_copy
= negation<std::is_same<decltype(std::declval<Vector>()[typename Vector::size_type()]),
typename Vector::value_type &>>;
// The usual case: access and iterate by reference
template <typename Vector, typename Class_>
void vector_accessor(enable_if_t<!vector_needs_copy<Vector>::value, Class_> &cl) {
using T = typename Vector::value_type;
using SizeType = typename Vector::size_type;
using DiffType = typename Vector::difference_type;
using ItType = typename Vector::iterator;
auto wrap_i = [](DiffType i, SizeType n) {
if (i < 0) {
i += n;
}
if (i < 0 || (SizeType) i >= n) {
throw index_error();
}
return i;
};
cl.def(
"__getitem__",
[wrap_i](Vector &v, DiffType i) -> T & {
i = wrap_i(i, v.size());
return v[(SizeType) i];
},
return_value_policy::reference_internal // ref + keepalive
);
cl.def(
"__iter__",
[](Vector &v) {
return make_iterator<return_value_policy::reference_internal, ItType, ItType, T &>(
v.begin(), v.end());
},
keep_alive<0, 1>() /* Essential: keep list alive while iterator exists */
);
}
// The case for special objects, like std::vector<bool>, that have to be returned-by-copy:
template <typename Vector, typename Class_>
void vector_accessor(enable_if_t<vector_needs_copy<Vector>::value, Class_> &cl) {
using T = typename Vector::value_type;
using SizeType = typename Vector::size_type;
using DiffType = typename Vector::difference_type;
using ItType = typename Vector::iterator;
cl.def("__getitem__", [](const Vector &v, DiffType i) -> T {
if (i < 0) {
i += v.size();
if (i < 0) {
throw index_error();
}
}
auto i_st = static_cast<SizeType>(i);
if (i_st >= v.size()) {
throw index_error();
}
return v[i_st];
});
cl.def(
"__iter__",
[](Vector &v) {
return make_iterator<return_value_policy::copy, ItType, ItType, T>(v.begin(), v.end());
},
keep_alive<0, 1>() /* Essential: keep list alive while iterator exists */
);
}
template <typename Vector, typename Class_>
auto vector_if_insertion_operator(Class_ &cl, std::string const &name)
-> decltype(std::declval<std::ostream &>() << std::declval<typename Vector::value_type>(),
void()) {
using size_type = typename Vector::size_type;
cl.def(
"__repr__",
[name](Vector &v) {
std::ostringstream s;
s << name << '[';
for (size_type i = 0; i < v.size(); ++i) {
s << v[i];
if (i != v.size() - 1) {
s << ", ";
}
}
s << ']';
return s.str();
},
"Return the canonical string representation of this list.");
}
// Provide the buffer interface for vectors if we have data() and we have a format for it
// GCC seems to have "void std::vector<bool>::data()" - doing SFINAE on the existence of data()
// is insufficient, we need to check it returns an appropriate pointer
template <typename Vector, typename = void>
struct vector_has_data_and_format : std::false_type {};
template <typename Vector>
struct vector_has_data_and_format<
Vector,
enable_if_t<std::is_same<decltype(format_descriptor<typename Vector::value_type>::format(),
std::declval<Vector>().data()),
typename Vector::value_type *>::value>> : std::true_type {};
// [workaround(intel)] Separate function required here
// Workaround as the Intel compiler does not compile the enable_if_t part below
// (tested with icc (ICC) 2021.1 Beta 20200827)
template <typename... Args>
constexpr bool args_any_are_buffer() {
return detail::any_of<std::is_same<Args, buffer_protocol>...>::value;
}
// [workaround(intel)] Separate function required here
// [workaround(msvc)] Can't use constexpr bool in return type
// Add the buffer interface to a vector
template <typename Vector, typename Class_, typename... Args>
void vector_buffer_impl(Class_ &cl, std::true_type) {
using T = typename Vector::value_type;
static_assert(vector_has_data_and_format<Vector>::value,
"There is not an appropriate format descriptor for this vector");
// numpy.h declares this for arbitrary types, but it may raise an exception and crash hard
// at runtime if PYBIND11_NUMPY_DTYPE hasn't been called, so check here
format_descriptor<T>::format();
cl.def_buffer([](Vector &v) -> buffer_info {
return buffer_info(v.data(),
static_cast<ssize_t>(sizeof(T)),
format_descriptor<T>::format(),
1,
{v.size()},
{sizeof(T)});
});
cl.def(init([](const buffer &buf) {
auto info = buf.request();
if (info.ndim != 1 || info.strides[0] % static_cast<ssize_t>(sizeof(T))) {
throw type_error("Only valid 1D buffers can be copied to a vector");
}
if (!detail::compare_buffer_info<T>::compare(info)
|| (ssize_t) sizeof(T) != info.itemsize) {
throw type_error("Format mismatch (Python: " + info.format
+ " C++: " + format_descriptor<T>::format() + ")");
}
T *p = static_cast<T *>(info.ptr);
ssize_t step = info.strides[0] / static_cast<ssize_t>(sizeof(T));
T *end = p + info.shape[0] * step;
if (step == 1) {
return Vector(p, end);
}
Vector vec;
vec.reserve((size_t) info.shape[0]);
for (; p != end; p += step) {
vec.push_back(*p);
}
return vec;
}));
return;
}
template <typename Vector, typename Class_, typename... Args>
void vector_buffer_impl(Class_ &, std::false_type) {}
template <typename Vector, typename Class_, typename... Args>
void vector_buffer(Class_ &cl) {
vector_buffer_impl<Vector, Class_, Args...>(
cl, detail::any_of<std::is_same<Args, buffer_protocol>...>{});
}
PYBIND11_NAMESPACE_END(detail)
//
// std::vector
//
template <typename Vector, typename holder_type = std::unique_ptr<Vector>, typename... Args>
class_<Vector, holder_type> bind_vector(handle scope, std::string const &name, Args &&...args) {
using Class_ = class_<Vector, holder_type>;
// If the value_type is unregistered (e.g. a converting type) or is itself registered
// module-local then make the vector binding module-local as well:
using vtype = typename Vector::value_type;
auto *vtype_info = detail::get_type_info(typeid(vtype));
bool local = !vtype_info || vtype_info->module_local;
Class_ cl(scope, name.c_str(), pybind11::module_local(local), std::forward<Args>(args)...);
// Declare the buffer interface if a buffer_protocol() is passed in
detail::vector_buffer<Vector, Class_, Args...>(cl);
cl.def(init<>());
// Register copy constructor (if possible)
detail::vector_if_copy_constructible<Vector, Class_>(cl);
// Register comparison-related operators and functions (if possible)
detail::vector_if_equal_operator<Vector, Class_>(cl);
// Register stream insertion operator (if possible)
detail::vector_if_insertion_operator<Vector, Class_>(cl, name);
// Modifiers require copyable vector value type
detail::vector_modifiers<Vector, Class_>(cl);
// Accessor and iterator; return by value if copyable, otherwise we return by ref + keep-alive
detail::vector_accessor<Vector, Class_>(cl);
cl.def(
"__bool__",
[](const Vector &v) -> bool { return !v.empty(); },
"Check whether the list is nonempty");
cl.def("__len__", &Vector::size);
#if 0
// C++ style functions deprecated, leaving it here as an example
cl.def(init<size_type>());
cl.def("resize",
(void (Vector::*) (size_type count)) & Vector::resize,
"changes the number of elements stored");
cl.def("erase",
[](Vector &v, SizeType i) {
if (i >= v.size())
throw index_error();
v.erase(v.begin() + i);
}, "erases element at index ``i``");
cl.def("empty", &Vector::empty, "checks whether the container is empty");
cl.def("size", &Vector::size, "returns the number of elements");
cl.def("push_back", (void (Vector::*)(const T&)) &Vector::push_back, "adds an element to the end");
cl.def("pop_back", &Vector::pop_back, "removes the last element");
cl.def("max_size", &Vector::max_size, "returns the maximum possible number of elements");
cl.def("reserve", &Vector::reserve, "reserves storage");
cl.def("capacity", &Vector::capacity, "returns the number of elements that can be held in currently allocated storage");
cl.def("shrink_to_fit", &Vector::shrink_to_fit, "reduces memory usage by freeing unused memory");
cl.def("clear", &Vector::clear, "clears the contents");
cl.def("swap", &Vector::swap, "swaps the contents");
cl.def("front", [](Vector &v) {
if (v.size()) return v.front();
else throw index_error();
}, "access the first element");
cl.def("back", [](Vector &v) {
if (v.size()) return v.back();
else throw index_error();
}, "access the last element ");
#endif
return cl;
}
//
// std::map, std::unordered_map
//
PYBIND11_NAMESPACE_BEGIN(detail)
/* Fallback functions */
template <typename, typename, typename... Args>
void map_if_insertion_operator(const Args &...) {}
template <typename, typename, typename... Args>
void map_assignment(const Args &...) {}
// Map assignment when copy-assignable: just copy the value
template <typename Map, typename Class_>
void map_assignment(
enable_if_t<is_copy_assignable<typename Map::mapped_type>::value, Class_> &cl) {
using KeyType = typename Map::key_type;
using MappedType = typename Map::mapped_type;
cl.def("__setitem__", [](Map &m, const KeyType &k, const MappedType &v) {
auto it = m.find(k);
if (it != m.end()) {
it->second = v;
} else {
m.emplace(k, v);
}
});
}
// Not copy-assignable, but still copy-constructible: we can update the value by erasing and
// reinserting
template <typename Map, typename Class_>
void map_assignment(enable_if_t<!is_copy_assignable<typename Map::mapped_type>::value
&& is_copy_constructible<typename Map::mapped_type>::value,
Class_> &cl) {
using KeyType = typename Map::key_type;
using MappedType = typename Map::mapped_type;
cl.def("__setitem__", [](Map &m, const KeyType &k, const MappedType &v) {
// We can't use m[k] = v; because value type might not be default constructable
auto r = m.emplace(k, v);
if (!r.second) {
// value type is not copy assignable so the only way to insert it is to erase it
// first...
m.erase(r.first);
m.emplace(k, v);
}
});
}
template <typename Map, typename Class_>
auto map_if_insertion_operator(Class_ &cl, std::string const &name)
-> decltype(std::declval<std::ostream &>() << std::declval<typename Map::key_type>()
<< std::declval<typename Map::mapped_type>(),
void()) {
cl.def(
"__repr__",
[name](Map &m) {
std::ostringstream s;
s << name << '{';
bool f = false;
for (auto const &kv : m) {
if (f) {
s << ", ";
}
s << kv.first << ": " << kv.second;
f = true;
}
s << '}';
return s.str();
},
"Return the canonical string representation of this map.");
}
template <typename KeyType>
struct keys_view {
virtual size_t len() = 0;
virtual iterator iter() = 0;
virtual bool contains(const KeyType &k) = 0;
virtual bool contains(const object &k) = 0;
virtual ~keys_view() = default;
};
template <typename MappedType>
struct values_view {
virtual size_t len() = 0;
virtual iterator iter() = 0;
virtual ~values_view() = default;
};
template <typename KeyType, typename MappedType>
struct items_view {
virtual size_t len() = 0;
virtual iterator iter() = 0;
virtual ~items_view() = default;
};
template <typename Map, typename KeysView>
struct KeysViewImpl : public KeysView {
explicit KeysViewImpl(Map &map) : map(map) {}
size_t len() override { return map.size(); }
iterator iter() override { return make_key_iterator(map.begin(), map.end()); }
bool contains(const typename Map::key_type &k) override { return map.find(k) != map.end(); }
bool contains(const object &) override { return false; }
Map &map;
};
template <typename Map, typename ValuesView>
struct ValuesViewImpl : public ValuesView {
explicit ValuesViewImpl(Map &map) : map(map) {}
size_t len() override { return map.size(); }
iterator iter() override { return make_value_iterator(map.begin(), map.end()); }
Map &map;
};
template <typename Map, typename ItemsView>
struct ItemsViewImpl : public ItemsView {
explicit ItemsViewImpl(Map &map) : map(map) {}
size_t len() override { return map.size(); }
iterator iter() override { return make_iterator(map.begin(), map.end()); }
Map &map;
};
PYBIND11_NAMESPACE_END(detail)
template <typename Map, typename holder_type = std::unique_ptr<Map>, typename... Args>
class_<Map, holder_type> bind_map(handle scope, const std::string &name, Args &&...args) {
using KeyType = typename Map::key_type;
using MappedType = typename Map::mapped_type;
using StrippedKeyType = detail::remove_cvref_t<KeyType>;
using StrippedMappedType = detail::remove_cvref_t<MappedType>;
using KeysView = detail::keys_view<StrippedKeyType>;
using ValuesView = detail::values_view<StrippedMappedType>;
using ItemsView = detail::items_view<StrippedKeyType, StrippedMappedType>;
using Class_ = class_<Map, holder_type>;
// If either type is a non-module-local bound type then make the map binding non-local as well;
// otherwise (e.g. both types are either module-local or converting) the map will be
// module-local.
auto *tinfo = detail::get_type_info(typeid(MappedType));
bool local = !tinfo || tinfo->module_local;
if (local) {
tinfo = detail::get_type_info(typeid(KeyType));
local = !tinfo || tinfo->module_local;
}
Class_ cl(scope, name.c_str(), pybind11::module_local(local), std::forward<Args>(args)...);
static constexpr auto key_type_descr = detail::make_caster<KeyType>::name;
static constexpr auto mapped_type_descr = detail::make_caster<MappedType>::name;
std::string key_type_name(key_type_descr.text), mapped_type_name(mapped_type_descr.text);
// If key type isn't properly wrapped, fall back to C++ names
if (key_type_name == "%") {
key_type_name = detail::type_info_description(typeid(KeyType));
}
// Similarly for value type:
if (mapped_type_name == "%") {
mapped_type_name = detail::type_info_description(typeid(MappedType));
}
// Wrap KeysView[KeyType] if it wasn't already wrapped
if (!detail::get_type_info(typeid(KeysView))) {
class_<KeysView> keys_view(
scope, ("KeysView[" + key_type_name + "]").c_str(), pybind11::module_local(local));
keys_view.def("__len__", &KeysView::len);
keys_view.def("__iter__",
&KeysView::iter,
keep_alive<0, 1>() /* Essential: keep view alive while iterator exists */
);
keys_view.def("__contains__",
static_cast<bool (KeysView::*)(const KeyType &)>(&KeysView::contains));
// Fallback for when the object is not of the key type
keys_view.def("__contains__",
static_cast<bool (KeysView::*)(const object &)>(&KeysView::contains));
}
// Similarly for ValuesView:
if (!detail::get_type_info(typeid(ValuesView))) {
class_<ValuesView> values_view(scope,
("ValuesView[" + mapped_type_name + "]").c_str(),
pybind11::module_local(local));
values_view.def("__len__", &ValuesView::len);
values_view.def("__iter__",
&ValuesView::iter,
keep_alive<0, 1>() /* Essential: keep view alive while iterator exists */
);
}
// Similarly for ItemsView:
if (!detail::get_type_info(typeid(ItemsView))) {
class_<ItemsView> items_view(
scope,
("ItemsView[" + key_type_name + ", ").append(mapped_type_name + "]").c_str(),
pybind11::module_local(local));
items_view.def("__len__", &ItemsView::len);
items_view.def("__iter__",
&ItemsView::iter,
keep_alive<0, 1>() /* Essential: keep view alive while iterator exists */
);
}
cl.def(init<>());
// Register stream insertion operator (if possible)
detail::map_if_insertion_operator<Map, Class_>(cl, name);
cl.def(
"__bool__",
[](const Map &m) -> bool { return !m.empty(); },
"Check whether the map is nonempty");
cl.def(
"__iter__",
[](Map &m) { return make_key_iterator(m.begin(), m.end()); },
keep_alive<0, 1>() /* Essential: keep map alive while iterator exists */
);
cl.def(
"keys",
[](Map &m) {
return std::unique_ptr<KeysView>(new detail::KeysViewImpl<Map, KeysView>(m));
},
keep_alive<0, 1>() /* Essential: keep map alive while view exists */
);
cl.def(
"values",
[](Map &m) {
return std::unique_ptr<ValuesView>(new detail::ValuesViewImpl<Map, ValuesView>(m));
},
keep_alive<0, 1>() /* Essential: keep map alive while view exists */
);
cl.def(
"items",
[](Map &m) {
return std::unique_ptr<ItemsView>(new detail::ItemsViewImpl<Map, ItemsView>(m));
},
keep_alive<0, 1>() /* Essential: keep map alive while view exists */
);
cl.def(
"__getitem__",
[](Map &m, const KeyType &k) -> MappedType & {
auto it = m.find(k);
if (it == m.end()) {
throw key_error();
}
return it->second;
},
return_value_policy::reference_internal // ref + keepalive
);
cl.def("__contains__", [](Map &m, const KeyType &k) -> bool {
auto it = m.find(k);
if (it == m.end()) {
return false;
}
return true;
});
// Fallback for when the object is not of the key type
cl.def("__contains__", [](Map &, const object &) -> bool { return false; });
// Assignment provided only if the type is copyable
detail::map_assignment<Map, Class_>(cl);
cl.def("__delitem__", [](Map &m, const KeyType &k) {
auto it = m.find(k);
if (it == m.end()) {
throw key_error();
}
m.erase(it);
});
cl.def("__len__", &Map::size);
return cl;
}
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
// Copyright (c) 2023 The pybind Community.
#pragma once
#include "detail/common.h"
#include "detail/descr.h"
#include "cast.h"
#include "pytypes.h"
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(detail)
template <>
class type_caster<PyObject> {
public:
static constexpr auto name = const_name("object"); // See discussion under PR #4601.
// This overload is purely to guard against accidents.
template <typename T,
detail::enable_if_t<!is_same_ignoring_cvref<T, PyObject *>::value, int> = 0>
static handle cast(T &&, return_value_policy, handle /*parent*/) {
static_assert(is_same_ignoring_cvref<T, PyObject *>::value,
"Invalid C++ type T for to-Python conversion (type_caster<PyObject>).");
return nullptr; // Unreachable.
}
static handle cast(PyObject *src, return_value_policy policy, handle /*parent*/) {
if (src == nullptr) {
throw error_already_set();
}
if (PyErr_Occurred()) {
raise_from(PyExc_SystemError, "src != nullptr but PyErr_Occurred()");
throw error_already_set();
}
if (policy == return_value_policy::take_ownership) {
return src;
}
if (policy == return_value_policy::reference
|| policy == return_value_policy::automatic_reference) {
return handle(src).inc_ref();
}
pybind11_fail("type_caster<PyObject>::cast(): unsupported return_value_policy: "
+ std::to_string(static_cast<int>(policy)));
}
bool load(handle src, bool) {
value = reinterpret_borrow<object>(src);
return true;
}
template <typename T>
using cast_op_type = PyObject *;
explicit operator PyObject *() { return value.ptr(); }
private:
object value;
};
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
Teo Mrnjavac <teo@kde.org>
<!-- SPDX-FileCopyrightText: no
SPDX-License-Identifier: CC0-1.0
-->
# MAINTAINER
Calamares maintainers through the years:
* Teo Mrnjavac <teo@kde.org> (maintainer -2017)
* Adriaan de Groot <groot@kde.org> (maintainer 2017-2022)
* Community (2022-)
Community maintainers are Adriaan de Groot, Anke Boersma, Evan James.
# CONTRIBUTORS
Calamares has received contributions of code, documentation, artwork
and moral support from (alphabetically by first name or nickname):
- Aaron Rainbolt
- Adriaan de Groot
- Aleksey Samoilov
- Alf Gaida
- aliveafter1000
- Allen Welkie
- AlmAck
- Andrius Štikonas
- Anke Boersma
- Anubhav Choudhary
- Arjen Balfoort
- Arnaud Ferraris
- Artem Grinev
- artoo
- benne-dee
- Bernhard Landauer
- Bezzy1999
- Bill Auger
- Bob van der Linden
- Boria138
- Brian Morison
- Caio Jordão Carvalho
- Camilo Higuita
- Christophe Marin
- Collabora LTD
- Corey Lang
- crispg72
- dalto8
- Dan Simmons
- demmm
- DemonKiller
- Dominic Hayes
- El-Wumbus
- Emir SARI
- Emmanuel Arias
- Enrique Medina Gremaldos
- Erik Dubois
- Evan Goode
- Evan James
- Evan Maddock
- Ficelloo
- Frede Hundewadt
- Gabriel Craciunescu
- Gaël PORTAY
- GeckoLinux
- Harald Sitter
- Hector Martin
- Huang Jia Wen
- huxingyi
- Ivan Borzenkov
- Jeremy Attali
- Jeremy Whiting
- Jerrod Frost
- Jia Chao
- Johannes Kamprad
- Jonas Strassel
- Jonathan Esk-Riddell
- Kai Dohmen
- Kasra Hashemi
- Kevin Kofler
- Kyle Robertze
- Lisa Vitolo
- Lukas Märdian
- Mario Haustein
- Masato TOYOSHIMA
- Matti Hyttinen
- n3rdopolis
- Neal Gompa
- Nico 'dr460nf1r3'
- Omer I.S.
- Panda
- Paolo Dongilli
- Peter Jung
- Philip Müller
- Ramon Buldó
- Raul Rodrigo Segura
- Rohan Garg
- Santosh Mahto
- Scott Harvey
- shivanandvp
- Simon Quigley
- Sunderland93
- Sławomir Lach
- Taejun Park
- Tj
- Victor Fuentes
- Vitor Lopes
- vtriolet
- Walter Lapchynski
- Waneon Kim
- wiz64
> This list was updated to revision 283668cb0155c1c14739bb3b51db3d5d0b39c8e2 on February 17th 2024.
<!-- SPDX-FileCopyrightText: no
SPDX-License-Identifier: CC0-1.0
-->
This is the changelog for Calamares. For each release, the major changes and
contributors are listed. Note that Calamares does not have a historical
changelog -- this log starts with version 3.2.0. The release notes on the
website will have to do for older versions.
Calamares version 3.2.61 is the last one to have updated CHANGES-3.2
in the *calamares* (e.g. development, or 3.3, branch). For changes
in the stable release branch, see CHANGES-3.2 in that branch.
# 3.2.61 (2022-08-24) #
This is the second community-maintainence release of Calamares 3.2.
It corrects a handful of bugs foud in the stable release. There
are also translation updates.
This release contains contributions from (alphabetically by first name):
- Adriaan de Groot
- Anke Boersma
## Core ##
- The "About" and "Debug" buttons in a QWidgets-based panel were no
longer translated. This has been fixed (by re-using translations
of the same buttons from the QML module. #2030 (Thanks Anke)
## Modules ##
- *bootloader* Python code slipped in that was incompatible with
the minimum required Python version. #2033 (Thanks Adriaan)
- *locale* fixes a large regression introduced with 3.2.60, where
the location picked for many locales was not the same as in 3.2.59,
and generally peculiar (e.g. picking "English" led to "en_AG" which
is nice if you are in Bermuda, but not expected in the rest of the
world). #2008
- *luksopenswaphookcfg* Remove duplicate options. #1659 (Thanks Anke)
# 3.2.60 (2022-06-19) #
This is the first community-maintainence release of Calamares 3.2.
Somewhat ironically, all the commits in the branch come from
Adriaan de Groot -- the community is working in the 3.3 (*calamares*)
branch.
## Core ##
- No core changes
## Modules ##
- *fstab* now warns when the mount options are empty (which is non-
sensical, and indicates that the configuration is bad).
- *locale* does a better job of preserving Catalan (Valencia)
across modules; previously it dropped the *Valencia*
after the locale module unless you specifically re-selected
`ca@valencia` in the locale module. (Reported by Lliurex)
- *welcome* now has text labels on the special buttons (nominally,
this is part of the core, but the *About* button was always on the
welcome page).
# 3.2.59 (2022-05-29) #
This release contains contributions from (alphabetically by first name):
- Arjen Balfoort
This is the final release of Calamares 3.2 where the release is from
the *calamares* branch -- that is, where the primary development
branch is also the branch being released regularly. Future releases
of the 3.2 series are bugfix-only, and no new feature development
or translations are expected. This is also the final release done
*as work-work* by the current maintainer.
## Core ##
- Prep-work for moving the *About Calamares* button to the panels,
rather than keeping it in the Welcome module. The about information
is somewhat more flexible now, so that a new maintainer can be added
easily without frustrating translators.
- The progress panels (both Widgets and QML) now have an About button
on them, showing the traditional *About Calamares* dialog.
- Translations for the (QML) slideshow were not being loaded correctly.
The log is now somewhat more informative when that fails.
## Modules ##
- *fstab* can now be configured to put `/tmp` on a *tmpfs*, and this can
depend on it being on an SSD or not. Options applicable to `/tmp` can
be configured separately as well. #1818 (Thanks Arjen)
- *partition* now has some support for re-using LUKS partitions.
(Thanks Arjen)
- *partition* will cycle out a LUKS key if all the key slots are in use
and a new key is added, rather than crashing the installer. (Thanks Arjen)
- *welcome* and *welcomeq* have no *About* button anymore; this is now
available from the progress panel, since it's also not-really about the
distro itself.
# 3.2.58.2 (2022-05-24)
This is a extra-quick release for an issue that shows up when using a
swap **file** on a btrfs filesystem; the installation would fail with
a Python error, raised from btrfs-progs. Reported by Evan James, Erik
Dubois, TechXero.
# 3.2.58.1 (2022-05-20)
This is a hot-fix release for a regression in the *partition* module where
it was impossible to proceed unless *Encrypt system* was checked.
# 3.2.58 (2022-05-18) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Arjen Balfoort
- Enrique Medina Gremaldos
- Evan James
## Core ##
- Internal improvements to translations-setup means that Catalan (in the
Valencian dialect), Occitan (Lenga d'Oc) and Serbian (in Latin script)
are all better supported. Thanks Enrique.
## Modules ##
- *netinstall* Now displays entries with an empty name slightly differently.
An empty name is not generally useful, but in combination with
*immutable:true* and *selected:false* can be used to introduce separators
or descriptive comments into the list of packages.
- *partition* does not offer full-disk encryption when using ZFS. ZFS and the
way Calamares sets up FDE don't mix well. (Thanks Evan)
- *partition* Various bugs related to LUKS have been fixed. (Thanks Arjen)
- *users* module now has a structured *user* key with settings specific
to the user (shell, in particular). This maintains backwards compatibility
with the *userShell* key.
- *users* module now has lists of forbidden login- and host-names, to
avoid settings that will mess up the install (e.g. using a login-name
that is one of the system's reserved names). #1944
# 3.2.57 (2022-05-04) #
This release contains contributions from (alphabetically by first name):
- Arjen Balfoort (new contributor! Welcome!)
- Victor Fuentes
## Core ##
- Calamares can now be started in Serbian (Latin Script) and Catalan
(Valencia) when the LANG environment variable is set to values
that indicate those languages.
## Modules ##
- *fstab* and *luksbootkeyfile* have better support for an **un**encrypted
`/boot` partition. #1931 (thanks Arjen)
- *packagechooser* and *packagechooserq* can now be given a custom name
in the side-panel. #1932 (thanks Victor)
# 3.2.56 (2022-04-22) #
As of this release, Calamares 3.2 development is winding down. The
reason is simple: systems where the backwards-compatibility of Calamares
3.2 is important are becoming increasingly difficult to work with
for **other** reasons. Foremost among these are deprecated versions
of dependencies and tools. Calamares 3.2 branch remains open for
bugfixes and will see a few more releases, but development is now
shifting wholesale to the newer generation.
This release contains contributions from (alphabetically by first name):
- Victor Fuentes (new contributor! Welcome!)
## Core ##
- Changes in git forced some changes on the CI tooling.
## Modules ##
- *locale* showed the wrong timezone for Dhaka, although it configured
the correct one. #1929
- *users* module sets global storage key *fullname* to the full name
of the user (e.g. what is entered in the "your full name" box on the
users page). #1923 (Thanks Victor)
# 3.2.55 (2022-04-11) #
This release contains contributions from (alphabetically by first name):
- vtriolet (new contributor! Welcome!)
## Core ##
- `readTargetFile()` did not properly return all the lines of the target
file. #1918 (thanks vtriolet)
## Modules ##
- *users* module has rearranged configuration for setting the hostname.
Legacy settings are preserved, but produce a warning. Please see
`users.conf` for details.
- *users* module has a new hostname.location setting, *Transient*, which
will force the installed system to transient-hostname-setting by removing
the file `/etc/hostname`.
- *users* module has a new hostname.template setting, which allows some
tweaking of how the hostname suggestion is constructed. In particular,
it can be configured to use the current hostname (whatever that may be).
See the example `users.conf` for details on available keys.
# 3.2.54 (2022-03-21) #
This release contains contributions from (alphabetically):
- Bob van der Linden (new contributor! Welcome!)
- El-Wumbus (new contributor! Welcome!)
- Evan James
- Santosh Mahto (new contributor! Welcome!)
## Core ##
- During the installation ("exec") step, while the slideshow is displayed,
there is also a button to show the scrolling installation log as it
is written. (Thanks Bob)
## Modules ##
- *fstab* module correctly handles empty UUID strings. (Thanks Evan)
- *partition* module no longer forgets configured partition-layouts.
It also respects configured partition labels better. (Thanks Santosh)
# 3.2.53 (2022-03-04) #
This release contains contributions from (alphabetically by first name):
- Huang Jia Wen (new contributor! Welcome!)
## Core ##
- Automount-manipulation (to switch off KDE Plasma automounting new devices)
now logs slightly more as it works. Defaults have changed in KDE Plasma
5.24 and it turns out the automount-manipulation does not work well.
Distro's are encouraged to turn off automount in the live ISO (see #1885).
## Modules ##
- *bootloader* now knows about loongarch64 and can install suitable EFI
files for this CPU type. (Thanks Huang Jia Wen)
- Progress reporting for `pacman` from the *packages* module has been switched
off. The progress reporting works under low load, but there are many reports
of it crashing (from XeroLinux and from Evan James, who has been debugging
the issue) during a regular installation with thousands of updates. This
will be revisited in the next release.
- The *umount* module was buggy and did not actually unmount anything.
# 3.2.52 (2022-02-25) #
This release contains contributions from (alphabetically by first name):
- Evan James
## Core ##
- No core changes yet
## Modules ##
- *fstab* recognizes nvme and mmc devices correctly as SSDs now. #1883
- *luksbootkeyfile* handles trailing slashes in mount point
- *partition* can be built with a new `SKIP` option, which skips
the actual formatting steps but does not fail. The old `LAME`
option is renamed `BAIL_OUT`.
- *users* has a new key *sudoersConfigureWithGroup* to allow for
different styles of sudo configuration. #1887
# 3.2.51 (2022-02-01) #
This release contains contributions from (alphabetically by first name):
- Evan James
**WARNING** The *umount* module has been rewritten in C++. Check your
configuration if you previously used the copy-a-log functionality.
## Core ##
- Evan has made a start on documenting which Global Storage keys there
are and how they tie modules together. This can be found in the
`src/modules/README.md` documentation.
## Modules ##
- *bootloader* can now be configured to try to generate a unique
suffix for the bootloader-id. #1820
- *grubcfg* now has a configurable default for kernel parameters,
which allows distributions to change the value from `quiet`.
The default, if nothing is set, remains `quiet`. Use an explicitly-
empty list to specify no-arguments-at-all.
- *packagechooser* can now export its choices for use by the *netinstall*
module. This makes it possible to use *packagechooser* for large-scale
choices, followed by *netinstall* for fine-grained control. (Thanks Evan)
- When the *partition* module has a conflicting configuration for the
swap choices, it prints a warning and uses the configured choice, rather
than always using "suspend". #1881
- The *umount* module has been re-written in C++. The copy-a-log-file
functionality has been removed. Use the *preservefiles* module for that.
# 3.2.50 (2022-01-18) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Erik Dubois
- Evan James
- Johannes Kamprad
- Taejun Park (new contributor, welcome!)
**Replacement notice:** The *umount* module will be replaced by a C++
implementation in the next release. The "preserve log file" feature
will be removed in that release. Use the *preservefiles* module instead.
## Core ##
- No core changes yet
## Modules ##
- *initcpiocfg* mentioned a special kernel-name "all", which did not work,
and a special kernel-name "$uname" which cannot work. Fixed the former
and removed the "$uname" special key. (Thanks Evan)
- *luksswaphookcfg* has been converted to a C++ module.
- *networkcfg* could fail to update the NetworkManager configuration
if the SSID or username contained non-ASCII characters **and** the
default Python text-file encoding was set to ASCII. The files are
now read and written in UTF-8, explicitly. #1848
- *partition* always sets *bigtime* option on XFS filesystems, if possible.
Requires sufficiently-recent xfsprogs. #1874
- *preservefiles* was missing some necessary features, needed for it
to replace the deprecated log-file-saving functionality in the *umount*
module. (Thanks Erik and Joe for testing) #1851
- *umount* is now marked as an emergency module in the example configuration,
since it should **probably** be run as a cleanup. (Thanks Evan)
- *welcome* and *locale* could be confusing, together, and configure
the target system with a language that does not match the installer
language, even though the user did not make any explicit choice.
(Thanks Taejun) #1864
# 3.2.49.1 (2021-12-11) #
This is a hot-fix release, to fix a regression in the calculation of
swap-size. Reported by EndeavourOS (Joe Kamprad) and Xero Linux.
# 3.2.49 (2021-12-10) #
This release contains contributions from (alphabetically by first name):
- Artem Grinev
- Evan James
Distributions are **specifically** reminded to update the *umount* module
configuration (and to use *preservefiles* if needed).
## Core ##
- Errors (e.g. when an installation fails for whatever reason) are displayed
in a dialog with a scrollable details panel, rather than growing up
to the size of the screen. (Thanks Artem)
## Modules ##
- *bootloader* better supports multiple installations of the same OS.
- *mount* supports btrfs subvolumes on subdirectories of / now.
- *partition* now supports "deep" btrfs subvolume names, e.g. a
separate subvolume for `/usr/local`. (Thanks Evan)
- The *umount* module now warns if the "preserve log file" feature is used.
This has been deprecated for a long time: use the *preservefiles* module
instead. A future release will turn this into an error.
# 3.2.48 (2021-12-03) #
This release contains contributions from (alphabetically by first name):
- Evan James
## Core ##
- Python modules now have `warn()` and `error()` methods they can call,
alongside the existing `debug()` and `warning()` (all live in the
*libcalamares.utils* module).
- Python modules can load YAML files via `libcalamares.utils.load_yaml()`.
This may be the most useful for test-scripts.
## Modules ##
- *fstab* now has a separate, special, flags-setting for swap subvolumes
on btrfs. A swap subvolume is created if a swap **file** (not a separate
partition) is selected in the auto-partitioning page. (Thanks Evan)
- When using btrfs, the *mount* module creates subvolumes. It was not
possible to **avoid** having a subvolume name created for the root.
This is now possible. #1837
- The *packages* module now has some special settings for the `pacman`
package manager (generally used on Arch-derivatives). This allows
tweaking of the installation process, if downloads are slow or
packages may fail to install. See the `packages.conf` file for
details. (Thanks Evan)
# 3.2.47 (2021-11-19) #
This release contains contributions from (alphabetically by first name):
- Evan James
- Jonas Strassel
## Core ##
- The translation for Sinhala (`si`) has reached 100%. Thank you to
හෙළබස and Sandaruwan, translators for Sinhala, for special effort
in completing that translation.
- Logging now supports Redacted names. This reduces the scope for
leaking names or other private information through the logs
(if they are posted to a pastebin). A name is redacted consistently
within one run of Calamares, but differently each time.
## Modules ##
- *bootloader* with systemd-boot now handles root subvolumes better
(Thanks Evan)
- *displaymanager* supports the *greetd* display manager, which is a
kind of meta-DM itself, supporting multiple greeters. (Thanks Jonas)
- *finishedq* now has an extra example QML file that builds the UI in
a different fashion, demonstrating how a mobile-OS customization of
Calamares would present the "all done" message.
- *fstab* has an example configuration file that mentioned `space_cache`
as an option. Since 2014 there was only one possible value, so this
option matched the default-and-only value. Newer kernels with newer
btrfs versions have a `v2` option value as well. Remove the example
option, since the kernel automatically picks the right value, while
setting it to the wrong one may prevent the system from booting.
(Thanks Evan)
- The *partition* module no longer logs recognizable disk names or
UUIDs. These are redacted in the logs. #1593
- The *partition* module, together with the new *zfs* module and changes
in *mount* and *bootloader* can install to ZFS **if** the distribution
kernel supports it. ZFS tools are required, as well as the relevant
kernel modules. See the `README.md` in the *zfs* module. (Thanks Evan)
# 3.2.46 (2021-11-09) #
This release contains contributions from (alphabetically by first name):
- Philip Müller
## Core ##
- A new core class `Runner` is now responsible for running commands
either in the host or in the target system. This is invisible for
end-users, but **does** expand the API available to consumers inside
Calamares modules. In particular, Python modules can now easily read
and respond to command output. #1740
## Modules ##
- *fstab* writes a slightly different message in `/etc/crypttab`
about the root filesystem. Since Calamares itself ignores the
(previous wording of) message, it was confusing. #1811
- *packages* module has some support for reporting progress while
the packages are installed. This depends on the package-manager itself
reporting useful progress information **and** the *packages* module having
support-code to interpret that progress. A proof-of-concept for `pacman`
has been implemented. #1582
- *partition* has a number of edge-cases for LVM and LUKS resolved. #1564 #1817
- *partition* module once again always offers `/boot` as a mount-point, even
when EFI would want `/boot/efi`. (Thanks Phil)
- *summary* had a regression and showed some descriptive texts twice.
# 3.2.45 (2021-10-31) #
This release contains contributions from (alphabetically by first name):
- Evan James (new contributor, welcome!)
## Core ##
- New internal convenience functions from Evan
## Modules ##
- *packagechooser* now displays screenshots nicely-scaled
rather than jagged. (#1807)
- *partition* module removes ZFS partitions directly. At install-time,
we think that the partitions should be handled separately from a
zpool that potentially includes those partitions. (Thanks Evan)
- *services-systemd* supports timers, e.g. for weekly trim on SSDs.
(Thanks Evan)
# 3.2.44.3 (2021-10-04) #
This is not a hotfix release, but a tiny-tiny incremental improvement
that fixes one hugely annoying -- user-facing message presenting
bytes as mebibytes -- bug in the partition module.
## Modules ##
- The *partition* module now consistently uses the configured EFI
partition size (defaults to 300MiB).
- Internal changes in the *summary* module to increase consistency
between *summary* and *summaryq*.
# 3.2.44.2 (2021-09-27) #
This release contains contributions from (alphabetically by first name):
- Corey Lang (new contributor, welcome!)
This is a hotfix for a typo -- not a syntax error -- that affects the
*networkcfg* module. Reported and fixed by Corey.
# 3.2.44.1 (2021-09-24) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
This is a hotfix for a typo -- not a syntax error -- that affects the
*initcpiocfg* module. Reported and fixed by Anke.
# 3.2.44 (2021-09-24) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Shrinivas Vishnu Kumbhar (new contributor, welcome!)
- whorfin (new contributor, welcome!)
## Core ##
- "Log spam" has been reduced a little in the partitioning module.
## Modules ##
- *initcpiocfg* has had a number of internal code-fixes, and now adds
the `consolefont` hook by default as well. (Thanks Shrinivas)
- Both *locale* and *keyboard* have received some tweaks for configurations
in India; unless the user selects otherwise, English is preferred.
- The *luksbootkeyfile* module was reported to be too quick to declare
a timeout when applying the keyfile. The timeout has been increased
to one minute. (Thanks whorfin)
- *networkcfg* tries harder to find the live-user login for re-working
networking settings. This fixes a regression on FerenOS, where the
installer was crashing because it could not find the live-user login.
# 3.2.43 (2021-09-17) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Joe Kamprad
## Core ##
- Translations have been made more consistent. In particular, some *OK*,
*Yes*, *No* and *Cancel* buttons that were previously untranslated
or "stuck" in the language that Calamares started in, are now
changed to the current language as selected in the welcome page.
- Documentation improvements from Joe Kamprad. A *sizeLimit* of zero
(which is the default if nothing is set in the branding configuration)
disables log uploads.
## Modules ##
- The *keyboardq* module (QML-based UI for keyboard-layout-selection)
now features an interactive keyboard preview and has the
layout adjusted. (Thanks Anke)
# 3.2.42 (2021-09-06) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Artem Grinev
- Nico 'dr460nf1r3' (new contributor, welcome!)
- Waneon Kim (new contributor, welcome!)
## Core ##
- No core changes yet
## Modules ##
- BTRFS partitions are no longer listed as "check in phase 2" in
the *fstab* module. (Thanks Nico)
- The *keyboard* module (and *keyboardq*) now pick an English layout
(with Rupee) for keyboards when the language is English and locale is India,
rather than Hindi layout.
- The *localeq* module had the i18n.qml rewritten to make it easier
to customize. A bug in the layout has been fixed, and the overall
look has been updated.
- *networkcfg* now translates the "live user" on an ISO to the regular
user on the installed system, so that network configuration changes
made in the live system are automatically used after installation. #1755
- *partition* no longer allows you to delete an extended partition with
children (which led to crashes). #1749 (Thanks Artem)
- *partition* complains in more detail about the state of the UEFI
boot partition (under manual partitioning schemes). #1761
- *welcome* can now check multiple URLs to determine if internet connectivity
is available. It is still recommended to check the distro home-page or
some special "ping" page of the distro, although that has some privacy
implications; using example.com or google.com may work as well. Listing
multiple URLs will ping each of them in turn until one succeeds. #1669
- The work to make a QML version available for all view modules is almost
completed. Two new QML modules have been added *packagechooserq* and *summaryq*.
Summaryq brings the option to present the summary page in a customizable
way, with a bit more of a contemporary look. Packagechooserq adds the option
to preselect an item and displays all options in one overview.
(Thanks Anke)
# 3.2.41.1 (2021-08-05) #
This is a hotfix release for a crash in the *partition* module, reported on
KDE neon. #1746
# 3.2.41 (2021-07-31) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Camilo Higuita
## Core ##
- The (re)translation framework has been internally re-vamped to be
less resource-intensive and to work with all QObjects, not just
widgets. Consumers of the translations framework are expected to
set up the event filter on the top-level widget(s) manually. Since
Calamares and the Calamares-test-applications have been adjusted already,
no further action is needed.
## Modules ##
- When the *keyboard* module is activated, it no longer replaces
an explicit user choice (e.g. for a Belgian layout) by a guessed-for-
this-language layout (e.g. Danish if you're installing in Danish).
- Logic for handling installation lists has been moved around in the
*packages* module so that package managers can, in principle,
adjust how to handle critical and non-critical package lists.
- In the *partition* module, translation code has been simplified.
- The *usersq* module has had a fair bit of QML rewritten to make it easier
to customize the colors used by the module in a consistent way.
(Thanks Anke)
- *Welcome* now uses a translated message from the Config object,
increasing the sharing between widgets- and QML-modules.
# 3.2.40 (2021-07-14) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Anubhav Choudhary (SoK success!)
- Emmanuel Arias (new contributor! welcome!)
- Erik Dubois
- Jerrod Frost (new contributor! welcome!)
- Jia Chao (new contributor! welcome!)
- Joe Kamprad
- Lisa Vitolo (blast from the past!)
- Omer I.S. (new contributor! welcome!)
In project news, chat (instant-messaging) communications has largely
moved to Matrix and Libera.Chat. CI notifications -- issues and build
results -- are sent to Matrix only.
## Core ##
- The CMake modules for consumption by external modules (e.g. the
calamares-extensions repository, but also any other modules built
by distro's for internal use) now support consistent skip-module
behavior and reporting. #1641 (one tiny part of this change)
- In global storage, the *filesystem_use* key now has an API in
libcalamares to systematically mark filesystem (types) as "in use"
or not. This, in turn, means that modules can depend on that information
for other work (e.g. removing drivers for unused filesystems). #1635
- The "upload log file" now has a configurable log-file-size. (Thanks Anubhav)
## Modules ##
- *bootloader* can now install an aarch64 (ARM) compatible EFI GRUB. (Thanks Jia)
- *displaymanager* example configuration has been shuffled around a bit,
for better results when the live image is running XFCE. Also lists
more potential display managers. #1205 (Thanks Erik)
- *keyboard* now switches on an alternate `en_US` keyboard layout when
Arabic or Hebrew is selected as primary layout. (Thanks Omer)
- *localeq* now has a fully functional offline option (alongside the default
interactive map option, which requires internet).
- The *netinstall* module can now fall back to alternative URLs when
loading groups data. The first URL to yield a non-empty groups
collection is accepted. No changes are needed in the configuration. #1673
- *packagechooser* can now integrate with the *packages* module; that
means you can specify package names to install for a given selection,
and the regular package-installation mechanism will take care of it.
Legacy configurations that use *contextualprocess* are still supported.
See the `packagechooser.conf` file for details. #1550
- A long-neglected pull request from Lisa Vitolo for the *partition*
module -- allowing to set filesystem labels during manual partitioning --
has been revived and merged.
- The *partition* manager has had a long-standing bug with partition-flags
and manual partitioning resolved. This may help resolve some installation
issues on UEFI systems. #1724
- *usersq* is further implemented and can now be used for a successful install.
Not all warning messages available in the regular users module are implemented.
# 3.2.39.3 (2021-04-14) #
A minor bugfix tweak release. Since this contains yet **another**
autologin-related fix, and there is nothing large enough to justify
a 3.2.40 release yet, add it to the growing tail of 3.2.39. (Reported
by Joe Kamprad, #1672). Also fixes a regression from 3.2.28 in
localized packages (e.g. *package-LOCALE* did not work).
# 3.2.39.2 (2021-04-02) #
This is **another** hotfix release for issues around autologin ..
autoLogin, really, since the whole problem is that internal capitalization
changed. An unrelated bug in writing /etc/default/keyboard was
also fixed. (Reported by pcrepix, #1668)
# 3.2.39.1 (2021-03-30) #
This hotfix release corrects a regression in the *displaymanager*
module caused by changes in the *users* module; autologin was
internally renamed and no longer recognized by the *displaymanager*
module. (Reported by Erik Dubois, #1665)
# 3.2.39 (2021-03-19) #
This release contains contributions from (alphabetically by first name):
- Matti Hyttinen
## Core ##
- A *packages* service has been added to the core, for use by
*netinstall* module and any others that need to set up
package information for the *packages* module.
## Modules ##
- The *mount* module has gained a configurable setup for btrfs volumes.
If your distro has a default-to-btrfs setup, it can skip the hard-
coded setup (which Calamares has had for a long time with @home
and similar) and introduce a custom btrfs configuration through the
`mount.conf` file. See issues #1659 and #1661 for warnings about
using this in production.
- *netinstall* now supports fallbacks for the groups data.
Instead of a single URL, multiple URLs may be specified in
a list and Calamares goes through them until one is successfully
retrieved. Older configurations with a single string are
treated like a one-item list. #1579
- The *usersq* module now connects to the internal configuration
object and may be usable for regular installations.
# 3.2.38.1 (2021-03-15) #
This hotfix release is for this item in the release notes of 3.2.38:
- The .desktop file for Calamares now makes a longer trip, calling
`sh -c "pkexec calamares"`; distributions may still need to adjust.
The change had been lost while updating other files. It has been restored
in `calamares.desktop` and `calamares.desktop.in`. (Reported by Erik)
Other minor changes and fixes:
- presets in the *users* module show the hostname, too,
- translations update for Korean, Ukranian and Chinese (zh_TW).
# 3.2.38 (2021-03-14) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Anubhav Choudhary
- Neal Gompa
## Core ##
- Uploading your log files (in case of installation failure) has been
expanded and is now more configurable. Users should still take care
when uploading logs, and distro's should configure a URL with
no public viewing of those logs. (Thanks Anubhav)
- The .desktop file for Calamares now makes a longer trip, calling
`sh -c "pkexec calamares"`; distributions may still need to adjust.
## Modules ##
- A new QML-based *finishedq* module has been added. (Thanks Anke)
- The *packages* module no longer supports *urpmi*; no Calamares-
consumers with that package manager seem to exist. (Thanks Neal)
- The *users* module now can set a fixed username and prevent editing.
The *presets* configuration entry in `users.conf` can set a *loginName*
and a *fullName* and (independently) enable or disable editing of
that value. You can, for instance, set *loginName* to "manjaro" if
you like; the user can change it afterwards. You could set the
*loginName* to "oem" and prevent editing it as well. #942
# 3.2.37 (2021-02-23) #
This release contains contributions from (alphabetically by first name):
- benne-dee
## Core ##
- Calamares has a table of 'best guess' languages for each country
and when GeoIP is enabled, it will automatically select that
country's language as default -- the user can of course pick
a different one. The 'best guess' is based on Unicode / ISO
data, which is sometimes dubious. Based on some personal notes,
the 'best guess' language for Belarus has been changed to Russian.
- Calamares has a table of 'best guess' keyboard mappings,
allowing native language input. However, usernames and
passwords should be in US-ASCII (this is a limitation of
the login system -- **some** parts of the system will support
non-ASCII input, but it's better safe than sorry).
Add Greek to the list of languages that needs US-ASCII
in addition to native input.
- The CI infrastructure now builds Calamares and Calamares-extensions
on a nightly basis.
## Modules ##
- The *netinstall* module has a YAML schema, allowing packagers
to validate and verify their netinstall configurations before
shipping an ISO (or writing bug reports). Thanks benne-dee.
- The *finished* module has been heavily refactored, opening
the way to a QML-based version of the same module. This is
also preparatory work for allowing packagers (e.g. PostmarketOS)
to customize the messages on the finished page.
# 3.2.36 (2021-02-03) #
This release contains contributions from (alphabetically by first name):
- Anubhav Choudhary
- benne-dee
- Gaël PORTAY
- Jonas Strassel
- Kevin Kofler
- Matti Hyttinen
- Neal Gompa
## Core ##
- It is now possible to hide the *next* and *back* buttons during
the "exec" phase of installation. Thanks Anubhav.
- The Calamares CI has migrated to GitHub actions. Thanks Jonas.
## Modules ##
- *bootloader* now uses the current file names for the UEFI Secure Boot
shim instead of obsolete ones.
- The *mount* module creates swap in its own subvolume, if btrfs is used.
Thanks Matti.
- *partition* includes more information about what it will do, including
GPT partition types (in human-readable format, if possible). Thanks Gaël.
- Some edge-cases with overlay filesystems have been resolved in the
*partition* module. Thanks Gaël.
- During the creation of filesystems and partitions, automounting is
turned off (if DBus is available, and the host system supports
KDE Solid automount control). This should reduce the number of
failed installations if automount grabs partitions while they are
being created. The code is prepared to handle other ways to control
automount-behavior as well.
# 3.2.35.1 (2020-12-07) #
This release contains contributions from (alphabetically by first name):
- Anubhav Choudhary
- Matti Hyttinen
Some strange string artifacts appeared, leading to `{1?}` being
displayed in various user-facing messages. These have been removed
and the translations updated.
## Modules ##
- The *initcpiocfg* module would sometimes configure the system to ask
for a passphrase, when none is needed.
# 3.2.35 (2020-11-30) #
This release contains contributions from (alphabetically by first name):
- Clarissa Borges
- Matti Hyttinen
A new kind of issue template has been added for Calamares,
for reporting (and adding tests for) usability issues. Thanks
to Clarissa for leading that effort.
## Core ##
- No core changes yet
## Modules ##
- The *partition* module now supports a not-full-disk-encryption setup,
where `/boot` is not encrypted, but the rest of the system is.
- The *plasmalnf* module has been substantially rewritten, so that it
can support a QML version of the module in future. The UI has changed
a little, and now displays more themes than before.
# 3.2.34 (2020-11-16) #
This release contains contributions from (alphabetically by first name):
- Artem Grinev
- Gaël PORTAY
## Core ##
- No core changes yet
## Modules ##
- The *keyboard* module had a regression in which it no-longer painted
the keycaps in the keyboard preview. (reported by Vinnie)
- The *plasmalnf* module did not set all of the look-and-feel values
in the target system. (reported by Bluestar Linux)
- In the *users* module, warnings about the strength of the password
are now correctly pluralized when possible.
- In the *users* module, if ICU is installed, the user's full name is
automatically transliterated to US-ASCII (for some locales; this will
need tweaking) so that the login name is acceptable. (Thanks Artem)
# 3.2.33 (2020-11-09) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Andrius Štikonas
- Artem Grinev
- Gaël PORTAY
- Matti Hyttinen
- TTran Me
## Core ##
- Calamares now sets the C++ standard for compilation to C++17; this
is for better compatibility and fewer warnings when building with
modern KDE Frameworks and KPMcore 4.2.0.
- Vietnamese translations have been added. Welcome! (Thanks TTran)
## Modules ##
- The *initcpiocfg* module should support plymouth with encryption
now. (Thanks Matti)
- The *keyboard* and *keyboardq* modules now share backend code
and handle non-ASCII layouts better (for setting passwords
and usernames). (Thanks Artem)
- Various cleanups and documentation improvements in the *partition*
module, and configurable GPT name for swap. (Thanks Gaël)
- A long-standing bug related to GPT partition flags in the
*partition* module has been resolved. #1327 #1267
- The *users* module now has a more detailed way to specify
user groups -- which may be system groups rather than user-GIDs.
A new option in each group can require that the group already
exists in the target system, allowing for better consistency checks
with the squashfs. #1523
# 3.2.32.1 (2020-10-17) #
This is a release to address source-incompatible changes in KPMcore 4.2.0,
which was released just before Calamares 3.2.32 and had not yet been
compile-tested. There is also one changed message in the translations,
reported by Yuri Chornoivan.
# 3.2.32 (2020-10-16) #
This release contains contributions from (alphabetically by first name):
- Fabian Tomat
- Gaël PORTAY
## Core ##
- When doing GeoIP lookups, Calamares pretends to be Firefox.
This resolves an issue where the GeoIP provider was refusing
QNAM connections with the default User-Agent.
- New translation available, Friulian. Welcome!
## Modules ##
- The *netinstall* module has some tricky configuration files;
it now complains about more cases of bad syntax or poor structure.
- The *partition* module can now be constrained to work only with
a particular kind of partition table. (thanks Gaël)
- The *partition* module is a little more resilient to variations
in btrfs notation from os-prober.
- The *shellprocess* module now supports having a different progress
message (other than "Shell Processes Job") through the config file.
# 3.2.31 (2020-10-06) #
This release contains contributions from (alphabetically by first name):
- Corentin Noël
- kadler15 (new contributor! hi!)
## Core ##
- At the start of the *exec* phase, an overview is given of the
various job weights, which allows you to tweak the overall
progress reporting during the installation.
- Problems with running Calamares on a 1-core single CPU have been resolved.
## Modules ##
- The *keyboard* module now recognizes Turkish "F" layout and
will set the vconsole keyboard layout correctly even if xkb
keymaps are not found.
- The *machineid* module, which generates UUIDs for systemd and dbus
and can generate entropy files (filled from `/dev/urandom` in the host
system) now supports more than one entropy file; generate them as needed
(or copy a fixed value to all, depending on *entropy-copy*). Deprecate
*entropy* (which generates a specific output file) as too inflexible.
- In the *partition* module, swap can now be chosen as *file*, which is
**not** create a swap partition, but write a `/swapfile` in the root
directory, 512MiB large, and set that as swap. There is as yet no
"smarts" about the size of the swap file.
- Multiple problems in the *partition* module around partition
sizing have been resolved by Corentin Noël.
- The *preservefiles* module documentation did not match the functionality,
and when used, didn't work right. #1521 (thanks kadler15)
- Progress reporting from the *unpackfs* module has been revamped:
it reports more often now, so that it is more obvious that files
are being transferred even when the percentage progress does not
change.
- The *unpackfs* module now supports a *weight* setting for each
of the unpack entries. For a single entry this does not matter,
but if there are multiple entries it allows tweaking the relative
progress between each entry.
# 3.2.30 (2020-09-03) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Asif Mahmud Shimon
- Manzoor Ahmed Munawar
- Sai Kamal
- Victor Ibragimov
This release has two giant source-code changes that have no effect
on functionality, but do touch each and every source file:
- SPDX headers for licensing information, following the standard
set by REUSE.software ; all source files and resources have
SPDX-License-Identifier information and copyright notices. All
of the boilerplate texts have been removed.
- Calamares coding style has been mechanically applied to the entire
codebase. This was already done to most of it, but there were
some hold-outs.
## Core ##
- Network access status is deprecated in Qt 5.15's QNetworkAccessManager,
and was not useful already in some previous versions. Replace its
use in the Calamares network service by testing-it-ourself directly
via a synchronous ping. (Thanks to Asif)
- New Telugu translation. (Thanks to Sai)
- Urdu translation started. (Thanks to Manzoor)
- Timezones translated in Tajik and Russian. (Thanks to Victor)
## Modules ##
- *keyboardq* and *localeq* improvements. (Thanks to Anke)
- *users* module did not set up autologin properly. This is yet another
regression left over from 3.2.28. (Reported by Phil and pcrepix, #1498)
- *welcome* module now sets the *LANG* key in the locale configuration
(which is shared with the *locale* module and consumed by the
*localecfg* module). This makes it feasible to drop the *locale*
module and still set the installed system's language to the language
selected in Calamares. (Reported by FerenOS)
# 3.2.29 (2020-08-20) #
This release contains contributions from (alphabetically by first name):
- Asif Mahmud Shimon (new contributor! hi!)
## Core ##
- Edge case in extracting string-lists from YAML, reported and fixed
by Asif (#1491).
- Progress reporting is now more flexible. Modules can have a weight
assigned to them in the descriptor; module instances can have a weight
assigned which overrides the module descriptor. When jobs are run
for a module instance, the jobs report progress pro-rated by the
module's weight. Or in other words, it is now possible to tweak
the amount of the overall progress bar that different modules fill.
The default settings give unpackfs a weight of 12. (#1176)
## Modules ##
- The *users* module did not read the *defaultGroups* correctly.
Fixed by the string-lists change mentioned above.
# 3.2.28.3 (2020-08-18) #
Another hotfix, for more issues reported by Marco Obaid. Users
were not having a password set (#1489)
# 3.2.28.2 (2020-08-12) #
A second hotfix, for autologin support -- the autologin group was not
created in the target system before assigning the user to it. Reported
by Marco Obaid.
# 3.2.28.1 (2020-08-10) #
This is a hotfix release for #1482 and #1483, where no user was
created during installation and a chmod was failing (resulting in
a failed installation). Reported by Jonathan Riddell.
With incidental improvements in SPDX tagging (code licensing)
and some new icon options for the welcomeq and localeq modules.
# 3.2.28 (2020-08-09) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- apt-ghetto
- Victor Ibragimov
## Core ##
- A new object *Network* is available to QML modules in `io.calamares.core`.
It exposes network status through the *hasInternet* property.
- Welcome to Tajik translations. The Tajik language has quickly reached
100% completion. Thanks Victor!
- Welcome to [Interlingue](https://en.wikipedia.org/wiki/Interlingue).
The translation is at an early stage. Qt does not support language
code *ie* though, so it may take some time to be integrated (much
like Esperanto wasn't supported until Qt 5.12).
## Modules ##
- The *locale* module has been completely redone on the inside.
Users should see no changes. #1391
- The *localeq* module uses the redone internals of the locale module.
It can now be used to set timezone, language and locale information
and is a suitable alternative module. Thanks to Anke Boersma who did
the work of figuring out maps. Note that the map uses several GeoIP
and GeoData providers and you may need to configure the URLs
with suitable usernames for those services. #1426
- Both *locale* and *localeq* can now be configured to use the system's
timezone setting -- this can be useful to avoid both hard-coding an
initial zone and doing extra GeoIP lookups, in the case where the
live system already does so. #1391
- The *locale* and *localeq* modules have additional machinery for
timezone lookups; please report cases where clicking on the map
returns an obviously bogus timezone (up until this release, for
instance, Cape Town).
- The *users* module no longer accepts `root` as a username. #1462
- The *keyboardq* module is now more inline with the look of the rest
of the Calamares modules, use of a background image is removed.
- The *grubcfg* module now understands `/etc/default/grub.d`. #1457
# 3.2.27 (2020-07-11) #
This release contains contributions from (alphabetically by first name):
- Gaël PORTAY
- Vitor Lopes (new! welcome!)
## Core ##
- QML modules with no surrounding navigation -- this is basically a
special case for full-screen Calamares -- now have margins suitable
for full-screen use.
- PythonQt modules are increasingly on the way out.
## Modules ##
- The Manjaro package manager *pamac* has been added to those supported by
the *packages* module.
- The *netinstall* module has had some minor UI tweaks.
- Partitioning now tries harder to avoid floppy drives.
# 3.2.26.1 (2020-06-23) #
This is a hotfix release for undefined behavior caused by an
uninitialized integer variable. It includes new translations
and features as well since those arrived independently.
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Gaël PORTAY
## Core ##
- Welcome to Azerbaijani translations. These are available
in two variations, *Azerbaijani* and *Azerbaijani (Azerbaijan)*.
[Wikipedia Azerbaijani](https://en.wikipedia.org/wiki/Azerbaijani_language#North_vs._South_Azerbaijani)
has a nice overview.
- Warnings while building with Qt 5.15 have been much reduced.
## Modules ##
- *partitioning* has one case of undefined behavior (UB) due
to a missing integer-initialization. (Thanks Gaël)
- *keyboardq* QML module now works correctly. (Thanks Anke)
# 3.2.26 (2020-06-18) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Gaël PORTAY
- Pablo Ovelleiro Corral
- Philip Müller
## Core ##
- The default branch for Calamares source repositories (calamares
and calamares-extensions) is now *calamares*.
- External modules can now be built again, outside of the Calamares
source and build-tree.
- The repository *calamares-tools* has been removed. The idea behind
the tooling was to provide schema validation for Calamares configuration
files. This has been merged into the primary repository, where it
is now part of the test suite.
## Modules ##
- *locale* put some more places into the correct timezone **visually**;
for instance Norfolk Island gave up UTC+11.5 in 2015 and is now
UTC+11, but Calamares still showed it in a zone separate from UTC+11.
- *localeq* can now properly switch between on & offline mode,
it detects internet status through js.
- *packages* gained support for the Void Linux package manager,
*xbps*. (thanks Pablo)
- *tracking* now supports kuserfeedback configuration.
- *welcomeq* added the GEOIP configuration option, so locale can be
initially set according to IP address.
# 3.2.25 (2020-06-06) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Callum Farmer
- FLVAL
- Gaël PORTAY
## Core ##
- The slideshow in `branding.desc` can be configured with QML (recommended,
as it has been for the past umpteen releases) or with a list of
images (new).
- It is possible to turn off all the new QML code -- navigation, slideshow,
QML-based modules -- with a single `-DWITH_QML=OFF` at CMake time.
This removes QML from Calamares' dependency footprint (but only saves
200kB in Calamares itself).
- Tests have been extended and now support a tests/CMakeTests.txt file
for fine-tuning tests for Python modules.
- SPDX identifiers are used much more widely and consistently in Calamares.
(thanks Callum)
## Modules ##
- The QML based *welcomeq* module is now a viable alternative to the
*welcome*(widgets based) module. Using QML files means it no longer
is needed to have pop-up windows for additional information or warnings,
all loads in the Calamares window itself. Additional features include the
option to customize the *About* info and load files like Release Notes
direct into Calamares, QML files added to the branding directory can be used.
- The *welcome* and *locale* modules that do GeoIP lookup can now also
use "fixed" style; this just negates the GeoIP lookup and substitutes a
constant (fixed) value; useful for testing specific locales.
- The *keyboard* module no longer uses *ca_eng* keyboards in Canada by
default, but sticks to the *us* keyboard. #1419
# 3.2.24 (2020-05-11) #
This release contains contributions from (alphabetically by first name):
- Bill Auger
- Gaël PORTAY
- Luna Jernberg
- Philip Müller
## Core ##
- There is now a bash-completions script for Calamares; turn on
the (CMake-time) option INSTALL_COMPLETION to get it. (Thanks Gaël)
- The *productWallpaper* setting is documented and works. (Thanks Bill)
- GlobalStorage is available to QML modules as `Global`.
- The height of the navigation bar in QML can be set within the
QML code for the navigation; if not set, try something sensible.
- A regression in the requirements-checker which could block the
installer from proceeding without telling the user **why** it
was blocked, has been resolved.
## Modules ##
- The *bootloader* module can force a UEFI-based machine to boot into
the newly-installed system. #1394 (Thanks Gaël)
- *partition* Pop-ups about boot flags use the right flag names. #1192
# 3.2.23 (2020-04-17) #
This release contains contributions from (alphabetically by first name):
- FLVAL
## Core ##
- Some strange annotations were added to the *About* dialog text in
all the translations, like `{1?}`. These have been removed again.
## Modules ##
- *locale* module had some errors in timezone data, where clicking
on a city would select a different timezone. Some of these are
now fixed (thanks FLVAL). #1374
- *netinstall* supports a wider variety of package naming schemes,
and is more flexible in loading a `netinstall.yaml` that is copied from
the example configuration file, *groups* key and all. #1369
- *users* module logs a full error message from libpwquality if something
is wrong internally.
# 3.2.22 (2020-04-08) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Camilo Higuita
## Core ##
- Both the sidebar (on the left) and the navigation buttons (along the
bottom of the window) can now be configured to use the traditional
*widgets*, to use *qml*, or *hidden* from view (hiding the navigation
is not recommended unless you have a pure-QML UI to run inside
Calamares). The example QML that is compiled into Calamares has
been improved. To use your own QML, put files `calamares-sidebar.qml`
or `calamares-navigation.qml` into the branding directory.
- The sidebar and navigation can now be placed on any side of the
main window. This is probably only useful for QML-based UIs.
See `branding.desc` for details.
## Modules ##
- The *welcomeq* module has been improved with better layout and
nicer buttons in the example QML form. (Thanks to Anke Boersma)
- The *keyboardq* and *localeq* modules now provide some QML for
configuring these parts, although they are still very primitive.
- *netinstall* has had some minor layout fixes.
- *unpackfs* has much more detailed progress reporting and no
longer jumps around strangely in overall progress.
- *partition* now correctly marks a partition as bootable in BIOS + MBR
installs. #1175
# 3.2.21 (2020-03-27) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Camilo Higuita
- Gabriel Craciunescu
- Gaël PORTAY
## Core ##
- Python job modules (such as *unpackfs* or *packages*) can now provide
a `pretty_status_message()` function, like the existing `pretty_name()`
function, that is used to update the status during install. #1330
- QML support-modules and objects are now registered into the io.calamares
namespace. This affects modules using Calamares models inside their
QML UI (at this point, very few). With this release, the necessary
`import` for Calamares parts looks like
> ```import io.calamares.ui 1.0```
A complete list of objects available from Calamares van be found in the
documentation in `Qml.h`.
- The sidebar (which shows overall progress in the installation) is now
more configurable: the branding key *sidebar* controls it. The sidebar
can be shown as a widget (default, as it has been), hidden, or use a
new QML view which is more easily customised.
- A new `settings.conf` key *quit-at-end* will automatically close
Calamares (by clicking on the *Done* button) when the end of the
sequence is reached. If *finished* is the last module in the sequence,
this will run whatever it is configured for; you can also leave out
the finished page and Calamares will close after the exec parts.
## Modules ##
- *packages* now reports more details in the installation progress-bar.
- *netinstall* module supports an `expanded` key, which will pre-expand
a group (as if the user had pressed the arrow-button in the tree-view).
This only affects the UI, and only the **outermost** level of groups.
- *netinstall* module now supports a special value for *groupsUrl*.
Setting this to *local* will read the groups directly from the
configuration file.
- *netinstall* groups now support a new key `immutable` which prevents
their check-state from being changed (they are shown, or hidden,
as usual and can be expanded).
- Modules that use QML need a new import line. The QML file for the
module is configured through new keys *qmlSearch* and *qmlFilename*
(previously those were without the `qml` prefix, which invites name
collisions). The full module identifier is also used as a filename,
so that multiple instances of a module can use different QML files.
- *partition* module has a number of new features and settings for
type, UUID, and filesystem characteristics. Thanks to Gaël.
# 3.2.20 (2020-02-27) #
This release contains contributions from (alphabetically by first name):
- Bart Ribbers
## Core ##
- When logging level is set to 8 (eight), for instance via the `-D8`
logging flag, or the `-d` debug flag, the *Show debug information*
button will appear in the progress view. This helps with debugging
issues where the `-d` flag would be inappropriate.
- Calamares now starts at logging level 1 (warnings and errors to
the console) by default. Previously it (wrongly) started at level 8.
## Modules ##
- The *partition* module now stores which filesystems are in use in
global storage.
- The *contextualprocess* module now understands "compound variable
names", where a dot (.) is used to index into structured data
stored in global storage. This allows it to use the map stored
by the partition module (but also other things, like looking into
the branding information).
- The *packages* module now understands "apk", the Alpine Linux
package manager.
# 3.2.19.1 (2020-02-24) #
This is a hotfix release for bugs in the *users* module.
Reported by Philip Mueller and Walter Lapchynski.
## Modules ##
- The *users* module no longer wrote `/etc/hostname` at all.
- The *users* module erroneously shows the root password input fields.
- The *initramfs* module sets a resume-hook even when there is no swap.
- The partitioning service expects *udevadm* in `/sbin`, but some
distro's place it elsewhere.
- The mount service didn't unmount directories properly, leading to
blocked installations.
# 3.2.19 (2020-02-21) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Camilo Higuita
- Gabriel Craciunescu
## Core ##
- *Assamese* translation has been completed.
- Translations are now loaded from more places: instead of **only**
being compiled in to the Calamares executable, they can now be
read from the current directory (when Calamares is run in developer
mode) and from the application data directory.This allows updating the
translations without requiring a recompile: helpful for translators
and possibly for distributions with their own translation style.
See the translators and deployers wiki for details.
- A new `ViewStep` base class, `QmlViewStep`, has been added that loads
a configurable QML file and plays it. This is used by the new *notesqml*
module -- which is in itself a minimal wrapper around the same that
adds only a translatable module name.
## Modules ##
- The *machineid* and *users* modules now prefer high-quality random
data from `/dev/urandom` rather than pseudo-random data. #1254
- A new *notesqml* module supports loading QML. This can be used for
"fancy" release notes as a QML application, rather than a webview
or text widget. Note that this does not replace the slideshow-during-
installation module.
- The *users* module now has knobs for setting the hostname and writing
the `/etc/hosts` file. The new configuration options are documented
in `users.conf`. #1140
- Multiple *netinstall* modules can exist side-by-side, and they each
control the package installation for their part of the package list.
Previously, a netinstall module would overwrite all of the package
configuration done by other netinstall modules. Translations can be
provided in the configuration file, `netinstall.conf`. #1303
- The *fstab* module no longer "claims" all the swap partitions it finds
on disk. It only uses swap specified for the current installation.
This means that "replace" and "alongside" installations will have
no swap configured in the target system.
# 3.2.18 (2020-01-28) #
This release contains contributions from (alphabetically by first name):
- Bill Auger
## Core ##
- *Assamese* translation has been added (still in preliminary state).
- Timezone support code has migrated into the core of Calamares. This
means that modules now have easier access to timezone information.
Translations for timezones have also been enabled, so it is **possible**
at least to translate the displayed zones in the *locale* module.
- Branding can now specify whether to (try to) display the Calamares window
in the middle of the desktop or not. The *windowPlacement* key in
`branding.desc` specifies *center* or *free* placement.
## Modules ##
- All modules can now set a new key in `module.desc` called *noconfig*.
If this key is set to `true` (the default is `false), no configuration
file is searched-for or loaded, and no warning is printed if the
configuration is missing. This should tidy up some unnecessary warnings
on startup. #1302 #1301
- The *license* module has seen a significant change to its looks.
Actions are now labeled more clearly, and the URL (or filename)
for each license is displayed.
- The *locale* module now supports translations for timezone and
location names (e.g. "Berlin" is "Berlijn" in Dutch).
- *Packagechooser* is a little more careful with displaying
default and empty package names. (thanks to Bill Auger)
- The *unpackfs* module now carries a larger weight in the overall
progress of the installation, which should resolve downstream reports
like "progress stops at 24% for a long time". This is currently
hard-coded, but will become configurable in a future release. #1176
# 3.2.17.1 (2019-12-02) #
This is a hotfix release for a bug in the grubcfg module.
Reported by Philip Mueller and Erik Dubois.
## Modules ##
- The *grubcfg* module had a typo in it that made installations fail.
# 3.2.17 (2019-11-28) #
This release contains contributions from (alphabetically by first name):
- Bill Auger
## Core ##
- A translation "string freeze" is now enforced by the release scripts.
## Modules ##
- A new module, *hostinfo*, places information about the host into
Global Storage. This can support contextualprocess modules that
need that information.
- The password-checks in the *users* module are now ordered consistently.
A new check *nonempty* can be used to explicitly check for a non-empty
password. This was previously hard-coded. If you have no other
password-requirements set (e.g. minimum-length) and rely on
Calamares to filter out empty passwords, add this check.
- The *grubcfg* module has a new configuration setting *keepDistributor*
which prevents replacing the `GRUB_DISTRIBUTION` line when writing
the new configuration. #1201
- *packagechooser* documentation has been updated.
- *welcome* module now works better with dark themes.
- The *license* module could get into a confused state, now fixed. #1271
# 3.2.16 (2019-11-01) #
This release contains contributions from (alphabetically by first name):
- Bill Auger
## Core ##
- Some obscure build scenarios which would lead to bogus module-is-
misconfigured messages on startup have been resolved.
## Modules ##
- The explanatory messages on the *users* page have moved to tooltips,
and placeholder text has been added to the fields. #1202
- The bad-password messages in the *users* page have been improved. #1261
- Password-checking in the *users* module has been substantially
changed. A new key *allowWeakPasswords* can be used to introduce
an additional checkbox to the page, which can then be used to
switch off strict password checking. (Thanks to Bill Auger)
- The icons used in password warnings on the *users* page have been
changed to the colorful status icons (rather than the thin red X).
# 3.2.15 (2019-10-11) #
This release contains contributions from (alphabetically by first name):
- No other contributors this time around.
## Core ##
- No changes to core functionality
## Modules ##
- *displaymanager* module now treats *sysconfig* as a regular entry in the
*displaymanagers* list, and the *sysconfigSetup* key is used as a
shorthand to force **only** that entry in the list. #1253
- *machineid* module has been re-written in C++ and extended with
a new configuration key to generate urandom pool data. #1252
- *unpackfs* now supports a special *sourcefs* value of `file`
for copying single files (optionally with renaming) or directory
trees to the target system.
- *unpackfs* now support an *exclude* and *excludeFile* setting for
excluding particular files or patters from unpacking. #1229
# 3.2.14 (2019-09-30) #
This release contains contributions from (alphabetically by first name):
- Andrius Štikonas
- Harald Sitter
## Core ##
- No changes to core functionality
## Modules ##
- *locale* module no longer recognizes the legacy GeoIP configuration.
This has been deprecated since Calamares 3.2.8 and is now removed.
- *packagechooser* module can now be custom-labeled in the overall
progress (left-hand column). #1228
- *displaymanager* module now recognizes KDE Plasma 5.17.
- *displaymanager* module now can handle Wayland sessions and can detect
sessions from their .desktop files. #1247 #1248
- *unpackfs* now has special handling for *sourcefs* setting "file"
(so you can copy single files or directories that are on the source
system, directly to the target). #1188 #1181
# 3.2.13 (2019-08-30) #
This release contains contributions from (alphabetically by first name):
- Arnaud Ferraris
- Arnaud Rebillout
- Bill Auger
- Kevin Kofler
## Core ##
- The Calamares standard coding style -- embodied in `ci/calamaresstyle`
has had a few updates and has now been consistently applied across
the core codebase (e.g. libcalamares, libcalamaresui, calamares, but
not the modules).
- *KCoreAddons* is now a required dependency. This lets us drop a chunk
of code that was copied from KCoreAddons years ago, and use the
(maintained!) upstream version instead. It also gives us KMacroExpander
everywhere, which will simplify code for handling substitutions
in configuration files.
- *Slideshows* now have a new property *activatedInCalamares* which
controls the keyboard shortcuts (and can control timers and other
properties of the slideshow, too).
## Modules ##
- The *packagechooser* module can load data from the config-file,
from AppData XML files referred by the config-file, and (new) also
from AppStream caches by referring to an application's AppStream id. #1212
- The *partition* module now understands the units *KB*, *MB*, *GB* which
are powers-of-ten sizes, alongside the powers-of-two sizes that it already
used. (thanks to Arnaud)
- The *welcome* module now supports a *Donate* button if *showDonateUrl*
is set to a non-empty URL. #1197
- The *welcome* module can have URLs for the various buttons configured
directly in the module configuration (rather than in `branding.desc`).
# 3.2.12 (2019-08-07) #
This release contains contributions from (alphabetically by first name):
- apt-ghetto
- Bill Auger
- embar
## Core ##
- Preliminary work to allow jobs to have a *weight* assigned to them
has been added. This will allow the progress bar to better reflect
progress by the amount of work done rather than purely by the
number of jobs. (Thanks to Bill Auger)
- Preliminary work has been added to post the installation log to a
pastebin for bug reporting. (Thanks to Bill Auger)
- Support for translated human-readable strings in Calamares
config files has been added. This is used only in the *packagechooser*
module (see below) but will expand to those modules that need
user-visible strings from the configuration file (existing
solutions need either gettext or Qt support).
- Esperanto is now available when Qt version 5.12.2 or later is used.
## Modules ##
- *fstab* A new configuration key *efiMountOptions* has been added, to
allow setting filesystem options specifically for the EFI partition.
(Thanks to apt-ghetto)
- *packagechooser* is a new module for low-density package choices,
e.g. for selecting a default desktop environment, or adding some
proprietary drivers, or chosing browsers of office suites. It presents
**one** collection of items -- at most ten or so, because of the UI --
and the user can select zero or more of them. The behavior is
configurable, and package information can be set through the Calamares
configuration file or by reading AppData files for the packages. #426
# 3.2.11 (2019-07-06) #
This release contains contributions from (alphabetically by first name):
- No other contributors this time around.
This is a security release with no functional changes (except for
improved security) relative to 3.2.10. The Calamares team would like
to acknowledge the help of the following people in reporting and
understanding the issues (alphabetically by first name):
- Kevin Kofler
- Seth Arnold
- Simon Quigley
- Thomas Ward
Both CVE's have been resolved.
## Core ##
No core changes.
## Modules ##
- *initramfs* could create an initramfs with insecure permissions.
Since the keyfile is included in the initramfs, an attacker could
read the file from the initramfs. #1190 CVE-2019-13178
- *luksbootkeyfile* created a key file where a window of opportunity
existed where the key file could have too-lax file permissions.
#1191 CVE-2019-13179
# 3.2.10 (2019-06-28) #
This release contains contributions from (alphabetically by first name):
- No other contributors this time around.
Distributions are **advised** to check the slideshow they use for the
installation step; changes in loading and translation mechanisms may
require changes in the slideshow.
## Core ##
- With this release, option *WITH_PYTHONQT* changes default to **off**.
There does not seem to be any serious use of the PythonQt API and
the UI opportunities it offers, so begin the process of deprecating
and removing that. Sometime in the future, QML pages will fill the
gap for easily-prototyped-yet-slick UI elements.
- A crash when no *finished* page (or rather, no page at all) is
configured after the last *exec* section of the sequence has been
solved. The *finished* page can be left out (but then you don't get
the restart-now functionality). #1168
- The *slideshow* which is run during installation now has API versions.
API version 1 (the default) runs as before, where the slideshow is loaded
when the installation starts. API version 2 loads the slideshow on
Calamares startup, thus improving responsiveness. Documentation
in `src/branding/README.md`. #1152
- The example slideshow now uses API version 2.
## Modules ##
- *initramfs* has been changed from a Python module to a C++ module.
Packaging will need to adjust now it installs a .so instead of a .py.
The module itself functions as before. It does have a new configuration
option, to change the version passed as to the `-k` option of
update-initramfs. #1180
- *partition* Now has its own setting for *requiredStorage*, duplicating
the same setting in the *welcome* module. This is useful for
configurations where no *welcome* module is used, but a minimum
size must be checked anyway. #1169
# 3.2.9 (2019-06-03) #
This release contains contributions from (alphabetically by first name):
- Kevin Kofler
## Core ##
No user- or deployer-visible changes. Bugfixing as usual, see the
milestone for details.
## Modules ##
- *branding* now supports os-release variables in the *strings* section,
which allows re-using (at runtime) information set in /etc/os-release .
This requires KDE Frameworks 5.58. #1150
- *branding* allows the use of FreeDesktop.org icon names for the
*productLogo* and *productIcon* keys. If a file is named there, then
the file is used, and otherwise the icon is looked up in the current
theme. #1160
- *packages* On Arch, with the `pacman` package manager, avoid a hang
during system update. #1154
- *welcome* allows a custom image path or icon name to be set for the
language-selection drop-down (instead of the international standard one).
# 3.2.8 (2019-05-10) #
This is a **source-incompatible** release of Calamares. Include files
have been shuffled around, so third-party C++ modules will need
adjustment to the changed names.
This release contains contributions from (alphabetically by first name):
- Arnaud Ferraris
- Kevin Kofler
## Core ##
- All user-visible texts referring to "MB" and "GB" now use the standard
"MiB" and "GiB" wording, which matches what we were actually calculating
with (i.e. 2^20 and 2^30 respectively). #1129
- The side-pane, which shows the list of steps that will be executed,
now tries to fit the text (name of each module) into the available space
by shrinking the font as needed. #1137
- *libcalamares* (accidentally) linked with Qt's GUI libraries when
PythonQt was found. This led to the odd situation where the non-GUI
Calamares library depends on a bunch of GUI libraries.
- *libcalamares* The `utils/` subdirectory has been hugely refactored,
with functionality split out into separate files. C++ modules will
need to have their `#include` names updated. Basically, users of
`utils/CalamaresUtils.h` will need to include the header file for
the functionality that is actually used.
## Modules ##
- *finished* has a new mechanism for configuring the behavior of the
*restart now* button. The old-style boolean configuration is still
supported but generates a warning. #1138
- *locale* module GeoIP configuration has a new preferred format.
See `locale.conf` for details. The old configuration is still
supported but will be phased out before 3.3.0 -- in particular,
support for "legacy" format will be removed, since that was a
crutch for the disappearance of one GeoIP provider in 2018.
- *oemid* is a new module for configuring OEM phase-0 (image pre-mastering,
or pre-deployment) things. It has limited functionality at the moment,
writing only a single batch-identifier file. #943
- *welcome* can now do GeoIP lookups as well (but be careful with the
configuration, since you need a GeoIP that provides country information,
not just timezones). This will let Calamares select a starting language
that matches where it is -- which might not be useful at all. #934
- All Python modules now bail out gracefully on (at least some) bad
configurations, rather than raising an exception. The pre-release
scripts now test for exceptions to avoid shipping modules with
ImportError or SyntaxError results.
# 3.2.7 (2019-04-27) #
This is a **hotfix** release for regressions introduced in the
Python modules. The *localecfg* module was unusable because of
a missing `import`.
# 3.2.6 (2019-04-25) #
This release contains contributions from (alphabetically by first name):
- Arnaud Ferraris
- Dominic Hayes (feren)
- Raul Rodrigo Segura (raurodse)
## Core ##
* Under-the-hood code cleanups in lots of parts of the core. Calamares now
builds without warnings when Clang 8 is used.
* A new *disable-cancel-during-exec* setting provides more fine-grained
control than *disable-cancel*, which hides the button entirely.
#1122 (Thanks to Dominic, FerenOS)
* A branding module can now also cause a stylesheet to be loaded, which
will be applied to the widgets inside Calamares. #961 (Thanks to Raul)
## Modules ##
* All of the Python-based modules now have translations enabled. #991
* *Displaymanager* module has improved support for LightDM configuration.
#1123 (Thanks to Dominic, FerenOS)
* *License* module can now display local files inline, and scrolls to
allow longer lists of licenses and to support long license texts
displayed inline. #1124 #1125 #1052
* *Partition* module has additional checks for validity partition layouts.
#1127 (Thanks to Arnaud)
* *Welcome* module has improved usability: a standard icon
alongside the *Language* label, for improved recognition,
and improved language-list display and sorting. #1107
# 3.2.5 (2019-04-15) #
This release contains contributions from (alphabetically by first name):
- Arnaud Ferraris
- Dan Simmons
- Gabriel Craciunescu
## Core ##
* View modules (in C++) can now perform their own requirements-checking
to see if installation makes sense. This expands upon the existing
requirements checks in the welcome module (RAM, disk space, ..).
The checks have been made asynchronous, so that responsiveness during
requirements-checking is improved and the user has better feedback.
* Support for building an AppImage of Calamares has been added to the
`ci/` directory. There are use-cases where a containerized build and
configuration make sense rather than having Calamares installed in the
host system. (Thanks to the AppImage team, Alexis)
* OEM mode (phase-1) now correctly refers to Calamares as a "Setup Program"
rather than an installer. #1100 (Thanks to Arnaud)
## Modules ##
* *Bootloader* module: a serious bug introduced in 3.2.4 which prevents
succesful boot after installation on EFI machines, has been repaired.
(Thanks to Gabriel) #1104
* *Displaymanager* module: it is no longer a fatal error to not have any
display-managers. #1095
* *Partition* module: it is now possible to build without libparted. Since
KPMCore may not need this library anymore, it is a dependency that will
be dropped as soon as it is feasible. Add this to the CMake flags:
`-DCMAKE_DISABLE_FIND_PACKAGE_LIBPARTED=ON`
* *Partition* module: the location that is selected for the bootloader,
no longer changes when a new partition is created. #1098
* Python modules: several modules have had translations added. This is
usually only visible when the module runs as part of the *exec* step,
when the module's *pretty name* is displayed. In addition, some error
messages are now translated.
* *UnpackFS* module: improved progress reporting and tests. #565
# 3.2.4 (2019-02-12) #
This release contains contributions from (alphabetically by first name):
- Alf Gaida
- aliveafter1000
- Arnaud Ferraris
- Caio Jordão Carvalho
- Collabora LTD
- Gabriel Craciunescu
- Kevin Kofler
- Philip Mueller
- Scott Harvey
## Core ##
* The Calamares application now recognizes the `-X` or `--xdg-config`
option, which adds XDG_DATA_DIRS to the places used to find QML
and branding directories, and XDG_CONFIG_DIRS to the places used
to find the global settings and module configurations. This allows
a more fine-grained, and more layered, approach to setting up
Calamares configurations (in particular, distro's can **add**
configuration files and give them priority, instead of **forking**
configuration files).
* The *branding* file now contains settings that control the size
and resize behavior of Calamares. See the branding file for
more documentation. In particular, the setting *windowExpanding*
can be set to *normal*, *fullscreen* or *noexpand*.
* The `settings.conf` file can now configure whether the *Cancel* button
is shown (this isn't a branding thing, because it's quite fundamental
to the workflow of the installer).
## Modules ##
* The *partition* module supports RAID devices, but only when Calamares
is compiled with the newest KPMCore release (3.3.0).
* The calculation of required space -- including swap -- has been simplified,
and Calamares no longer reserves 2GiB of space in calculations for internal
use (this means that it no longer mysteriously drops swap when the disk
size is close to the required installation size).
* The name of the type of default filesystem (e.g. ext4 or btrfs) is now handled
case- and localization-insensitively. This means that *btrfs* is now always
an acceptable spelling.
* The currently-selected disk device is remembered between manual partitioning
and the partitioning-overview pages. (Thanks to Arnaud)
* *partition* There is new support for partitioning layout presets.
See `partition.conf` for documentation and details.
* The *keyboard* module now handles the (bogus) Austrian keymap for
the system console properly. (Thanks to Kevin)
* The *preservefiles* module now has a mechanism for setting the permissions
(and ownership) of preserved files. (Thanks to Scott)
* New module *fsresizer* can be used to resize filesystems. It is intended
for use in OEM installs where an image of fixed size is created,
and then sized to the actual SD card the user has used.
* The *mount* module now handles missing *extraMounts* and *extraMountsEfi*
keys gracefully (this is probably a misconfiguration, though, and gives a
warning).
* The *packages* module now supports pre- and post-script options
for all operations, not just during install (keep in mind that
these run as three separate shells, though).
* A new *rawfs* module supports straightforward copying of filesystems from
the installation media to the target stystem. This can be used, for instance,
for block-level-identical installations.
# 3.2.3 (2019-01-09) #
This release contains contributions from (alphabetically by first name):
- aliveafter1000
## Core ##
There are no core changes in this release.
## Modules ##
* *partition* Fixed bug where, during detection of existing systems, the
existing system partitions may be mounted and then files deleted.
This is a **limited** version of the patch from aliveafter1000
that will be in 3.2.4, which tries harder to mount filesystems
read-only and unmodifiable.
* *locale* It was possible to set the installer and system language
(e.g. to German) while the global storage value for *locale*
remained set to English. Then no localization packages are installed
(see feature `${LOCALE}` in `packages.conf`). Reported downstream
in Netrunner.
# 3.2.2 (2018-09-04) #
This release contains contributions from (alphabetically by first name):
- Andrius Štikonas
- artoo@cromnix.org
- Caio Jordão Carvalho
- Harald Sitter
- Philip Müller
- Simon Quigley
- Walter Lapchynski
## Core ##
* Example configurations are **no longer installed** by default.
The default setting for *INSTALL_CONFIG* has changed. Distributions
are strongly encouraged to write their own configuration files and
not rely on the example configuration files. Example configurations
may change unpredictably.
* It is now possible to express module dependencies through the
*requiredModules* key in `module.desc`. All of the required modules
for a given module must occur in the sequence **before** the module
requiring them. None of the core modules use this facility.
* The search paths for QML files, branding descriptors and module
descriptors have been revamped and now self-document in the log.
* A new `ci/RELEASE.sh` script has been added to streamline releases;
it is not guaranteed to work anywhere in particular though.
## Modules ##
* When multiple modules are mutually exclusive, or don't make sense
to enable concurrectly, a new `USE_<foo>` framework has been added
to CMake to simplify the selection of modules. This is in addition
to the existing `SKIP_MODULES` mechanism.
* Various off-by-one-sector errors in the automatic partitioning
mode have been corrected. In addition, swap space is calculated
a little more conservatively.
* A new module has been added to the core which can configure openrc
services. To make services configuration consistent:
- The *services* module has been **renamed** *services-systemd*,
- The openrc module is named *services-openrc*,
- At CMake time, it is possible to select all of the services modules,
or one specific one, by setting the *USE_services* CMake variable.
By default, all of the modules are built and installed.
* The systemd-services module can now disable targets and mask both
targets and services (which will allow you to break the system with
a bad configuration). The configuration is a little more flexible
because a service (or target) name can be used on its own with
sensible defaults.
* The displaymanager module has been entirely revamped. A long-standing
bug which ignored the settings for default desktop has been fixed
(thanks to Walter Lapchynski). Translations have been added to the
error messages. Each DM now has an implementation class for doing
all the configuration steps it needs. This groups the code needed for
a specific DM (and presumably, per-distro) in one place.
Distro's are **strongly advised** to re-test their DM configuration
and installation with the revamped code.
# 3.2.1 (2018-06-25) #
This release contains contributions from (alphabetically by first name):
- Bill Auguer
- Gabriel Craciunescu
- Phil Mueller
- Raul Rodrigo Segura
## Core ##
* Qt 5.7 is now the minimum required Qt version. Because KPMCore
(a fairly fundamental dependency) requires Qt 5.7, Calamares
has followed suit.
* New testing application `loadmodule` for loading and running a
single Calamares module.
* New translations Belarussian and Korean.
* Jobs can now be *emergency jobs* which run even after a failure.
* Improved debugging when modules fail to load.
* Bad configuration files will now cause the user-interface of
Calamares to display an error message, rather than silently
ignoring some configuration errors. This will certainly cause
problems for distributions with sloppy configurations.
## Modules ##
* New module preservefiles, keeps (log) files around after install;
this duplicates functionality with the unmount module, but unmount
is very late, rather limited, and fragile.
* Interactiveterminal module now disables itself if build requirements
are not met, rather than blocking the build.
* Fixes in the timezone map data make the southern hemisphere more
usable and put Reykjavik in its place.
* The packages module can now update the target system if explicitly
told to do so.
* More paths and executables are configurable in the bootloader module.
* Distributions are advised to review the `users.conf` setup **again**,
as some changes in version 3.2.0 caused regressions downstream.
* Distributions are advised to review their `locale.gen` files
**again**. Previous changes were too restrictive, matching only
the specific format Chakra Linux uses. Calamares now preserves
all the comment-lines in the file and writes enabled locales
at the end, with a descriptive comment.
# 3.2.0 (2018-05-17) #
This release contains contributions from (alphabetically by first name):
- Alf Gaida
- AlmAck
- Caio Jordão Carvalho
- Frede H
## Modules ##
* UI annoyances in the partitioning module were fixed; the
mount-point selector is now more obvious when no mount-point
has been chosen, and the mount-point and flags are preserved
when (re)editing partitions.
* The handling of `@@ROOT@@` substitution in shellprocesses was
backwards; this has been fixed (the substitution is made when
running in the **host**).
* The user shell is no longer hard-coded to `/bin/bash`,
but follows the default setting for useradd(8), e.g.
those set in `/etc/default/useradd`.
<!-- SPDX-FileCopyrightText: no
SPDX-License-Identifier: CC0-1.0
-->
This is the changelog for Calamares. For each release, the major changes and
contributors are listed. Note that Calamares does not have a historical
changelog -- this log starts with version 3.3.0. See CHANGES-3.2 for
the history of the 3.2 series (2018-05 - 2022-08).
# 3.3.15 (unreleased)
This release contains contributions from (alphabetically by given name):
- Nobody yet!
## Core ##
- Nothing yet!
## Modules ##
- Nothing yet!
# 3.3.14 (2024-02-20)
This release contains contributions from (alphabetically by given name):
- Adriaan de Groot
- Evan James
- TNE
- vincent PENVERN
## Core ##
- The Python bindings have been re-organized (source) and made more
consistent. At least one valid Python program would work with
the Boost::Python bindings, but not the pybind11 bindings. A
memory-corruption problem in the Boost::Python bindings was resolved.
- Steps in the UI now have a hook to undo any changes they have made
to the live system, if the user cancels the installation.
## Modules ##
- *keyboard* module undoes changes to the keyboard layout if the
user cancels the installation (returning the system to whatever
layout was in use when Calamares started). (#2377, #2431)
- *locale* module undoes changes to the timezone. (#2377, #2431)
- *partition* module stores a global storage value in luksPassphrase,
for later modules that need to manipulate the encrypted partition.
(thanks vincent, #2424)
- *partition* module no longer clear (unmounts) a Ventoy device.
(thanks TNE, #2427)
- *partition* module has configurable exceptions for the clear-mounts
(unmount) job, which always includes Ventoy.
# 3.3.13 (2024-12-31)
This release contains contributions from (alphabetically by given name):
- Aaron Rainbolt
- Adriaan de Groot
- Anke Boersma
- Ching Hsü
- Jakob Petsovits
- Masato TOYOSHIMA
- Simon Quigley
- Vladyslav Prudius
## Core ##
- Fewer compile warnings with most-recent Qt versions.
- Support systemd and consolekit block-suspend, not just KDE Plasma
block-suspend, during installation. (thanks Jakob, #2404)
## Modules ##
- *dracut* module has more freedom to specify program options. (thanks Simon, #2401)
- *partition* module improved some user-visible messages. (thanks Masato, #2412)
- *partition* module re-scans available devices when selecting
"manual" partitioning mode, avoiding a crash. (thanks Masato, #2414)
- *partition* module can hide the LVM buttons during manual partitioning,
if the distro does not want to support LVM. (#2413)
- *partition* module can restrict what filesystems a user applies where,
e.g. ensuring EFI is a FAT32 partition. (thanks Aaron, #2400)
- *unpackfs* module supports skipping installation media if it
is not present, e.g. depending on how the live media is booted.
(thanks Simon, #2410)
## Translations ##
Calamares translations are usually done through Transifex, but
some users provide translation updates via patches, instead.
- *uk* thanks Vladyslav Prudius
- *zh_CN* thanks Ching Hsü
# 3.3.12 (2024-11-21)
This release contains contributions from (alphabetically by given name):
- Adriaan de Groot
## Core ##
- This release repairs the Calamares configuration file which is
used by external Calamares modules -- calamares-extensions in particular.
## Modules ##
- *users* module always uses a 3-digit UMASK if one is specified.
# 3.3.11 (2024-11-05)
This release contains contributions from (alphabetically by given name):
- Adriaan de Groot
- Jakob Petsovits
- Simon Quigley
## Core ##
- Nothing yet
## Modules ##
- *unpackfs* now supports a `condition` configuration option for
conditional installation / unsquash. (thanks Simon)
- *unpackfsc* module imported from Calamares-extensions, and extended
with the same `condition` configuration.
- *partition* crash fixed when swap was using the wrong end-sector
in some GPT configurations. (thanks Jakob, #2367)
# 3.3.10 (2024-10-21)
This release contains contributions from (alphabetically by given name):
- Aaron Rainbolt
- Adriaan de Groot
- Evan James
- Neal Gompa
## Core ##
- Nothing yet
## Modules ##
- *keyboard* Repaired summary messages with strange formatting. (#2364)
- *keyboard* Can update KDE Plasma configuration in Wayland. (thanks Neal, #2264)
- *locale* Repaired summary messages with strange formatting. (#2364)
- *partition* Module fixed unwanted behavior with the encryption checkbox. (thanks Aaron, #2376)
- *umount* Correctly unmounts the root filesystem of the target. (thanks Evan)
- *users* Supports a new `home_permissions` setting to override the
distro's `useradd` configuration of the umask. Supports octal and rwx-style
specifications of permissions. Other places that use permissions now also
support octal and rwx-style. (#2362)
- *welcome* Follows system styling colors (e.g. Dark Mode).
# 3.3.9 (2024-08-12)
Please note that if you are using the *luksbootkeyfile* module,
it must be placed before the *fstab* module in settings.conf. If it comes
after, then the keyfile will be missing from crypttab and the user will be
asked for their password multiple times.
This release contains contributions from (alphabetically by given name):
- Adriaan de Groot
- Evan James
- Luca Matei Pintilie
## Core ##
- Improved schemas for configuration files
- Support for Interlingue in Qt 6.7
## Modules ##
- Placed *luksbootkeyfile* before *fstab* in the example `settings.conf` (#2356, Evan)
- *packages* module `xbcs` package manager now logs progress messages (#2359, Luca)
- *partition* module mentions creating a swap file in its summary (#2320, Adriaan)
# 3.3.8 (2024-07-02)
The *partition* bug described below was reported by jghodd, then carefully
described and made reproducible by Joe Kamprad, examined by Evan James
and repaired by Adriaan de Groot. Many thanks to all who participated.
This release contains contributions from (alphabetically by first name):
- Adriaan de Groot
- Evan James
- Lorenzo Faletra
- Tj
- Victor Fuentes
## Core ##
- nothing in particular
## Modules ##
- *contextualprocess* see *shellprocess*.
- *mount* module now correctly mounts luks and luks2-encrypted swap. (thanks Victor)
- *partition* avoids a crash with specific checkbox-presets. (thanks Evan)
- *partition* had a bug where manual partitioning on MBR systems might
skip the installation of a bootloader, even though the visible bootloader
combo-box showed that it would be installed. (see #2318)
- *partition* could calculate an incorrect partition size when installing to
very specific partition sizes, and now leaves a few more sectors for secondary
GPT tables. (thanks Tj)
- *shellprocess* now supports a *verbose* key (globally and per-command) which logs
command output line-by-line.
- *users* module defaults password salt to *yescrypt*. (thanks Lorenzo)
# 3.3.7 (2024-06-20)
This release contains contributions from (alphabetically by first name):
- Adriaan de Groot
- Eugene San
- Evan James
- Ivan Borzenkov
- Sohrab Behdani
- Vincent Penvern
- Vladislav Nepogodin
## Core ##
- Updated clang-formatting
- Some C++20 future-proofing (thanks Vladislav)
- CommandList (used by *contextualprocess* and *shellprocess*) now supports
globalstorage keys as substitutable variables.
## Modules ##
- *contextualprocess* see *shellprocess*.
- *fstab* module does not add an encryption keyfile if it does
not exist. (thanks Eugene)
- *initcpiocfg* has some new configuration settings to more carefully
adjust hooks for initcpio.
- *keyboard* module handles Persian (fa) layout better. (thanks Sohrab)
- *keyboard* module handles other non-ascii layout better. (thanks Ivan)
- *partition* module did not filter out invalid fstab entries;
they were not written, either, so no net change.
- *partition* module now has a configurable default check-state
for the encryption checkbox. (thanks Vincent)
- *shellprocess* commands now support globalstorage variables, which
are written as `${gs[key]}`, where `key` is a dotted string that
selects the globalstorage key to use (like in *contextualprocess*
variable-selectors) and `${gs[` and `]}` are literal characters.
# 3.3.6 (2024-04-16)
This release contains contributions from (alphabetically by first name):
- Adriaan de Groot
- Anke Boersma
- Eugene San
- Evan James
- Harald Sitter
- Mike Stemle
- Peter Jung
- Simon Quigley
## Core ##
- Various Qt6-related fixes.
- Calamares now prevents sleep and suspend while the installation is
running, so that unattended installs do not accidentally fall asleep.
## Modules ##
- *bootloader* Adds "splash" to kernel parameters if plymouth is present.
(thanks Eugene)
- *locale* Now picks the correct timezone for Dubai, Muscat, Tehran.
- *plymouthcfg* Use plymouth-set-default-theme to avoid issues with
configuration. (thanks Peter)
- *users* module now supports enrolling in Active Directory, if enabled.
(thanks Simon)
# 3.3.5 (2024-03-03)
This release contains contributions from (alphabetically by first name):
- Adriaan de Groot
- Evan James
- Peter Jung
## Core ##
- Calamares logs more information about how the executable was created
in the session log on startup. This will help in recreating the specific
configuration when bug reports are filed. (thanks Evan)
- The debug window now has better Qt6 compatibility.
## Modules ##
- *displaymanager* module can configure an alternate SDDM configuration file.
- *networkcfg* a bug affecting NetPlan + NetworkManager was fixed.
- *initcpiocfg* Add microcode hook to initcpiocfg
# 3.3.4 (2024-02-27)
In this release, process jobmodules -- a particular kind of module
recognizable by `type: job` and `interface: process` in the descriptor
file -- undergo a large change to resemble *shellprocess* more.
Users of process jobmodules are encouraged to double-check the Functionality
of those modules in this release.
This release contains contributions from (alphabetically by first name):
- Adriaan de Groot
- Victor Fuentes
## Core ##
- Process jobs (a job type provided by Calamares core) now share more
code with *contextualprocess* and *shellprocess* jobs. The execution
mechanism is the same, and always invokes the shell, whether the command
runs in the host or in the target system. It is no longer necessary to
add `/bin/sh` in the *command* key -- this is always present.
## Modules ##
- *contextualprocess* and *shellprocess* can now set environment variables
as part of the configuration. See *shellprocess* documentation for details.
This is optional, and does not do anything that could not already be done
by putting `export VAR=value ;` in front of the command before.
- *partition* fixed a bug with an uninitialized variable. (thanks Victor)
- *shellprocess* (and therefore also *contextualprocess* and process
jobmodules) now substitutes `${LANG}` in commands with the language
selected in the user-interface of Calamares.
# 3.3.3 (2024-02-24)
This release contains contributions from (alphabetically by first name):
- Adriaan de Groot
- Anke Boersma
Translations have been updated (3.3.2 skipped that step).
## Core ##
- Core libraries *libcalamares* and *libcalamaresui* now build with
hidden visibility by default, as a step towards ABI stability.
- A runtime crash caused by (mis?)use of Qt UniqueConnection which
shows up in Debug builds was resolved.
## Modules ##
- *interactiveterminal* can use konsole in Qt6 too. (thanks Anke)
- *plasmalnf* module ported to Plasma 6. (thanks Anke)
- *welcomeq* example extended to include Markdown syntax. (thanks Anke)
# 3.3.2 (2024-02-19)
This release contains contributions from (alphabetically by first name):
- Aaron Rainbolt
- Adriaan de Groot
- Anke Boersma
- Evan James
- Jonathan Riddell
- Lukas Märdian
- Tj
## Core ##
- Slideshow support code (QML) now ported to Qt6 and made available
as two separate directories of support-code. (thanks Jon)
- Compatibility with Qt versions prior to 5.15.5 has been removed.
## Modules ##
- *fstab* bug fixed where BTRFS messes up the partition layout. (thanks Tj)
- *networkcfg* on NetPlan-enabled systems, configure NetworkManager
with the live-system's NetPlan settings. (thanks Lukas)
- *partition* module can now also define unencrypted partitions
when encryption is used. (thanks Aaron)
# 3.3.1 (2024-01-15)
This release sets `BUILD_APPDATA` and `BUILD_APSTREAM` to default to **OFF**,
where previously they defaulted to **ON**. When enabled, the dependencies for
both features are required -- previously they would silently switch off if
the dependencies were not found. Distributions are strongly advised to check
their package-building instructions.
This release contains contributions from (alphabetically by first name):
- Adriaan de Groot
- Aleksey Samoilov
- Emir Sari
- Simon Quigley
## Core ##
- There has been internal code re-organization (e.g. not using functions
named `tr()`) to help translation tools.
- Strings everywhere have been given more context. (thanks Emir)
- In CMake, "view" is no longer accepted as an alias of the module
type "viewmodule" in function `calamares_add_plugin()`.
- Plain Ubuntu builds have been added to the CI roster. (thanks Simon)
- Commands that run in the target system (in the chroot) no longer
use the TMP-related environment variables from the host. #2269
## Modules ##
- The *displaymanager* module configuration for `greetd` has some more
options now. (thanks Aleksey)
# 3.3.0 (2023-12-12)
This release contains contributions from (alphabetically by first name):
- Adriaan de Groot
- Alberto Salvia Novella
- Christophe Marin
- Evan Maddock
- Frede Hundewadt
Since this is the first non-alpha release of 3.3.0, we would like to thank
all the contributors to a year and a half of alpha releases, six in all.
Distributions are **strongly** advices to take the release notes of
the alpha's into account as well.
## Core ##
- No changes of note.
## Modules ##
- *users* and *usersq* no longer support the password requirement 'nonempty'.
Use 'minLength: 1' instead. The example configuration allows the user to
choose any password at all, but also contains suggestions for other
password-requirements schemes. (thanks Alberto)
- *users* now can use stronger password hashes, if `crypt_gensalt()` is
available in the *crypt* library. (thanks Evan)
- *machineid* module supports several variations of writing /etc/machine-id .
# 3.3.0-alpha6 (2023-11-16)
This release contains contributions from (alphabetically by first name):
- Adriaan de Groot
- Anke Boersma
This is a hotfix release because -alpha5 didn't compile,
and Anke repaired the partition unit-tests when building with Qt6.
# 3.3.0-alpha5 (2023-11-13)
This release contains contributions from (alphabetically by first name):
- Adriaan de Groot
- Alejo Fernandez
- Anke Boersma
- Christophe Marin
- Emir Sari
- Evan James
- Gaël PORTAY
- Gecko Linux
- Jeremy Whiting
- Neal Gompa
## Core ##
- Boost::Python is no longer a dependency, Calamares uses a bundled copy
of pybind11 instead. This speeds up compilation and reducese the
dependency tree a great deal. You can set `WITH_PYBIND11=OFF` in the
build to keep Boost::Python and all the binary-compatibility problems
it entails.
- Coding style now wants clang-format 15 or 16, but no longer needs astyle.
There is also a clang-tidy file for additional styling support.
- Ongoing translation improvements. (thanks Emir)
- Translations for bqi (Luri), es_AR (Castellano), eo (Esperanto),
ka (Georgian). In **non-release** builds (e.g. between releases,
so for developers building directly from git) all translations are
enabled, even the ones with no translations at all.
- The logging format in the `session.log` file and on-screen is now
more similar, although the file contains a lot more per-line information.
- The INSTALL_CONFIG option has been restored. It is still a terrible
idea to fork the repository to modify the config files, and you
probably should have a calamares-config package with those files
instead, there are packaging workflows that can usefully patch-and-
install configuration files. The option defaults to OFF.
## Modules ##
- All QML modules now have a Qt6-compatible set of QML files as well. (thanks Anke)
- *packagechooser* supports AppStream 1.0 API.
- *unpackfs* now uses the `-S` option to rsync for sparse file support. (thanks Jeremy)
# 3.3.0-alpha4 (2023-10-13)
Another closing-in-on-3.3.0 release! One of the big changes is that
Calamares -- the core and nearly all of the modules in this repository --
are compatible with Qt6. That is, it compiles. Functionality has not
been tested, but early-testing distributions are encouraged to submit
pull requests to improve the code.
This release contains contributions from (alphabetically by first name):
- Adriaan de Groot
- Anke Boersma
- Emir Sari
- Evan James
- Hector Martin
- Ivan Borzenkov
- Simon Quigley
## Core ##
- Qt6 compatibility. You can choose Qt5 (with KDE Frameworks 5) as before,
or choose Qt6 (with KDE Frameworks 6). This means that a Qt6-based Linux
distribution can use Calamares without needing an extra version of Qt.
Note that some KDE Frameworks are required as well, and those need to be
Qt6-based also (and are not released as of September 2023).
- QML-based modules are also supported in Qt6, but the QML is likely to
be source-incompatible. The *welcomeq* module shipped with Calamares
now has two `.qrc` files and uses the `${QT_VERSION_SUFFIX}` variable
to pick one of the two depending on the Qt version being used.
Other modules are likely to follow the same pattern.
- C++ namespaces have been shuffled around and `CalamaresUtils` has been
retired. This has an effect on all C++ plugins, since this is neither
a binary- nor source-compatible change.
## Modules ##
- *keyboard* module can now be explicitly configured to use X11 keyboard
settings or the FreeDesktop locale1 DBus service. The latter is most
useful for Calamares as an "initial setup" system, not an installer,
in a Wayland session. (thanks Hector)
- *keyboard* module now writes X11 layout configuration with variants
for all non-ASCII (e.g. us) layouts. (thanks Ivan)
- *keyboard* module now can configure keyboard switch. (thanks Ivan)
# 3.3.0-alpha3 (2023-08-28)
This release contains contributions from (alphabetically by first name):
- Adriaan de Groot
- Aleksey Samoilov
- Anke Boersma
- Arjen Balfoort
- Boria138
- Brian Morison
- Emir Sari
- Evan Goode
- Evan James
- Ficelloo
- Hector Martin
- Jeremy Attall
- Johannes Kamprad
- Kasta Hashemi
- Kevin Kofler
- Mario Haustein
- Masato TOYOSHIMA
- Panda
- Paolo Dongilli
- Peter Jung
- Philip Müller
- Shivanand
- Sławomir Lach
- Sunderland93
- wiz64
## Core ##
- Incompatible module-configuration changes, see #1438.
- Branding entries use ${var} instead of @{var} for substitutions,
in line with all the other substitution mechanisms used from C++
core. See documentation in `branding.desc`.
- Boost::Python requires at least version 1.72.
- KDE Frameworks must be version 5.58 or later.
- The `INSTALL_CONFIG` option has been removed. If you are installing
the example configuration files from the Calamares repository, just
stop. That was never a good idea, and you should keep your configs elsewhere.
- Progress percentage during install can now be localized. (thanks Emir)
## Modules ##
- *dracut* added a configurable kernel name. (thanks Anke)
- *initcpiocfg* orders hookds slightly differently. (thanks Peter)
- *localeq* moved to using Drawer instead of ComboBox in UI. (thanks Anke)
- *keyboardq* moved to using Drawer instead of ComboBox in UI. (thanks Anke)
- *netinstall* now has a new *noncheckable* option for groups, which prevent
it a group from being checked/uncheckd as a whole. You can still check
individual items **in** the group though. (thanks Shivanand)
- *partition* can now pick LUKS or LUKS2. (thanks Jeremy)
- *zfs* creates a hostid through zgenhostid.
- *zfshostid* new module to copy zfs generated /etc/hostid
# 3.3.0-alpha2 (2022-08-23)
Second alpha release, with updated ABI compatibility checking,
some 3.3.0 release goals, new features in modules and important bugfixes.
This release contains contributions from (alphabetically by first name):
- Adriaan de Groot
- Anke Boersma
- Evan James
- Shivanand
- Vitor Lopes
## Core ##
A core **TODO** is moving all library code into the `Calamares` namespace,
dropping the `CalamaresUtils` namespace. Modern C++ supports nested namespaces,
so in some cases we can use those. This has a drastic effect on ABI compatibility,
though, as functions move from one namespace to another. This needs to be
completed before a 3.3.0 with ABI stability is released.
## Modules ##
Module schemas have been updated to reflect all the incompatible changes.
# 3.3.0-alpha1 (2022-06-27)
Initial 3.3.0 alpha release to check the release scripts &c.
This release contains contributions from (alphabetically by first name):
- Adriaan de Groot
- Aleksey Samoilov
- Anke Boersma
- Dan Simmons
- Evan James
- Peter Jung
# 3.3.0-pre-alpha (unreleased) #
This release contains contributions from (alphabetically by first name):
- Anke Boersma
- Anubhav Choudhary
- Evan James
- Vitor Lopes
This is a "minor" version change, but the size of the changes is very
large. Configuration files from previous versions of Calamares will
**certainly** need to be re-validated. Take heed of the many changes
in the *Modules* heading, below.
Users (distributions) are **strongly** advised to use the tools
for configuration validation (`ci/configvalidator.py`) to check
that the distribution configuration files follow the current schema.
## Project ##
- The C++ code in the project is now formatted with clang-format 12 or 13,
with the coding-style as found in `.clang-format`; there are minor
differences from the tool, compared to the clang-format 9 usually applied
to Calamares 3.2.
- The CMake code in the project is now formatted with gersemi 0.7.5.
## Core ##
- CMake 3.16, Qt 5.15 are now required; the newer CMake is to support
new features (also for KDE Frameworks), Qt is the current LTS version.
- Running `calamares -d` no longer enforces a single-application
(it is for debugging purposes, after all).
- Python 3.6 or later is now required, to allow for F-strings in
Python code and allow other tidy-ups in the Python modules.
Boost::Python now requires 1.67 or later (for CMake support).
- The log file now **always** contains a debug-log, and the `-D` flag
primarily controls what is printed to stdout. By default, stdout
only gets errors; use `-D6` to match stdout with the file. Use `-D8`
to get an extra-verbose log file **and** verbose stdout.
## Modules ##
- *bootloader* now supports more options when building the kernel
command-line. (Thanks Evan)
- *bootloader* no longer supports `@@`-style suffixes for unique-EFI-id
generation. Use `${}` instead.
- *displaymanager* no longer supports the discontinued *kdm* display manager.
- *fstab* configuration has been completely re-done. Many configuration
options have moved to the *mount* module. See #1993
- *grubcfg* changed the key *keepDistributor* to *keep_distributor*.
Please update configurations.
- *mount* now does most of the mounting; options that were in *fstab*
have moved here. See #1993
- *oemid* now uses consistent variable replacement (e.g. KMacroExpander)
and does not support `@@DATE@@` anymore (use `${DATE}`).
- *partition* requires KPMCore 21.12 (e.g. KPMCore 4.2 API, or later).
- *partition* can now skip installing the bootloader in more scenarios.
#1632 (Thanks Anubhav)
- *preservefiles* follows `${}` variable syntax instead of `@@`.
project( calamares CXX )
# === This file is part of Calamares - <https://calamares.io> ===
#
# SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
#
###
#
# Calamares is Free Software: see the License-Identifier above.
#
# Individual files may have different licenses (like the CMake
# infrastructure, which is BSD-2-Clause licensed). Check the SPDX
# identifiers in each file.
#
###
#
# Generally, this CMakeLists.txt will find all the dependencies for Calamares
# and complain appropriately. See below (later in this file) for CMake-level
# options. There are some "secret" options as well:
#
# SKIP_MODULES : a space or semicolon-separated list of directory names
# under src/modules that should not be built.
# USE_<foo> : fills in SKIP_MODULES for modules called <foo>-<something>.
# WITH_<foo> : try to enable <foo> (these usually default to ON). For
# a list of WITH_<foo> grep CMakeCache.txt after running
# CMake once. These affect the ABI offered by Calamares.
# - PYBIND11 (use bundled pybind11, default ON, needs WITH_PYTHON)
# - PYTHON (enable Python Job modules, default ON if Python is found)
# - QML (enable QML UI View modules, default ON)
# - QT6 (use Qt6 rather than Qt5, default to OFF)
# The WITH_* options affect the ABI of Calamares: you must
# build (C++) modules for Calamares with the same WITH_*
# settings, or they may not load at all.
# BUILD_<foo> : choose additional things to build
# - APPDATA (use AppData in packagechooser, requires QtXml)
# - APPSTREAM (use AppStream in packagechooser, requires libappstream-qt)
# - BUILD_CRASH_REPORTING (uses KCrash, rather than Calamares internal, for crash reporting)
# - SCHEMA_TESTING (requires Python, see ci/configvalidator.py)
# - TESTING (standard CMake option)
# DEBUG_<foo> : special developer flags for debugging.
# PYTHONLIBS_VERSION : if set on the command-line, use a specific Python version
#
# Example usage:
#
# cmake . -DSKIP_MODULES="partition luksbootkeycfg"
#
# To obtain the version number of calamares, run CMake in script mode, e.g.
# cmake -P CMakeLists.txt
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
set(CALAMARES_VERSION 3.3.15)
set(CALAMARES_RELEASE_MODE OFF) # Set to ON during a release
if(CMAKE_SCRIPT_MODE_FILE)
include(${CMAKE_CURRENT_LIST_DIR}/CMakeModules/ExtendedVersion.cmake)
set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
extend_version( ${CALAMARES_VERSION} ${CALAMARES_RELEASE_MODE} _vshort _vlong )
message("${_vlong}")
return()
endif()
# The partition manager uses ECM but ECMConfig.cmake
# will complain if we require CMake less than 2.8.13,
# so never change this.
cmake_minimum_required( VERSION 2.8.12 )
# Massage the version for CMake if there is a version-suffix
string(REGEX REPLACE "-.*" "" CALAMARES_VERSION_SHORT "${CALAMARES_VERSION}")
# And preserve the original version (suffix and all) because project() overwrites
# .. but if we're doing non-release builds, this gets replaced with git versioning.
set(CALAMARES_VERSION_LONG "${CALAMARES_VERSION}")
set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules" )
project(CALAMARES VERSION ${CALAMARES_VERSION_SHORT} LANGUAGES C CXX HOMEPAGE_URL "https://calamares.io/")
if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
message( STATUS "Found Clang ${CMAKE_CXX_COMPILER_VERSION}, setting up Clang-specific compiler flags." )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99" )
set( CMAKE_C_FLAGS_DEBUG "-g" )
set( CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" )
set( CMAKE_C_FLAGS_RELEASE "-O4 -DNDEBUG" )
set( CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g" )
if(NOT CALAMARES_RELEASE_MODE AND CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "Do not build development versions in the source-directory.")
endif()
# Calamares in the 3.3 series promises ABI compatbility, so it sets a
# .so-version equal to the series number. We use ci/abicheck.sh to
# keep track of this. Note that the **alpha** releases also have
# such an .so-version, but are not ABI-stable yet.
set(CALAMARES_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
### OPTIONS
#
option(INSTALL_POLKIT "Install Polkit configuration" ON)
option(INSTALL_COMPLETION "Install shell completions" OFF)
option(INSTALL_CONFIG "Install configuration files" OFF)
# When adding WITH_* that affects the ABI offered by libcalamares,
# also update libcalamares/CalamaresConfig.h.in
option(WITH_PYBIND11 "Use bundled pybind11 instead of Boost::Python" ON)
option(WITH_PYTHON "Enable Python modules API." ON)
option(WITH_QML "Enable QML UI options." ON)
option(WITH_QT6 "Use Qt6 instead of Qt5" OFF)
#
# Additional parts to build that do not affect ABI
option(BUILD_SCHEMA_TESTING "Enable schema-validation-tests" ON)
# Options for the calamares executable
option(BUILD_CRASH_REPORTING "Enable crash reporting with KCrash." ON)
option(DEBUG_SANITIZERS "Enable sanitizers and Debug build type" OFF)
# Possible debugging flags are:
# - DEBUG_TIMEZONES draws latitude and longitude lines on the timezone
# widget and enables chatty debug logging, for dealing with the timezone
# location database.
# - DEBUG_FILESYSTEMS does extra logging and checking when looking at
# partition configuration. Lists known KPMCore FS types.
# - DEBUG_PARTITION_UNSAFE (see partition/CMakeLists.txt)
# - DEBUG_PARTITION_BAIL_OUT (see partition/CMakeLists.txt)
# Special handling for Python versions:
# - If you set PYTHONLIBS_VERSION on the command-line, then
# that **exact** version will be searched for, and no other.
# - If you do not set PYTHONLIBS_VERSION on the command-line,
# any suitable version will be found -- but this can fail if
# you have multiple Python versions installed, only some of
# which include the development headers.
### USE_*
#
# By convention, when there are multiple modules that implement similar
# functionality, and it only makes sense to have **at most one** of them
# enabled at any time, those modules are named <foo>-<implementation>.
# For example, services-systemd and services-openrc.
#
# Setting up SKIP_MODULES to ignore "the ones you don't want" can be
# annoying and error-prone (e.g. if a new module shows up). The USE_*
# modules provide a way to do automatic selection. To pick exactly
# one of the implementations from group <foo>, set USE_<foo> to the
# name of the implementation. If USE_<foo> is unset, or empty, then
# all the implementations are enabled (this just means they are
# **available** to `settings.conf`, not that they are used).
#
# To explicitly disable a set of modules, set USE_<foo>=none
# (e.g. the literal string none), which won't match any of the
# modules but is handled specially.
#
# The following USE_* functionalities are available:
# - *services* picks one of the two service-configuration modules,
# for either systemd or openrc. This defaults to empty so that
# **both** modules are available.
set(USE_services "" CACHE STRING "Select the services module to use")
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything -std=c++14" )
set( CMAKE_CXX_FLAGS_DEBUG "-g" )
set( CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG" )
set( CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG" )
set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g" )
### Calamares application info
#
set(CALAMARES_ORGANIZATION_NAME "Calamares")
set(CALAMARES_ORGANIZATION_DOMAIN "github.com/calamares")
set(CALAMARES_APPLICATION_NAME "Calamares")
set(CALAMARES_DESCRIPTION_SUMMARY "The distribution-independent installer framework")
### Transifex (languages) info
#
# complete = 100% translated,
# good = nearly complete (use own judgement, right now >= 75%)
# ok = incomplete (more than 25% untranslated, at least 5% translated),
# incomplete = <5% translated, placeholder in tx; these are not included.
#
# Language en (source language) is added later. It isn't listed in
# Transifex either. Get the list of languages and their status
# from https://app.transifex.com/calamares/calamares/ , or (preferably)
# use ci/txstats.py to automatically check.
#
# When adding a new language, take care that it is properly loaded
# by the translation framework. Languages with alternate scripts
# (sr@latin in particular) or location (ca@valencia) need special
# handling in libcalamares/locale/Translation.h .
#
# NOTE: move ie (Interlingue) to _ok once Qt supports it.
# NOTE: update these lines by running `txstats.py`, or for full automation
# `txstats.py -e`. See also
#
# Total 80 languages
set( _tx_complete de en es_AR fi_FI hr hu ja lt tr_TR uk zh_TW )
set( _tx_good az az_AZ be bg ca cs_CZ es fr fur he hi is it_IT ko
pl pt_BR pt_PT ru si sq sv zh_CN )
set( _tx_ok ar as ast bn ca@valencia da el en_GB eo es_MX et eu fa
gl id ka ml mr nb nl oc ro sk sl sr sr@latin tg th vi )
set( _tx_incomplete bqi es_PR gu ie ja-Hira kk kn lo lv mk ne_NP
ro_RO ta_IN te ur uz zh zh_HK )
# Total 80 languages
### Required versions
#
# See DEPENDENCIES section below.
# The default build is with Qt5, but that is increasingly not the
# version installed-by-default on Linux systems. Upgrade the default
# if Qt5 isn't available but Qt6 is. This also saves messing around
# with special CMake flags for every script (e.g. ci/RELEASE.sh and
# ci/abicheck.sh).
if(NOT WITH_QT6)
find_package(Qt5Core QUIET)
if(NOT TARGET Qt5::Core)
find_package(Qt6Core QUIET)
if(TARGET Qt6::Core)
message(STATUS "Default Qt version (Qt5) not found, upgrading build to Qt6")
set(WITH_QT6 ON)
endif()
endif()
endif()
if(WITH_QT6)
message(STATUS "Building Calamares with Qt6")
set(qtname "Qt6")
set(kfname "KF6")
set(QT_VERSION 6.5.0)
set(ECM_VERSION 5.240)
set(KF_VERSION 5.240) # KDE Neon weirdness
# API that was deprecated before Qt 5.15 causes a compile error
add_compile_definitions(QT_DISABLE_DEPRECATED_BEFORE=0x060400)
# Something to add to filenames for this specific Qt version
set(QT_VERSION_SUFFIX "-qt6")
else()
message(STATUS "Building Calamares with Qt5")
set(qtname "Qt5")
set(kfname "KF5")
set(QT_VERSION 5.15.0)
set(ECM_VERSION 5.78)
set(KF_VERSION 5.78)
# API that was deprecated before Qt 5.15 causes a compile error
add_compile_definitions(QT_DISABLE_DEPRECATED_BEFORE=0x050f00)
# Something to add to filenames for this specific Qt version
set(QT_VERSION_SUFFIX "")
endif()
set( CMAKE_TOOLCHAIN_PREFIX "llvm-" )
set(BOOSTPYTHON_VERSION 1.72.0)
if(DEFINED PYTHONLIBS_VERSION)
set(PYTHONLIBS_EXTRA "EXACT")
else()
set(PYTHONLIBS_VERSION 3.6)
set(PYTHONLIBS_EXTRA "")
endif()
set(YAMLCPP_VERSION 0.5.1)
### CMAKE SETUP
#
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules")
# Enable IN_LIST
cmake_policy(SET CMP0057 NEW)
# Let ``AUTOMOC`` and ``AUTOUIC`` process ``GENERATED`` files.
cmake_policy(SET CMP0071 NEW)
# Recognize more macros to trigger automoc
list(APPEND CMAKE_AUTOMOC_MACRO_NAMES
"K_PLUGIN_FACTORY_WITH_JSON"
"K_EXPORT_PLASMA_DATAENGINE_WITH_JSON"
"K_EXPORT_PLASMA_RUNNER"
)
if(POLICY CMP0171)
cmake_policy(SET CMP0177 NEW)
endif()
# CMake Modules
include(CMakePackageConfigHelpers)
include(CTest)
include(FeatureSummary)
# Calamares Modules
include(CMakeColors)
### C++ SETUP
#
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror=return-type")
set(CMAKE_CXX_FLAGS_DEBUG "-Og -g ${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_C_FLAGS_DEBUG "-Og -g")
set(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined -Wl,--fatal-warnings ${CMAKE_SHARED_LINKER_FLAGS}")
# If no build type is set, pick a reasonable one
if(DEBUG_SANITIZERS)
set(CMAKE_BUILD_TYPE DEBUG)
endif()
if(NOT CMAKE_BUILD_TYPE)
if(CALAMARES_RELEASE_MODE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
else()
set(CMAKE_BUILD_TYPE "Debug")
endif()
endif()
set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined" )
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(STATUS "Found Clang ${CMAKE_CXX_COMPILER_VERSION}, setting up Clang-specific compiler flags.")
# Clang warnings: doing *everything* is counter-productive, since it warns
# about things which we can't fix (e.g. C++98 incompatibilities, but
# Calamares is C++17).
foreach(
CLANG_WARNINGS
-Weverything
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-padded
-Wno-undefined-reinterpret-cast
-Wno-global-constructors
-Wno-exit-time-destructors
-Wno-missing-prototypes
-Wno-documentation-unknown-command
-Wno-unknown-warning-option
)
string(APPEND CMAKE_CXX_FLAGS " ${CLANG_WARNINGS}")
endforeach()
# The dwarf-debugging flags are slightly different, too
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -gdwarf")
string(APPEND CMAKE_C_FLAGS_DEBUG " -gdwarf")
# Third-party code where we don't care so much about compiler warnings
# (because it's uncomfortable to patch) get different flags; use
# mark_thirdparty_code( <file> [<file>...] )
# to switch off warnings for those sources.
set(SUPPRESS_3RDPARTY_WARNINGS "-Wno-everything")
set(CMAKE_TOOLCHAIN_PREFIX "llvm-")
# The path prefix is only relevant for CMake 3.16 and later, fixes #1286
set(CMAKE_AUTOMOC_PATH_PREFIX OFF)
set(CALAMARES_AUTOMOC_OPTIONS "-butils/moc-warnings.h")
set(CALAMARES_AUTOUIC_OPTIONS --include utils/moc-warnings.h)
else()
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wl,--no-undefined" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wl,--fatal-warnings -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Woverloaded-virtual")
set(SUPPRESS_3RDPARTY_WARNINGS "")
endif()
if( CMAKE_COMPILER_IS_GNUCXX )
if( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 OR
CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.9 )
message( STATUS "Found GNU g++ ${CMAKE_CXX_COMPILER_VERSION}, enabling colorized error messages." )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=auto" )
# Use mark_thirdparty_code() to reduce warnings from the compiler
# on code that we're not going to fix. Call this with a list of files.
macro(mark_thirdparty_code)
set_source_files_properties(
${ARGV}
PROPERTIES COMPILE_FLAGS "${SUPPRESS_3RDPARTY_WARNINGS}" COMPILE_DEFINITIONS "THIRDPARTY"
)
endmacro()
if(CMAKE_COMPILER_IS_GNUCXX)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.9)
message(STATUS "Found GNU g++ ${CMAKE_CXX_COMPILER_VERSION}, enabling colorized error messages.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=auto")
endif()
if(DEBUG_SANITIZERS)
message(STATUS "Setting up sanitizers")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fsanitize=address -g -O1")
endif()
endif()
cmake_policy( SET CMP0023 OLD )
cmake_policy( SET CMP0028 NEW ) # double colons in KF5::Foo and Qt5::Foo are necessarily IMPORTED or ALIAS targets, don't search further
### DEPENDENCIES
#
find_package(${qtname} ${QT_VERSION} CONFIG REQUIRED Concurrent Core DBus Gui LinguistTools Network Svg Widgets)
if(WITH_QML)
find_package(${qtname} ${QT_VERSION} CONFIG REQUIRED Quick QuickWidgets)
endif()
# Note that some modules need more Qt modules, optionally.
find_package(YAMLCPP ${YAMLCPP_VERSION})
set_package_properties(
YAMLCPP
PROPERTIES
TYPE REQUIRED
DESCRIPTION "YAML parser for C++"
PURPOSE "Parsing of configuration files"
)
# Keep cmake 3.0 quiet
if( POLICY CMP0043 )
cmake_policy( SET CMP0043 OLD )
find_package(Polkit${qtname}-1)
if(INSTALL_POLKIT)
set_package_properties(
Polkit${qtname}-1
PROPERTIES
TYPE REQUIRED
)
endif()
set_package_properties(
Polkit${qtname}-1
PROPERTIES
DESCRIPTION "${qtname} support for Polkit"
URL "https://cgit.kde.org/polkit-qt-1.git"
PURPOSE "Polkit${qtname}-1 helps with installing Polkit configuration"
)
include( MacroOptionalFindPackage )
include( MacroLogFeature )
# Find ECM once, and add it to the module search path; Calamares
# modules that need ECM can do
# if(ECM_FOUND)
# no need to mess with the module path after.
find_package(ECM ${ECM_VERSION} NO_MODULE)
if(ECM_FOUND)
message(STATUS "Found KDE ECM ${ECM_MODULE_PATH}")
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH})
if(BUILD_TESTING)
# ECM implies that we can build the tests, too
find_package(${qtname} COMPONENTS Test REQUIRED)
include(ECMAddTests)
endif()
include(KDEInstallDirs)
endif()
set( QT_VERSION 5.6.0 )
find_package(${kfname}CoreAddons ${KF_VERSION} QUIET)
set_package_properties(
${kfname}CoreAddons
PROPERTIES
TYPE REQUIRED
DESCRIPTION "KDE Framework CoreAddons"
URL "https://api.kde.org/frameworks/"
PURPOSE "Essential Framework for AboutData and Macros"
)
find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED Core Gui Widgets LinguistTools Svg Quick QuickWidgets )
find_package( YAMLCPP 0.5.1 REQUIRED )
find_package( PolkitQt5-1 REQUIRED )
# After this point, there should be no REQUIRED find_packages,
# since we want tidy reporting of optional dependencies.
feature_summary(
WHAT REQUIRED_PACKAGES_NOT_FOUND
FATAL_ON_MISSING_REQUIRED_PACKAGES
DESCRIPTION "The following REQUIRED packages were not found:"
QUIET_ON_EMPTY
)
option( WITH_PYTHON "Enable Python modules support." ON )
option( WITH_CRASHREPORTER "Build with CrashReporter" ON )
#
# OPTIONAL DEPENDENCIES
#
# First, set KF back to optional so that any missing components don't trip us up.
find_package(${kfname}Crash ${KF_VERSION} QUIET)
set_package_properties(
${kfname}Crash
PROPERTIES
TYPE OPTIONAL
DESCRIPTION "KDE Framework Crash"
URL "https://api.kde.org/frameworks/"
PURPOSE "Framework for sending Crash Dumps"
)
if( CMAKE_SYSTEM_PROCESSOR MATCHES "arm" OR NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libcrashreporter-qt/CMakeLists.txt" )
message( STATUS "Build of crashreporter disabled." )
set( WITH_CRASHREPORTER OFF )
if(NOT TARGET ${kfname}::Crash)
if(BUILD_CRASH_REPORTING)
message(WARNING "BUILD_CRASH_REPORTING is set, but ${kfname}::Crash is not available.")
endif()
set(BUILD_CRASH_REPORTING OFF)
endif()
macro_optional_find_package( PythonLibs 3.3 )
macro_log_feature(
PYTHONLIBS_FOUND
"Python"
"C interface libraries for the Python 3 interpreter."
"http://python.org"
FALSE "3.3"
"Python 3 is used for some Calamares job modules."
find_package(Python ${PYTHONLIBS_VERSION} ${PYTHONLIBS_EXTRA} COMPONENTS Interpreter Development)
set_package_properties(
Python
PROPERTIES
DESCRIPTION "Python3 interpreter."
URL "https://python.org"
PURPOSE "Python3 interpreter for certain tests."
)
if ( PYTHONLIBS_FOUND )
include( BoostPython3 )
find_boost_python3( 1.54.0 ${PYTHONLIBS_VERSION_STRING} CALAMARES_BOOST_PYTHON3_FOUND )
macro_log_feature(
CALAMARES_BOOST_PYTHON3_FOUND
"Boost.Python"
"A C++ library which enables seamless interoperability between C++ and Python 3."
"http://www.boost.org"
FALSE "1.54.0"
"Boost.Python is used for interfacing with Calamares job modules written in Python 3."
)
set(_schema_explanation "")
if(Python_Interpreter_FOUND)
if(BUILD_SCHEMA_TESTING)
# The configuration validator script has some dependencies,
# and if they are not installed, don't run. If errors out
# with exit(1) on missing dependencies.
if(CALAMARES_CONFIGVALIDATOR_CHECKED)
message(STATUS "Using cached config-validation result")
set(_validator_deps ${CALAMARES_CONFIGVALIDATOR_RESULT})
else()
execute_process(
COMMAND ${Python_EXECUTABLE} "${CMAKE_SOURCE_DIR}/ci/configvalidator.py" -x
RESULT_VARIABLE _validator_deps
)
set(CALAMARES_CONFIGVALIDATOR_CHECKED TRUE CACHE INTERNAL "Dependencies for configvalidator checked")
set(CALAMARES_CONFIGVALIDATOR_RESULT ${_validator_deps}
CACHE INTERNAL "Result of configvalidator dependency check"
)
endif()
# It should never succeed, but only returns 1 when the imports fail
if(_validator_deps EQUAL 1)
message(STATUS "Checked for config-validation dependencies: NOT-FOUND")
set(_schema_explanation " Missing dependencies for configvalidator.py.")
set(BUILD_SCHEMA_TESTING OFF)
else()
message(STATUS "Checked for config-validation dependencies: found")
endif()
else()
set(CALAMARES_CONFIGVALIDATOR_CHECKED OFF CACHE INTERNAL "Dependencies for configvalidator checked")
endif()
else()
# Can't run schema tests without Python3.
set(_schema_explanation " Missing Python3.")
set(BUILD_SCHEMA_TESTING OFF)
set(CALAMARES_CONFIGVALIDATOR_CHECKED OFF CACHE INTERNAL "Dependencies for configvalidator checked")
endif()
add_feature_info(yaml-schema BUILD_SCHEMA_TESTING "Validate YAML (config files) with schema.${_schema_explanation}")
if ( PYTHONLIBS_NOTFOUND OR NOT CALAMARES_BOOST_PYTHON3_FOUND )
set( WITH_PYTHON OFF )
if(NOT Python_Development_FOUND)
message(STATUS "Disabling Python modules")
set(WITH_PYTHON OFF)
set(WITH_PYBIND11 OFF)
set(WITH_BOOST_PYTHON OFF)
endif()
###
### Calamares application info
###
set( CALAMARES_ORGANIZATION_NAME "Calamares" )
set( CALAMARES_ORGANIZATION_DOMAIN "github.com/calamares" )
set( CALAMARES_APPLICATION_NAME "Calamares" )
set( CALAMARES_DESCRIPTION_SUMMARY "The distribution-independent installer framework" )
set( CALAMARES_TRANSLATION_LANGUAGES ar ast bg ca cs_CZ da de el en en_GB es_MX es eu fr hr hu id is it_IT ja lt nl pl pt_BR pt_PT ro ru sk sv th tr_TR zh_CN zh_TW )
### Bump version here
set( CALAMARES_VERSION_MAJOR 2 )
set( CALAMARES_VERSION_MINOR 4 )
set( CALAMARES_VERSION_PATCH 5 )
set( CALAMARES_VERSION_RC 0 )
set( CALAMARES_VERSION ${CALAMARES_VERSION_MAJOR}.${CALAMARES_VERSION_MINOR}.${CALAMARES_VERSION_PATCH} )
set( CALAMARES_VERSION_SHORT "${CALAMARES_VERSION}" )
if( CALAMARES_VERSION_RC )
set( CALAMARES_VERSION ${CALAMARES_VERSION}rc${CALAMARES_VERSION_RC} )
endif()
# additional info for non-release builds
if( NOT BUILD_RELEASE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git/" )
include( CMakeDateStamp )
set( CALAMARES_VERSION_DATE "${CMAKE_DATESTAMP_YEAR}${CMAKE_DATESTAMP_MONTH}${CMAKE_DATESTAMP_DAY}" )
if( CALAMARES_VERSION_DATE GREATER 0 )
set( CALAMARES_VERSION ${CALAMARES_VERSION}.${CALAMARES_VERSION_DATE} )
if(WITH_PYTHON AND NOT WITH_PYBIND11)
set(WITH_BOOST_PYTHON ON)
find_package(boost_python)
if(NOT TARGET Boost::python)
find_package(Boost ${BOOSTPYTHON_VERSION} COMPONENTS python)
set_package_properties(Boost PROPERTIES
PURPOSE "Boost.Python is used for Python job modules (because WITH_PYBIND11 is OFF)."
TYPE REQUIRED
)
else()
message(STATUS "Found boost_python with target Boost::python")
set(Boost_FOUND ON)
endif()
endif()
add_feature_info(python WITH_PYTHON "Enable Python-modules")
add_feature_info(python-pybind11 WITH_PYBIND11 "Python-modules through pybind11")
add_feature_info(python-boost WITH_BOOST_PYTHON "Python-modules through Boost::Python")
# Now we know the state of the ABI-options, copy them into "Calamares_"
# prefixed variables, to match how the variables would-be-named
# when building out-of-tree.
set(Calamares_WITH_PYTHON ${WITH_PYTHON})
set(Calamares_WITH_PYBIND11 ${WITH_PYBIND11})
set(Calamares_WITH_BOOST_PYTHON ${WITH_BOOST_PYTHON})
set(Calamares_WITH_QML ${WITH_QML})
set(Calamares_WITH_QT6 ${WITH_QT6})
### Transifex Translation status
#
# Construct language lists for use. This massages the language lists if
# needed and checks for some obvious errors. The actual work of
# compiling translations is done in the lang/ directory.
#
set(curr_tx ${_tx_complete} ${_tx_good} ${_tx_ok} ${_tx_incomplete})
set(tx_errors OFF)
if(curr_tx)
# New in list
foreach(l ${curr_tx})
set(p_l "lang/calamares_${l}.ts")
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${p_l})
message(WARNING "Language ${l} has no .ts file yet.")
set(tx_errors ON)
endif()
endforeach()
unset(p_l)
unset(l)
endif()
unset(curr_tx)
if(tx_errors)
message(FATAL_ERROR "Translation warnings, see above.")
endif()
include( CMakeVersionSource )
if( CMAKE_VERSION_SOURCE )
set( CALAMARES_VERSION ${CALAMARES_VERSION}-${CMAKE_VERSION_SOURCE} )
set(CALAMARES_TRANSLATION_LANGUAGES en ${_tx_complete} ${_tx_good} ${_tx_ok})
if(NOT CALAMARES_RELEASE_MODE)
# Outside of release mode, enable all the languages
list(APPEND CALAMARES_TRANSLATION_LANGUAGES ${_tx_incomplete})
endif()
list(SORT CALAMARES_TRANSLATION_LANGUAGES)
list(REMOVE_DUPLICATES CALAMARES_TRANSLATION_LANGUAGES)
add_subdirectory(lang) # i18n tools
### Example Distro
#
# For testing purposes Calamares includes a very, very, limited sample
# distro called "Generic". The root filesystem of "Generic" lives in
# data/example-root and can be squashed up as part of the build, so
# that a pure-upstream run of ./calamares -d from the build directory
# (with all the default settings and configurations) can actually
# do an complete example run.
#
# Some binaries from the build host (e.g. /bin and /lib) are also
# squashed into the example filesystem.
#
# To build the example distro (for use by the default, example,
# unsquashfs module), build the target 'example-distro', eg.:
#
# make example-distro
#
find_program(mksquashfs_PROGRAM mksquashfs)
if(mksquashfs_PROGRAM)
set(mksquashfs_FOUND ON)
set(src_fs ${CMAKE_SOURCE_DIR}/data/example-root/)
set(dst_fs ${CMAKE_BINARY_DIR}/example.sqfs)
if(EXISTS ${src_fs})
# based on the build host. If /lib64 exists, assume it is needed.
# Collect directories needed for a minimal binary distro,
# Note that the last path component is added to the root, so
# if you add /usr/sbin here, it will be put into /sbin_1.
# Add such paths to /etc/profile under ${src_fs}.
set(candidate_fs /sbin /bin /lib /lib64)
set(host_fs "")
foreach(c_fs ${candidate_fs})
if(EXISTS ${c_fs})
list(APPEND host_fs ${c_fs})
endif()
endforeach()
add_custom_command(
OUTPUT ${dst_fs}
COMMAND ${mksquashfs_PROGRAM} ${src_fs} ${dst_fs} -all-root
COMMAND ${mksquashfs_PROGRAM} ${host_fs} ${dst_fs} -all-root
)
add_custom_target(example-distro DEPENDS ${dst_fs})
endif()
else()
set(mksquashfs_FOUND OFF)
endif()
# Doesn't list mksquashfs as an optional dep, though, because it
# hasn't been sent through the find_package() scheme.
#
# "http://tldp.org/HOWTO/SquashFS-HOWTO/creatingandusing.html"
add_feature_info(ExampleDistro ${mksquashfs_FOUND} "Create example-distro target.")
### CALAMARES PROPER
#
# Additional info for non-release builds. The "extended" version information
# with date and git information (commit, dirty status) is used only
# by CalamaresVersionX.h, which is included by consumers that need a full
# version number with all that information; normal consumers can include
# CalamaresVersion.h with more stable numbers.
if(NOT CALAMARES_RELEASE_MODE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git/")
include(ExtendedVersion)
extend_version( "${CALAMARES_VERSION}" OFF CALAMARES_VERSION_SHORT CALAMARES_VERSION_LONG )
endif()
# Special define for RC (e.g. not-a-release) builds.
# This is consumed via the CalamaresConfig.h header.
if(NOT CALAMARES_RELEASE_MODE)
set(CALAMARES_VERSION_RC 1)
endif()
# enforce using constBegin, constEnd for const-iterators
add_definitions( "-DQT_STRICT_ITERATORS" )
add_definitions(-DQT_STRICT_ITERATORS -DQT_SHARED -DQT_SHAREDPOINTER_TRACK_POINTERS)
# set paths
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
# Better default installation paths: GNUInstallDirs defines
# CMAKE_INSTALL_FULL_SYSCONFDIR to be CMAKE_INSTALL_PREFIX/etc by default
# but we really want /etc
if( NOT DEFINED CMAKE_INSTALL_SYSCONFDIR )
set( CMAKE_INSTALL_SYSCONFDIR "/etc" )
if(NOT DEFINED CMAKE_INSTALL_SYSCONFDIR)
set(CMAKE_INSTALL_SYSCONFDIR "/etc")
endif()
# make predefined install dirs available everywhere
include( GNUInstallDirs )
# make uninstall support
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY
)
# Early configure these files as we need them later on
configure_file( CalamaresUse.cmake.in "${PROJECT_BINARY_DIR}/CalamaresUse.cmake" @ONLY )
file( COPY CalamaresAddLibrary.cmake DESTINATION "${PROJECT_BINARY_DIR}" )
file( COPY CalamaresAddModuleSubdirectory.cmake DESTINATION "${PROJECT_BINARY_DIR}" )
file( COPY CalamaresAddPlugin.cmake DESTINATION "${PROJECT_BINARY_DIR}" )
file( COPY CalamaresAddBrandingSubdirectory.cmake DESTINATION "${PROJECT_BINARY_DIR}" )
set( CALAMARES_LIBRARIES calamares )
set( THIRDPARTY_DIR "${CMAKE_SOURCE_DIR}/thirdparty" )
include(GNUInstallDirs)
add_subdirectory( thirdparty )
add_subdirectory( src )
# This is used by CalamaresAddLibrary; once Calamares is installed,
# the CalamaresConfig.cmake module sets this variable to the IMPORTED
# libraries for Calamares.
set(Calamares_LIBRARIES calamares)
macro_display_feature_log()
if ( NOT WITH_PYTHON )
message( "-- WARNING: Building Calamares without Python support. Python modules will not work.\n" )
add_subdirectory(3rdparty/kdsingleapplication)
if(WITH_PYBIND11)
add_subdirectory(3rdparty/pybind11)
endif()
# Add all targets to the build-tree export set
set( CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/Calamares" CACHE PATH "Installation directory for CMake files" )
set( CMAKE_INSTALL_FULL_CMAKEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}" )
export( TARGETS calamares
FILE "${PROJECT_BINARY_DIR}/CalamaresLibraryDepends.cmake" )
# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
export( PACKAGE Calamares )
# Create a CalamaresBuildTreeSettings.cmake file for the use from the build tree
configure_file( CalamaresBuildTreeSettings.cmake.in "${PROJECT_BINARY_DIR}/CalamaresBuildTreeSettings.cmake" @ONLY )
# Create the CalamaresConfig.cmake and CalamaresConfigVersion files
file( RELATIVE_PATH CONF_REL_INCLUDE_DIR "${CMAKE_INSTALL_FULL_CMAKEDIR}" "${CMAKE_INSTALL_FULL_INCLUDEDIR}" )
configure_file( CalamaresConfig.cmake.in "${PROJECT_BINARY_DIR}/CalamaresConfig.cmake" @ONLY )
configure_file( CalamaresConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/CalamaresConfigVersion.cmake" @ONLY )
add_subdirectory(src)
add_feature_info(Python ${WITH_PYTHON} "Python job modules")
add_feature_info(Pybind11 ${WITH_PYBIND11} "Python using bundled pybind11")
add_feature_info(Qml ${WITH_QML} "QML UI support")
add_feature_info(Polkit ${INSTALL_POLKIT} "Install Polkit files")
add_feature_info(KCrash ${BUILD_CRASH_REPORTING} "Crash dumps via KCrash")
### Post-source configuration
#
#
find_package(${kfname} ${KF_VERSION} QUIET COMPONENTS CoreAddons)
### CMake infrastructure installation
#
#
set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/Calamares" CACHE PATH "Installation directory for CMake files")
set(CMAKE_INSTALL_FULL_CMAKEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}")
export(PACKAGE Calamares)
configure_package_config_file(
"CalamaresConfig.cmake.in"
"${PROJECT_BINARY_DIR}/CalamaresConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR CMAKE_INSTALL_DATADIR
)
write_basic_package_version_file(
${PROJECT_BINARY_DIR}/CalamaresConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(EXPORT Calamares DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" FILE "CalamaresTargets.cmake" NAMESPACE Calamares::)
# Install the cmake files
install(
FILES
"${PROJECT_BINARY_DIR}/CalamaresConfig.cmake"
"${PROJECT_BINARY_DIR}/CalamaresConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/CalamaresUse.cmake"
"${PROJECT_BINARY_DIR}/CalamaresAddPlugin.cmake"
"${PROJECT_BINARY_DIR}/CalamaresAddModuleSubdirectory.cmake"
"${PROJECT_BINARY_DIR}/CalamaresAddLibrary.cmake"
"${PROJECT_BINARY_DIR}/CalamaresAddBrandingSubdirectory.cmake"
DESTINATION
"${CMAKE_INSTALL_CMAKEDIR}"
"CMakeModules/CalamaresAddBrandingSubdirectory.cmake"
"CMakeModules/CalamaresAddLibrary.cmake"
"CMakeModules/CalamaresAddModuleSubdirectory.cmake"
"CMakeModules/CalamaresAddPlugin.cmake"
"CMakeModules/CalamaresAddTest.cmake"
"CMakeModules/CalamaresAddTranslations.cmake"
"CMakeModules/CalamaresAutomoc.cmake"
"CMakeModules/CalamaresCheckModuleSelection.cmake"
"CMakeModules/CMakeColors.cmake"
"CMakeModules/FindYAMLCPP.cmake"
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
)
# Install the export set for use with the install-tree
install(
EXPORT
CalamaresLibraryDepends
DESTINATION
"${CMAKE_INSTALL_CMAKEDIR}"
)
### Miscellaneous installs
#
#
if(INSTALL_POLKIT)
install(FILES com.github.calamares.calamares.policy DESTINATION "${POLKITQT-1_POLICY_FILES_INSTALL_DIR}")
endif()
install(
FILES
settings.conf
DESTINATION
share/calamares
)
if(INSTALL_COMPLETION)
if(NOT CMAKE_INSTALL_BASHCOMPLETIONDIR)
set(CMAKE_INSTALL_BASHCOMPLETIONDIR "${CMAKE_INSTALL_DATADIR}/bash-completion/completions")
endif()
install(
FILES
com.github.calamares.calamares.policy
DESTINATION
"${POLKITQT-1_POLICY_FILES_INSTALL_DIR}"
)
install(FILES ${CMAKE_SOURCE_DIR}/data/completion/bash/calamares DESTINATION "${CMAKE_INSTALL_BASHCOMPLETIONDIR}")
endif()
install(
FILES
calamares.desktop
DESTINATION
${CMAKE_INSTALL_DATADIR}/applications
)
install(FILES calamares.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
install(FILES man/calamares.8 DESTINATION ${CMAKE_INSTALL_MANDIR}/man8/)
if(INSTALL_CONFIG)
install(FILES settings.conf DESTINATION share/calamares)
endif()
# uninstall target
### Uninstall
#
#
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY
IMMEDIATE
@ONLY
)
add_custom_target( uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
### Developer convenience
#
# The module support files -- .desc files, .conf files -- are copied into the build
# directory so that it is possible to run `calamares -d` from there. Copy the
# top-level settings.conf as well, into the build directory.
if(settings.conf IS_NEWER_THAN ${CMAKE_BINARY_DIR}/settings.conf)
configure_file(settings.conf ${CMAKE_BINARY_DIR}/settings.conf COPYONLY)
endif()
### CMAKE SUMMARY REPORT
#
get_directory_property(SKIPPED_MODULES DIRECTORY src/modules DEFINITION LIST_SKIPPED_MODULES)
calamares_explain_skipped_modules( ${SKIPPED_MODULES} )
feature_summary(WHAT ENABLED_FEATURES DESCRIPTION "The following features are enabled" QUIET_ON_EMPTY)
feature_summary(WHAT DISABLED_FEATURES DESCRIPTION "The following features have been disabled:" QUIET_ON_EMPTY)
feature_summary(
WHAT OPTIONAL_PACKAGES_NOT_FOUND
DESCRIPTION "The following OPTIONAL packages were not found:"
QUIET_ON_EMPTY
)
feature_summary(
WHAT REQUIRED_PACKAGES_NOT_FOUND
FATAL_ON_MISSING_REQUIRED_PACKAGES
DESCRIPTION "The following REQUIRED packages were not found:"
QUIET_ON_EMPTY
)
### PACKAGING
#
# Note: most distro's will do distro-specific packaging rather than
# using CPack, and this duplicates information in the AppStream, too.
set(CPACK_PACKAGE_VENDOR calamares)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A Linux system installer")
set(CPACK_PACKAGE_DESCRIPTION
"Calamares is a Linux system installer, intended for Linux distributions to use on their ISOs and other bootable media to install the distribution to the end-user's computer. Calamares can also be used as an OEM configuration tool. It is modular, extensible and highly-configurable for Linux distributions from all five major Linux families."
)
set(CPACK_PACKAGE_ICON "data/images/squid.png")
include(CPack)
# === This file is part of Calamares - <https://calamares.io> ===
#
# SPDX-FileCopyrightText: 2023 Adriaan de Groot <groot@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
#
###
#
# Finds AppStream-Qt suitable for the Qt version that is in use.
# Creates target calamares::appstreamqt to alias whatever is found.
# Sets AppStreamQt_FOUND appropriately, regardless of the underlying
# variables (e.g. might be AppStreamQt6_FOUND).
#
option(BUILD_APPSTREAM "Support appstream: items in PackageChooser (requires libappstream-qt)" OFF)
if(TARGET calaappstream)
if(TARGET calamares::appstreamqt)
message(STATUS "AppStreamQt has already been found")
set(AppStreamQt_FOUND TRUE)
else()
message(STATUS "AppStreamQt has been searched-for and not found")
set(AppStreamQt_FOUND FALSE)
endif()
return()
endif()
if(NOT BUILD_APPSTREAM)
return()
endif()
### FIND APPSTREAM
#
# First, look for a Qt-versioned variety of the package.
# If that is not found, look for an unversioned one.
set(HAVE_APPSTREAM OFF)
find_package(AppStream${qtname})
# Not everyone renames the variables consistently
if(AppStream${qtname}_FOUND OR AppStreamQt_FOUND)
set(_appstream_name AppStream${qtname})
set(HAVE_APPSTREAM ON)
else()
find_package(AppStreamQt)
if(AppStreamQt_FOUND)
set(_appstream_name AppStreamQt)
# TODO: how to check underlying Qt version?
set(HAVE_APPSTREAM ON)
endif()
endif()
if(HAVE_APPSTREAM)
# Look for the directory name containing the headers
find_file(_appstream_header NAMES ${_appstream_name}/pool.h AppStreamQt/pool.h)
if(NOT _appstream_header)
set(HAVE_APPSTREAM OFF)
else()
if(_appstream_header MATCHES /${_appstream_name}/)
set(_appstream_header_directory ${_appstream_name})
else()
set(_appstream_header_directory AppStreamQt)
endif()
endif()
else()
# Placeholder name
set(_appstream_name AppStreamQt)
endif()
set(_appstream_dependency_type OPTIONAL)
if(BUILD_APPSTREAM)
set(_appstream_dependency_type REQUIRED)
endif()
set_package_properties(
${_appstream_name}
PROPERTIES
DESCRIPTION "Support for AppStream (cache) data"
URL "https://github.com/ximion/appstream"
PURPOSE "AppStream provides package data"
TYPE ${_appstream_dependency_type}
)
add_library(calaappstream INTERFACE) # Always, but might not be populated
if(HAVE_APPSTREAM)
target_compile_definitions(calaappstream INTERFACE HAVE_APPSTREAM_VERSION=${${_appstream_name}_VERSION_MAJOR} HAVE_APPSTREAM_HEADERS=${_appstream_header_directory})
target_link_libraries(calaappstream INTERFACE ${_appstream_name})
add_library(calamares::appstreamqt ALIAS calaappstream)
endif()
set(AppStreamQt_FOUND ${HAVE_APPSTREAM})
# On Ubuntu 14.04, the libboost-python1.54-dev package comes with one library
# for each Python version:
# libboost_python-py27.so
# libboost_python-py33.so
# libboost_python-py34.so
#
# Boost upstream however installs Boost.Python3 libboost_python3.so, which is
# what FindBoost.cmake is looking for. It looks for a library named
# "libboost_${component}.so".
#
# On Gentoo instead, the >=dev-libs/boost-1.54 package provides boost library
# with a name like:
# libboost_python-2.7.so
# libboost_python-3.3.so
# libboost_python-3.4.so
# depending on what python's targets you selected during install
#
# find_boost_python3() tries to find the package with different component
# names. By default it tries "python3", "python-py$suffix" and
# "python-$dotsuffix", where suffix is based on the `python_version` argument.
# One can supply a custom component name by setting the
# `CALAMARES_BOOST_PYTHON3_COMPONENT` variable at CMake time.
set( CALAMARES_BOOST_PYTHON3_COMPONENT python3 CACHE STRING
"Name of the Boost.Python component. If Boost.Python is installed as
libboost_python-foo.so then this variable should be set to 'python-foo'."
)
macro( find_boost_python3 boost_version python_version found_var )
set( ${found_var} OFF )
# turns "3.4.123abc" into "34"
string( REGEX REPLACE "([0-9]+)\\.([0-9]+)\\..*" "\\1\\2" _fbp_python_short_version ${python_version} )
foreach( _fbp_name ${CALAMARES_BOOST_PYTHON3_COMPONENT} python-py${_fbp_python_short_version} )
find_package( Boost ${boost_version} QUIET COMPONENTS ${_fbp_name} )
string( TOUPPER ${_fbp_name} _fbp_uc_name )
if( Boost_${_fbp_uc_name}_FOUND )
set( ${found_var} ON )
break()
endif()
endforeach()
if (NOT ${found_var})
# The following loop changes the searched name for Gentoo based distributions
# turns "3.4.123abc" into "3.4"
string( REGEX REPLACE "([0-9]+)\\.([0-9]+)\\..*" "\\1.\\2" _fbp_python_short_version ${python_version} )
foreach( _fbp_name ${CALAMARES_BOOST_PYTHON3_COMPONENT} python-${_fbp_python_short_version} )
find_package( Boost ${boost_version} QUIET COMPONENTS ${_fbp_name} )
string( TOUPPER ${_fbp_name} _fbp_uc_name )
if( Boost_${_fbp_uc_name}_FOUND )
set( ${found_var} ON )
break()
endif()
endforeach()
endif()
endmacro()
# === This file is part of Calamares - <https://calamares.io> ===
#
# SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
# SPDX-FileCopyrightText: 2014 Kevin Kofler <kevin.kofler@chello.at>
# SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
#
###
#
# Defines a handful of strings that, with normal xterm handling,
# will change colors in the output, so it's nicer to read.
if(NOT WIN32)
# [ -t 2 ] tests whether stderr is interactive.
# The negation '!' is because for POSIX shells, 0 is true and 1 is false.
execute_process(COMMAND test ! -t 2 RESULT_VARIABLE IS_STDERR_INTERACTIVE)
if(IS_STDERR_INTERACTIVE)
set(_use_color ON)
if("0" STREQUAL "$ENV{CLICOLOR}")
set(_use_color OFF)
endif()
if("0" STREQUAL "$ENV{CLICOLOR_FORCE}")
set(_use_color OFF)
endif()
if(NOT CMAKE_COLOR_MAKEFILE)
set(_use_color OFF)
endif()
if(_use_color)
string(ASCII 27 Esc)
set(ColorReset "${Esc}[m")
set(ColorBold "${Esc}[1m")
......@@ -20,5 +39,5 @@ if(NOT WIN32)
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
endif(IS_STDERR_INTERACTIVE)
endif()
endif()
find_program(DATE_EXECUTABLE NAMES date)
mark_as_advanced(DATE_EXECUTABLE)
if(DATE_EXECUTABLE)
execute_process(
COMMAND ${DATE_EXECUTABLE} +%Y
OUTPUT_VARIABLE CMAKE_DATESTAMP_YEAR
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
execute_process(
COMMAND ${DATE_EXECUTABLE} +%m
OUTPUT_VARIABLE CMAKE_DATESTAMP_MONTH
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
execute_process(
COMMAND ${DATE_EXECUTABLE} +%d
OUTPUT_VARIABLE CMAKE_DATESTAMP_DAY
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()
# Try to identify the current development source version.
set(CMAKE_VERSION_SOURCE "")
if(EXISTS ${CMAKE_SOURCE_DIR}/.git/HEAD)
find_program(GIT_EXECUTABLE NAMES git git.cmd)
mark_as_advanced(GIT_EXECUTABLE)
if(GIT_EXECUTABLE)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --verify -q --short=7 HEAD
OUTPUT_VARIABLE head
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
if(head)
set(branch "")
execute_process(
COMMAND ${GIT_EXECUTABLE} name-rev HEAD
OUTPUT_VARIABLE branch
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
string(REGEX REPLACE "HEAD " "" branch "${branch}")
set(CMAKE_VERSION_SOURCE "git-${branch}-${head}")
execute_process(
COMMAND ${GIT_EXECUTABLE} update-index -q --refresh
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
execute_process(
COMMAND ${GIT_EXECUTABLE} diff-index --name-only HEAD --
OUTPUT_VARIABLE dirty
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
if(dirty)
set(CMAKE_VERSION_SOURCE "${CMAKE_VERSION_SOURCE}-dirty")
endif()
endif()
endif()
elseif(EXISTS ${CMAKE_SOURCE_DIR}/CVS/Repository)
file(READ ${CMAKE_SOURCE_DIR}/CVS/Repository repo)
set(branch "")
if("${repo}" MATCHES "\\.git/")
string(REGEX REPLACE ".*\\.git/([^\r\n]*).*" "-\\1" branch "${repo}")
endif()
set(CMAKE_VERSION_SOURCE "cvs${branch}")
endif()
# === This file is part of Calamares - <https://calamares.io> ===
#
# SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
# SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
#
# Calamares is Free Software: see the License-Identifier above.
#
#
###
#
# Support macros for creating Calamares branding components.
#
# Calamares branding components have two parts:
# - a branding.desc file that tells Calamares how to describe the product
# (e.g. strings like "Generic GNU/Linux") and the name of a QML file
# (the "slideshow") that is displayed during installation.
# - the QML files themselves, plus supporting images etc.
#
# Branding components can be created inside the Calamares source tree
# (there is one example the `default/` branding, which is also connected
# to the default configuration shipped with Calamares), but they can be
# built outside of, and largely independently of, Calamares by using
# these CMake macros.
#
# See the calamares-examples repository for more examples.
#
include( CMakeParseArguments)
include( CMakeColors )
# Usage calamares_add_branding( <name> [DIRECTORY <dir>] [SUBDIRECTORIES <dir> ...])
#
# Adds a branding component to the build:
# - the component's top-level files are copied into the build-dir;
# CMakeLists.txt is excluded from the glob.
# - the component's top-level files are installed into the component branding dir
#
# The branding component lives in <dir> if given, otherwise the
# current source directory. The branding component is installed
# with the given <name>, which is usually the name of the
# directory containing the component, and which must match the
# *componentName* in `branding.desc`.
#
# If SUBDIRECTORIES are given, then those are copied (each one level deep)
# to the installation location as well, preserving the subdirectory name.
function( calamares_add_branding NAME )
cmake_parse_arguments( _CABT "" "DIRECTORY" "SUBDIRECTORIES" ${ARGN} )
if (NOT _CABT_DIRECTORY)
set(_CABT_DIRECTORY ".")
endif()
set( SUBDIRECTORY ${_CABT_DIRECTORY} )
set( _brand_dir ${_CABT_DIRECTORY} )
set( BRANDING_DIR share/calamares/branding )
set( BRANDING_COMPONENT_DESTINATION ${BRANDING_DIR}/${NAME} )
foreach( _subdir "" ${_CABT_SUBDIRECTORIES} )
file( GLOB BRANDING_COMPONENT_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/${_brand_dir} "${_brand_dir}/${_subdir}/*" )
foreach( BRANDING_COMPONENT_FILE ${BRANDING_COMPONENT_FILES} )
set( _subpath ${_brand_dir}/${BRANDING_COMPONENT_FILE} )
if( NOT IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_subpath} )
set( _src ${CMAKE_CURRENT_SOURCE_DIR}/${_subpath} )
set( _dst ${CMAKE_CURRENT_BINARY_DIR}/${_subpath} )
if( ${_src} IS_NEWER_THAN ${_dst} )
configure_file( ${_src} ${_dst} COPYONLY )
endif()
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${_subpath}
DESTINATION ${BRANDING_COMPONENT_DESTINATION}/${_subdir}/ )
endif()
endforeach()
endforeach()
message( "-- ${BoldYellow}Found ${CALAMARES_APPLICATION_NAME} branding component: ${BoldRed}${NAME}${ColorReset}" )
message( " ${Green}TYPE:${ColorReset} branding component" )
message( " ${Green}BRANDING_COMPONENT_DESTINATION:${ColorReset} ${BRANDING_COMPONENT_DESTINATION}" )
endfunction()
# Usage calamares_add_branding_translations( <name> [DIRECTORY <dir>])
#
# Adds the translations for a branding component to the build:
# - the component's lang/ directory is scanned for .ts files
# - the component's translations are installed into the component branding dir
#
# Translation files must be called calamares-<name>_<lang>.ts . Optionally
# the lang/ dir is found in the given <dir> instead of the current source
# directory.
function( calamares_add_branding_translations NAME )
cmake_parse_arguments( _CABT "" "DIRECTORY" "" ${ARGN} )
if (NOT _CABT_DIRECTORY)
set(_CABT_DIRECTORY ".")
endif()
set( SUBDIRECTORY ${_CABT_DIRECTORY} )
set( _brand_dir ${_CABT_DIRECTORY} )
set( BRANDING_DIR share/calamares/branding )
set( BRANDING_COMPONENT_DESTINATION ${BRANDING_DIR}/${NAME} )
file( GLOB BRANDING_TRANSLATION_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${SUBDIRECTORY}/lang/calamares-${NAME}_*.ts" )
if ( BRANDING_TRANSLATION_FILES )
qt_add_translation( QM_FILES ${BRANDING_TRANSLATION_FILES} )
add_custom_target( branding-translation-${NAME} ALL DEPENDS ${QM_FILES}
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${SUBDIRECTORY}/lang/
COMMAND ${CMAKE_COMMAND} -E copy ${QM_FILES} ${CMAKE_CURRENT_BINARY_DIR}/${SUBDIRECTORY}/lang/
)
install( FILES ${QM_FILES} DESTINATION ${BRANDING_COMPONENT_DESTINATION}/lang/ )
list( LENGTH BRANDING_TRANSLATION_FILES _branding_count )
message( " ${Green}BRANDING_TRANSLATIONS:${ColorReset} ${_branding_count} language(s)" )
endif()
endfunction()
# Usage calamares_add_branding_subdirectory( <dir> [NAME <name>] [SUBDIRECTORIES <dir> ...])
#
# Adds a branding component from a subdirectory:
# - if there is a CMakeLists.txt, use that (that CMakeLists.txt should
# call suitable calamares_add_branding() and other macros to install
# the branding component).
# - otherwise assume a "standard" setup with top-level files and a lang/
# subdirectory for translations.
#
# If NAME is given, this is used instead of <dir> as the name of
# the branding component. This is needed if <dir> is more than
# one level deep, or to rename a component as it gets installed.
#
# If SUBDIRECTORIES are given, they are relative to <dir>, and are
# copied (one level deep) to the install location as well.
function( calamares_add_branding_subdirectory SUBDIRECTORY )
cmake_parse_arguments( _CABS "" "NAME" "SUBDIRECTORIES" ${ARGN} )
if (NOT _CABS_NAME)
set(_CABS_NAME "${SUBDIRECTORY}")
endif()
if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/CMakeLists.txt" )
add_subdirectory( ${SUBDIRECTORY} )
elseif( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/branding.desc" )
calamares_add_branding( ${_CABS_NAME} DIRECTORY ${SUBDIRECTORY} SUBDIRECTORIES ${_CABS_SUBDIRECTORIES} )
if( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/lang" )
calamares_add_branding_translations( ${_CABS_NAME} DIRECTORY ${SUBDIRECTORY} )
endif()
else()
message( "-- ${BoldYellow}Warning:${ColorReset} tried to add branding component subdirectory ${BoldRed}${SUBDIRECTORY}${ColorReset} which has no branding.desc." )
endif()
message( "" )
endfunction()
# === This file is part of Calamares - <https://calamares.io> ===
#
# SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
# SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
#
# Calamares is Free Software: see the License-Identifier above.
#
#
###
#
# Support functions for building plugins.
#
# Usage:
#
# calamares_add_library(
# library-name
# EXPORT_MACRO macro-name
# TARGET_TYPE <STATIC|MODULE|...>
# EXPORT export-name
# VERSION version
# SOVERSION version
# INSTALL_BINDIR dir
# RESOURCES resource-file
# SOURCES source-file...
# UI ui-file...
# LINK_LIBRARIES lib...
# LINK_PRIVATE_LIBRARIES lib...
# COMPILE_DEFINITIONS def...
# [NO_INSTALL]
# [NO_VERSION]
# )
#
# The COMPILE_DEFINITIONS are set on the resulting module with a suitable
# flag (i.e. `-D`) so only state the name (optionally, also the value)
# without a `-D` prefixed to it. Pass in a CMake list as needed.
include( CMakeParseArguments )
include( CalamaresAutomoc )
function(calamares_add_library)
# parse arguments (name needs to be saved before passing ARGN into the macro)
set(NAME ${ARGV0})
set(options NO_INSTALL NO_VERSION)
set(oneValueArgs NAME TYPE EXPORT_MACRO TARGET TARGET_TYPE EXPORT VERSION SOVERSION INSTALL_BINDIR RESOURCES)
set(multiValueArgs SOURCES UI LINK_LIBRARIES LINK_PRIVATE_LIBRARIES COMPILE_DEFINITIONS QT5_MODULES)
set(oneValueArgs NAME EXPORT_MACRO TARGET_TYPE EXPORT VERSION SOVERSION INSTALL_BINDIR RESOURCES)
set(multiValueArgs SOURCES UI LINK_LIBRARIES LINK_PRIVATE_LIBRARIES COMPILE_DEFINITIONS)
cmake_parse_arguments(LIBRARY "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(LIBRARY_NAME ${NAME})
# message("*** Arguments for ${LIBRARY_NAME}")
# message("Sources: ${LIBRARY_SOURCES}")
# message("Link libraries: ${LIBRARY_LINK_LIBRARIES}")
# message("UI: ${LIBRARY_UI}")
# message("TARGET_TYPE: ${LIBRARY_TARGET_TYPE}")
# message("EXPORT_MACRO: ${LIBRARY_EXPORT_MACRO}")
# message("NO_INSTALL: ${LIBRARY_NO_INSTALL}")
set(target ${LIBRARY_NAME})
# qt stuff
include_directories(${CMAKE_CURRENT_LIST_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if(LIBRARY_UI)
qt5_wrap_ui(LIBRARY_UI_SOURCES ${LIBRARY_UI})
list(APPEND LIBRARY_SOURCES ${LIBRARY_UI_SOURCES})
endif()
# add resources from current dir
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${LIBRARY_RESOURCES}")
qt5_add_resources(LIBRARY_RC_SOURCES "${LIBRARY_RESOURCES}")
list(APPEND LIBRARY_SOURCES ${LIBRARY_RC_SOURCES})
unset(LIBRARY_RC_SOURCES)
if(LIBRARY_RESOURCES)
list(APPEND LIBRARY_SOURCES ${LIBRARY_RESOURCES})
endif()
# add target
......@@ -41,35 +62,38 @@ function(calamares_add_library)
add_library(${target} STATIC ${LIBRARY_SOURCES})
elseif(LIBRARY_TARGET_TYPE STREQUAL "MODULE")
add_library(${target} MODULE ${LIBRARY_SOURCES})
else() # default
elseif(LIBRARY_TARGET_TYPE STREQUAL "SHARED")
add_library(${target} SHARED ${LIBRARY_SOURCES})
else() # default
message(FATAL_ERROR "Invalid library type '${LIBRARY_TARGET_TYPE}'")
endif()
# HACK: add qt modules - every lib should define its own set of modules
qt5_use_modules(${target} Core Gui Widgets ${LIBRARY_QT5_MODULES})
# definitions - can this be moved into set_target_properties below?
add_definitions(${QT_DEFINITIONS})
set_target_properties(${target} PROPERTIES AUTOMOC TRUE)
calamares_automoc(${target})
if(LIBRARY_UI)
calamares_autouic(${target} ${LIBRARY_UI})
endif()
if(LIBRARY_RESOURCES)
calamares_autorcc(${target} ${LIBRARY_RESOURCES})
endif()
if(LIBRARY_EXPORT_MACRO)
set_target_properties(${target} PROPERTIES COMPILE_DEFINITIONS ${LIBRARY_EXPORT_MACRO})
endif()
if(LIBRARY_COMPILE_DEFINITIONS)
# Dear CMake, i hate you! Sincerely, domme
# At least in CMake 2.8.8, you CANNOT set more than one COMPILE_DEFINITIONS value
# only takes the first one if called multiple times or bails out with wrong number of arguments
# when passing in a list, thus i redefine the export macro here in hope it won't mess up other targets
add_definitions( "-D${LIBRARY_EXPORT_MACRO}" )
set_target_properties(${target} PROPERTIES COMPILE_DEFINITIONS ${LIBRARY_COMPILE_DEFINITIONS})
set( _lib_definitions "${LIBRARY_EXPORT_MACRO}" ${LIBRARY_COMPILE_DEFINITIONS} )
set_target_properties(${target} PROPERTIES COMPILE_DEFINITIONS "${_lib_definitions}")
endif()
# add link targets
target_link_libraries(${target} ${CALAMARES_LIBRARIES})
target_link_libraries(${target}
LINK_PUBLIC ${Calamares_LIBRARIES}
${qtname}::Core
${qtname}::Gui
${qtname}::Widgets
)
if(LIBRARY_LINK_LIBRARIES)
target_link_libraries(${target} ${LIBRARY_LINK_LIBRARIES})
target_link_libraries(${target} LINK_PUBLIC ${LIBRARY_LINK_LIBRARIES})
endif()
if(LIBRARY_LINK_PRIVATE_LIBRARIES)
target_link_libraries(${target} LINK_PRIVATE ${LIBRARY_LINK_PRIVATE_LIBRARIES})
......@@ -94,9 +118,6 @@ function(calamares_add_library)
set(LIBRARY_INSTALL_LIBDIR "${LIBRARY_INSTALL_BINDIR}")
endif()
#message("INSTALL_BINDIR: ${LIBRARY_INSTALL_BINDIR}")
#message("INSTALL_LIBDIR: ${LIBRARY_INSTALL_LIBDIR}")
# make installation optional, maybe useful for dummy plugins one day
if(NOT LIBRARY_NO_INSTALL)
include(GNUInstallDirs)
......
# === This file is part of Calamares - <https://calamares.io> ===
#
# SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
# SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
#
# Calamares is Free Software: see the License-Identifier above.
#
#
###
#
# Function and support code for adding a Calamares module (either a Qt / C++ plugin,
# or a Python module, or whatever) to the build.
#
# # Usage
#
# The public API is one single function:
#
# - calamares_add_module_subdirectory(subdirectory [skiplistvar])
# Adds a given *subdirectory* to the modules list, building the
# module that is there. The *subdirectory* must contain a `module.desc`
# (generally non-C++ modules) or a `CMakeLists.txt` (for C++ modules,
# or special cases). The module is assumed to be named after the
# (last component of) the subdirectory.
#
# If the module would be skipped (by the global SKIP_MODULES setting
# or a USE_* setting) or the module itself sets a reason to skip
# via the calamares_skip_module() function, the module is added to
# the list of skipped-modules in *skiplistvar*. If no variable is
# given, the reason is set in the parent scope variable
# SKIPPED_MODULES . Do **not** use SKIPPED_MODULES as the name of
# *skiplistvar*, things will get weird.
#
# Do note that the name of a module must be the same as the name of
# the directory containing it (as documented in src/modules/README.md).
# This applies to both C++ and Python modules, and allows the use of
# the subdirectory as a proxy for the module name inside.
#
include( CalamaresAddTranslations )
include( CalamaresCheckModuleSelection )
set( MODULE_DATA_DESTINATION share/calamares/modules )
# We look for Pylint (just once) so that unittests can be added that
# check the syntax / variables of Python modules. This should help
# avoid more typo's-in-releases.
if(BUILD_TESTING AND NOT PYLINT_COMMAND_SEARCHED)
set(PYLINT_COMMAND_SEARCHED TRUE)
find_program(
PYLINT_COMMAND
NAMES pylint3 pylint
PATHS $ENV{HOME}/.local/bin
)
endif()
function( _calamares_add_module_subdirectory_impl )
set( SUBDIRECTORY ${ARGV0} )
# Set SKIPPED_MODULES here, so CMake-based modules have a
# parent scope to set it in; this function, in turn sets it
# in **its** parent scope.
set( SKIPPED_MODULES "" )
set( MODULE_CONFIG_FILES "" )
# The module subdirectory may be given as a/b/c, but the module
# needs to be installed as "c", so we split off any intermediate
# directories.
#
# Compute _modulename (the last directory name) and _mod_dir
# (the full path to the module sources).
get_filename_component(_dirname "${SUBDIRECTORY}" DIRECTORY)
if( _dirname )
# Remove the dirname and any leftover leading /s
string( REGEX REPLACE "^${_dirname}/*" "" _modulename "${SUBDIRECTORY}" )
else()
set( _modulename ${SUBDIRECTORY} )
endif()
# Strip any remaining /
string( REGEX REPLACE "/" "" _modulename "${_modulename}" )
set( _mod_dir "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}" )
# Skip list check applies to all kinds of modules
calamares_check_skip( ${_modulename} SKIPPED_MODULES )
if ( SKIPPED_MODULES )
# If it's skipped by infrastucture, the message already includes the module
# name. We don't need to do any further checking.
set( SKIPPED_MODULES "${SKIPPED_MODULES}" PARENT_SCOPE )
return()
endif()
# If this subdirectory has a CMakeLists.txt, we add_subdirectory it...
if( EXISTS "${_mod_dir}/CMakeLists.txt" )
add_subdirectory( ${SUBDIRECTORY} )
file( GLOB MODULE_CONFIG_FILES RELATIVE ${_mod_dir} "${SUBDIRECTORY}/*.conf" )
# Module has indicated it should be skipped, show that in
# the calling CMakeLists (which is src/modules/CMakeLists.txt normally).
if ( SKIPPED_MODULES )
set( SKIPPED_MODULES ${SKIPPED_MODULES} PARENT_SCOPE )
set( MODULE_CONFIG_FILES "" )
else()
# The SKIPPED_MODULES may be set in the directory itself
get_directory_property( _skip DIRECTORY ${SUBDIRECTORY} DEFINITION SKIPPED_MODULES )
if ( _skip )
set( SKIPPED_MODULES ${_skip} PARENT_SCOPE )
set( MODULE_CONFIG_FILES "" )
endif()
endif()
if ( SKIPPED_MODULES )
return()
endif()
# ...otherwise, we look for a module.desc.
elseif( EXISTS "${_mod_dir}/module.desc" )
set( MODULES_DIR ${CMAKE_INSTALL_LIBDIR}/calamares/modules )
set( MODULE_DESTINATION ${MODULES_DIR}/${_modulename} )
# Read module.desc, check that the interface type is supported.
#
# _mod_enabled boolean if the module should be built (only if the interface is supported)
# _mod_reason is a human-readable explanation why it isn't built
# _mod_testing boolean if the module should be added to the loadmodule tests
file(STRINGS "${_mod_dir}/module.desc" MODULE_INTERFACE REGEX "^interface")
if ( MODULE_INTERFACE MATCHES "pythonqt" )
message( FATAL_ERROR "PythonQt is no longer supported" )
set( _mod_enabled OFF )
set( _mod_reason "No PythonQt support" )
set( _mod_testing OFF )
elseif ( MODULE_INTERFACE MATCHES "python" )
set( _mod_enabled ${Calamares_WITH_PYTHON} )
set( _mod_reason "No Python support" )
set( _mod_testing ON ) # Will check syntax and imports, at least
elseif ( MODULE_INTERFACE MATCHES "qtplugin" )
set( _mod_enabled OFF )
set( _mod_reason "C++ modules must have a CMakeLists.txt instead" )
set( _mod_testing OFF )
elseif ( MODULE_INTERFACE MATCHES "process" )
set( _mod_enabled ON )
set( _mod_reason "" )
set( _mod_testing OFF )
else()
set( _mod_enabled OFF )
set( _mod_reason "Unknown module interface '${MODULE_INTERFACE}'" )
set( _mod_testing OFF )
endif()
if ( _mod_enabled )
# We glob all the files inside the subdirectory, and we make sure they are
# synced with the bindir structure and installed.
file( GLOB MODULE_FILES RELATIVE ${_mod_dir} "${SUBDIRECTORY}/*" )
foreach( MODULE_FILE ${MODULE_FILES} )
if( NOT IS_DIRECTORY ${_mod_dir}/${MODULE_FILE} )
configure_file( ${SUBDIRECTORY}/${MODULE_FILE} ${SUBDIRECTORY}/${MODULE_FILE} COPYONLY )
get_filename_component( FLEXT ${MODULE_FILE} EXT )
if( "${FLEXT}" STREQUAL ".conf" )
message(STATUS "Config ${MODULE_FILE}")
list( APPEND MODULE_CONFIG_FILES ${MODULE_FILE} )
else()
message(STATUS "Non-Config ${MODULE_FILE}")
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBDIRECTORY}/${MODULE_FILE}
DESTINATION ${MODULE_DESTINATION} )
endif()
endif()
endforeach()
message( "-- ${BoldYellow}Found ${CALAMARES_APPLICATION_NAME} module: ${BoldRed}${_modulename}${ColorReset}" )
message( " ${Green}TYPE:${ColorReset} jobmodule" )
message( " ${Green}MODULE_DESTINATION:${ColorReset} ${MODULE_DESTINATION}" )
if( MODULE_CONFIG_FILES )
if (INSTALL_CONFIG)
message(" ${Green}CONFIGURATION_FILES:${ColorReset} ${MODULE_CONFIG_FILES} => [Build directory and ${MODULE_DATA_DESTINATION}]")
foreach(_cf ${MODULE_CONFIG_FILES})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBDIRECTORY}/${_cf} DESTINATION ${MODULE_DATA_DESTINATION})
endforeach()
else()
message(" ${Green}CONFIGURATION_FILES:${ColorReset} ${MODULE_CONFIG_FILES} => [Build directory only]")
endif()
endif()
message( "" )
# We copy over the lang directory, if any
if( IS_DIRECTORY "${_mod_dir}/lang" )
install_calamares_gettext_translations(
${SUBDIRECTORY}
SOURCE_DIR "${_mod_dir}/lang"
FILENAME ${SUBDIRECTORY}.mo
RENAME calamares-${SUBDIRECTORY}.mo
)
endif()
else()
# Module disabled due to missing dependencies / unsupported interface
set( SKIPPED_MODULES "${SUBDIRECTORY} (${_mod_reason})" PARENT_SCOPE )
endif()
else()
message( "-- ${BoldYellow}Warning:${ColorReset} tried to add module subdirectory ${BoldRed}${SUBDIRECTORY}${ColorReset} which has no CMakeLists.txt or module.desc." )
message( "" )
endif()
# Check any config files for basic correctness
if ( BUILD_TESTING AND MODULE_CONFIG_FILES )
set( _count 0 )
foreach( _config_file ${MODULE_CONFIG_FILES} )
set( _count_str "-${_count}" )
if ( _count EQUAL 0 )
set( _count_str "" )
endif()
add_test(
NAME config-${SUBDIRECTORY}${_count_str}
COMMAND test_conf ${CMAKE_CURRENT_BINARY_DIR}/${SUBDIRECTORY}/${_config_file} )
math( EXPR _count "${_count} + 1" )
endforeach()
endif()
# Adding general tests
#
# Add a check that the module can be loaded. Since this calls exec(), the module
# may try to do things to the running system. Needs work to make that a
# safe thing to do.
#
# If the module has a tests/ subdirectory with *.global and *.job
# files (YAML files holding global and job-configurations for
# testing purposes) then those files are used to drive additional
# tests. The files must be numbered (starting from 1) for this to work;
# 1.global and 1.job together make the configuration for test 1.
#
# If the module has a tests/CMakeLists.txt while it doesn't have its
# own CMakeLists.txt (e.g. a Python module), then the subdirectory
# for tests/ is added on its own.
#
if ( BUILD_TESTING AND _mod_enabled AND _mod_testing )
add_test(
NAME load-${SUBDIRECTORY}
COMMAND loadmodule ${SUBDIRECTORY}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
# Try it with the tests/ configurations shipped with the module
set( _count 1 )
set( _testdir ${_mod_dir}/tests )
while ( EXISTS "${_testdir}/${_count}.global" OR EXISTS "${_testdir}/${_count}.job" )
set( _dash_g "" )
set( _dash_j "" )
if ( EXISTS "${_testdir}/${_count}.global" )
set( _dash_g -g ${_testdir}/${_count}.global )
endif()
if ( EXISTS "${_testdir}/${_count}.job" )
set( _dash_j -j ${_testdir}/${_count}.job )
endif()
add_test(
NAME load-${SUBDIRECTORY}-${_count}
COMMAND loadmodule ${_dash_g} ${_dash_j} ${SUBDIRECTORY}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
math( EXPR _count "${_count} + 1" )
endwhile()
if ( EXISTS ${_testdir}/CMakeTests.txt AND NOT EXISTS ${_mod_dir}/CMakeLists.txt )
include( ${_testdir}/CMakeTests.txt )
endif()
if ( PYLINT_COMMAND AND MODULE_INTERFACE MATCHES "python" )
# Python modules get an additional test via pylint; this
# needs to run at top-level because the ci/libcalamares directory
# contains API stubs.
#
# TODO: the entry point is assumed to be `main.py`, but that is
# configurable through module.desc
add_test(
NAME lint-${SUBDIRECTORY}
COMMAND env PYTHONPATH=ci: ${PYLINT_COMMAND} -E ${_mod_dir}/main.py
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()
endif()
endfunction()
function( calamares_add_module_subdirectory )
set( SUBDIRECTORY ${ARGV0} )
set( _ams_SKIP_LIST ${ARGV1} )
set( SKIPPED_MODULES "" )
_calamares_add_module_subdirectory_impl( ${SUBDIRECTORY} )
if ( SKIPPED_MODULES )
if ( _ams_SKIP_LIST )
list( APPEND ${_ams_SKIP_LIST} "${SKIPPED_MODULES}" )
set( ${_ams_SKIP_LIST} "${${_ams_SKIP_LIST}}" PARENT_SCOPE )
else()
set( SKIPPED_MODULES "${SKIPPED_MODULES}" PARENT_SCOPE )
endif()
endif()
endfunction()
# === This file is part of Calamares - <https://calamares.io> ===
#
# SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
# SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
#
# Calamares is Free Software: see the License-Identifier above.
#
#
###
#
# Convenience function for creating a C++ (qtplugin) module for Calamares.
# This function provides cmake-time feedback about the plugin, adds
# targets for compilation and boilerplate information, and creates
# a module.desc with standard values (if the module.desc file exists,
# that one is used instead, which happens only for unusual plugins).
#
# Usage:
#
# calamares_add_plugin(
# module-name
# TYPE <viewmodule|job>
# EXPORT_MACRO macro-name
# SOURCES source-file...
# UI ui-file...
# LINK_LIBRARIES lib...
# LINK_PRIVATE_LIBRARIES lib...
# [COMPILE_DEFINITIONS def...]
# [RESOURCES resource-file]
# [REQUIRES module-name...]
# [NO_INSTALL]
# [NO_CONFIG]
# [SHARED_LIB]
# [EMERGENCY]
# [WEIGHT w]
# )
#
# Function optional parameters:
# - COMPILE_DEFINITIONS
# Definitions are set on the resulting module with a suitable
# flag (i.e. `-D`) so only state the name (optionally, also the value)
# without a `-D` prefixed to it.
# - RESOURCES
# One (single!) filename for the RCC file for the plugin.
# - REQUIRES
# One or more names of modules which are added to the *requiredModules*
# key in the descriptor. See *Module Requirements* in the module
# documentation.
# - NO_INSTALL
# If this is set, the module is not installed by default; use this to
# build testing modules or unit-testing modules.
# - SHARED_LIB
# In unusual circumstances, this function is used to add a library
# rather than a normal Calamares module / plugin.
# - EMERGENCY
# If this is set, the module is marked as an *emergency* module in the
# descriptor. See *Emergency Modules* in the module documentation.
# - WEIGHT
# If this is set, writes an explicit weight into the module.desc;
# module weights are used in progress reporting.
#
#
# This function follows the global SKIP_MODULES and USE_* settings, so
# a plugin may be skipped -- then nothing will be built. In that case,
# SKIPPED_MODULES is set in the parent (i.e. caller's) scope with the
# reason why. This should rarely be a concern as AddModuleSubdirectory
# already handles skip-reasons and collects them for reporting.
#
# The target defined this way is called "calamares_<TYPE>_<module-name>",
# e.g. "calamares_viewmodule_packagechooserq". The function sets a variable
# in its **calling** scope, `<module-name>_TARGET` with the full name
# of the target.
include( CMakeParseArguments )
include( CalamaresAddLibrary )
include( CalamaresCheckModuleSelection )
include( CMakeColors )
function( calamares_add_plugin )
# parse arguments ( name needs to be saved before passing ARGN into the macro )
set( NAME ${ARGV0} )
set( options NO_CONFIG NO_INSTALL SHARED_LIB EMERGENCY )
set( oneValueArgs NAME TYPE EXPORT_MACRO RESOURCES WEIGHT )
set( multiValueArgs SOURCES UI LINK_LIBRARIES LINK_PRIVATE_LIBRARIES COMPILE_DEFINITIONS REQUIRES )
cmake_parse_arguments( PLUGIN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
set( PLUGIN_NAME ${NAME} )
set( PLUGIN_DESTINATION ${CMAKE_INSTALL_LIBDIR}/calamares/modules/${PLUGIN_NAME} )
set( PLUGIN_DESC_FILE module.desc )
file( GLOB PLUGIN_CONFIG_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.conf" )
set( PLUGIN_DATA_DESTINATION share/calamares/modules )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" )
calamares_check_skip( ${NAME} _skip)
if ( _skip )
set( SKIPPED_MODULES "${_skip}" PARENT_SCOPE )
return()
endif()
message( "-- ${BoldYellow}Found ${CALAMARES_APPLICATION_NAME} module: ${BoldRed}${PLUGIN_NAME}${ColorReset}" )
message( " ${Green}TYPE:${ColorReset} ${PLUGIN_TYPE}" )
message( " ${Green}LINK_LIBRARIES:${ColorReset} ${PLUGIN_LINK_LIBRARIES}" )
message( " ${Green}LINK_PRIVATE_LIBRARIES:${ColorReset} ${PLUGIN_LINK_PRIVATE_LIBRARIES}" )
message( " ${Green}PLUGIN_DESTINATION:${ColorReset} ${PLUGIN_DESTINATION}" )
if( PLUGIN_CONFIG_FILES )
if( PLUGIN_NO_CONFIG )
message( FATAL_ERROR "${Red}NO_CONFIG${ColorReset} is set, with configuration ${Red}${PLUGIN_CONFIG_FILES}${ColorReset}" )
endif()
set( _destination "(unknown)" )
if(INSTALL_CONFIG AND NOT PLUGIN_NO_INSTALL)
set(_destination "${PLUGIN_DATA_DESTINATION}")
elseif( NOT PLUGIN_NO_INSTALL )
set( _destination "[Build directory only]" )
else()
set( _destination "[Skipping installation]" )
endif()
message( " ${Green}CONFIGURATION_FILES:${ColorReset} ${PLUGIN_CONFIG_FILES} => ${_destination}" )
else()
if( NOT PLUGIN_NO_CONFIG )
message( " ${Red}NO_CONFIG${ColorReset} should be set." )
endif()
endif()
if( PLUGIN_RESOURCES )
message( " ${Green}RESOURCES:${ColorReset} ${PLUGIN_RESOURCES}" )
endif()
message( "" )
# create target name once for convenience
set( target "calamares_${PLUGIN_TYPE}_${PLUGIN_NAME}" )
# automatic library linkage
if(PLUGIN_TYPE STREQUAL "viewmodule")
list(APPEND PLUGIN_LINK_PRIVATE_LIBRARIES Calamares::calamaresui)
elseif(PLUGIN_TYPE STREQUAL "job")
list(APPEND PLUGIN_LINK_PRIVATE_LIBRARIES Calamares::calamares)
else()
message(FATAL_ERROR "Unknown plugin type ${PLUGIN_TYPE}")
endif()
# determine target type
if( NOT ${PLUGIN_SHARED_LIB} )
set( target_type "MODULE" )
else()
set( target_type "SHARED" )
endif()
set( calamares_add_library_args
"${target}"
"EXPORT_MACRO" "${PLUGIN_EXPORT_MACRO}"
"TARGET_TYPE" "${target_type}"
"SOURCES" "${PLUGIN_SOURCES}"
)
if( PLUGIN_UI )
list( APPEND calamares_add_library_args "UI" "${PLUGIN_UI}" )
endif()
if( PLUGIN_LINK_LIBRARIES )
list( APPEND calamares_add_library_args "LINK_LIBRARIES" "${PLUGIN_LINK_LIBRARIES}" )
endif()
if( PLUGIN_LINK_PRIVATE_LIBRARIES )
list( APPEND calamares_add_library_args "LINK_PRIVATE_LIBRARIES" "${PLUGIN_LINK_PRIVATE_LIBRARIES}" )
endif()
if( PLUGIN_COMPILE_DEFINITIONS )
list( APPEND calamares_add_library_args "COMPILE_DEFINITIONS" ${PLUGIN_COMPILE_DEFINITIONS} )
endif()
if ( PLUGIN_NO_INSTALL )
list( APPEND calamares_add_library_args "NO_INSTALL" )
endif()
list( APPEND calamares_add_library_args
"NO_VERSION"
"INSTALL_BINDIR" "${PLUGIN_DESTINATION}"
)
if( PLUGIN_RESOURCES )
list( APPEND calamares_add_library_args "RESOURCES" "${PLUGIN_RESOURCES}" )
endif()
calamares_add_library( ${calamares_add_library_args} )
if ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PLUGIN_DESC_FILE} )
configure_file( ${PLUGIN_DESC_FILE} ${PLUGIN_DESC_FILE} COPYONLY )
else()
set( _file ${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_DESC_FILE} )
set( _type ${PLUGIN_TYPE} )
file( WRITE ${_file} "# AUTO-GENERATED metadata file\n# Syntax is YAML 1.2\n---\n" )
file( APPEND ${_file} "type: \"${_type}\"\nname: \"${PLUGIN_NAME}\"\ninterface: \"qtplugin\"\nload: \"lib${target}.so\"\n" )
if ( PLUGIN_REQUIRES )
file( APPEND ${_file} "requiredModules:\n" )
foreach( _r ${PLUGIN_REQUIRES} )
file( APPEND ${_file} " - ${_r}\n" )
endforeach()
endif()
if ( PLUGIN_EMERGENCY )
file( APPEND ${_file} "emergency: true\n" )
endif()
if ( PLUGIN_NO_CONFIG )
file( APPEND ${_file} "noconfig: true\n" )
endif()
if ( PLUGIN_WEIGHT )
file( APPEND ${_file} "weight: ${PLUGIN_WEIGHT}\n" )
endif()
endif()
if ( NOT PLUGIN_NO_INSTALL )
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_DESC_FILE}
DESTINATION ${PLUGIN_DESTINATION} )
set( _warned_config OFF )
foreach( PLUGIN_CONFIG_FILE ${PLUGIN_CONFIG_FILES} )
if( ${CMAKE_CURRENT_SOURCE_DIR}/${PLUGIN_CONFIG_FILE} IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_CONFIG_FILE} )
configure_file( ${PLUGIN_CONFIG_FILE} ${PLUGIN_CONFIG_FILE} COPYONLY )
else()
message( " ${BoldYellow}Not updating${ColorReset} ${PLUGIN_CONFIG_FILE}" )
set( _warned_config ON )
endif()
if(INSTALL_CONFIG)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_CONFIG_FILE} DESTINATION ${PLUGIN_DATA_DESTINATION})
endif()
endforeach()
if ( _warned_config )
message( "" )
endif()
endif()
set(${NAME}_TARGET ${target} PARENT_SCOPE)
endfunction()
# === This file is part of Calamares - <https://calamares.io> ===
#
# SPDX-FileCopyrightText: 2020 Adriaan de Groot <groot@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
#
# Calamares is Free Software: see the License-Identifier above.
#
#
###
#
# Support functions for building Calamares tests.
# This extends KDE's ECM tests with some custom patterns.
#
# calamares_add_test(
# <NAME>
# [GUI]
# [RESOURCES FILE]
# SOURCES <FILE..>
# )
include(CMakeParseArguments)
include(CalamaresAutomoc)
function(calamares_add_test name)
set(options GUI)
set(oneValueArgs RESOURCES)
set(multiValueArgs SOURCES LIBRARIES DEFINITIONS)
cmake_parse_arguments(TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(TEST_NAME ${name})
if(ECM_FOUND AND BUILD_TESTING)
ecm_add_test(
${TEST_SOURCES} ${TEST_RESOURCES}
TEST_NAME
${TEST_NAME}
LINK_LIBRARIES
Calamares::calamares
${TEST_LIBRARIES}
${qtname}::Core
${qtname}::Test
)
calamares_automoc( ${TEST_NAME} )
# We specifically pass in the source directory of the test-being-
# compiled, so that it can find test-files in that source dir.
target_compile_definitions(
${TEST_NAME}
PRIVATE -DBUILD_AS_TEST="${CMAKE_CURRENT_SOURCE_DIR}" ${TEST_DEFINITIONS}
)
if(TEST_GUI)
target_link_libraries(${TEST_NAME} Calamares::calamaresui ${qtname}::Gui)
endif()
if(TEST_RESOURCES)
calamares_autorcc( ${TEST_NAME} ${TEST_RESOURCES} )
endif()
endif()
endfunction()
# === This file is part of Calamares - <https://calamares.io> ===
#
# SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
#
# Calamares is Free Software: see the License-Identifier above.
#
#
###
#
# This file has not yet been documented for use outside of Calamares itself.
include(CMakeParseArguments)
include(FeatureSummary)
# The Gettext module is still old-fashioned, ALLCAPS variables
find_package( Gettext )
set_package_properties( GETTEXT PROPERTIES
DESCRIPTION "GNU gettext (translation) tools."
URL "https://www.gnu.org/software/gettext/"
PURPOSE "Gettext is used in the translation of Python modules."
TYPE REQUIRED
)
# Installs a directory containing language-code-labeled subdirectories with
# gettext data into the appropriate system directory. Allows renaming the
# .mo files during install to avoid namespace clashes.
#
# install_calamares_gettext_translations(
# NAME <name of module, for human use>
# SOURCE_DIR path/to/lang
# FILENAME <name of file.mo>
# [RENAME <new-name of.mo>]
# )
#
# For all of the (global) translation languages enabled for Calamares,
# try installing $SOURCE_DIR/$lang/LC_MESSAGES/<filename>.mo into the
# system gettext data directory (e.g. share/locale/), possibly renaming
# filename.mo to renamed.mo in the process.
function( install_calamares_gettext_translations )
# parse arguments ( name needs to be saved before passing ARGN into the macro )
set( NAME ${ARGV0} )
set( oneValueArgs NAME SOURCE_DIR FILENAME RENAME )
cmake_parse_arguments( TRANSLATION "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
if( NOT TRANSLATION_NAME )
set( TRANSLATION_NAME ${NAME} )
endif()
if( NOT TRANSLATION_FILENAME )
set( TRANSLATION_FILENAME "${TRANSLATION_NAME}.mo" )
endif()
if( NOT TRANSLATION_RENAME )
set( TRANSLATION_RENAME "${TRANSLATION_FILENAME}" )
endif()
string( REGEX REPLACE ".mo$" ".po" TRANSLATION_SOURCE_FILENAME "${TRANSLATION_FILENAME}" )
if ( GETTEXT_FOUND AND GETTEXT_MSGFMT_EXECUTABLE )
message( STATUS "Installing gettext translations for ${TRANSLATION_NAME}")
message( STATUS " Installing ${TRANSLATION_FILENAME} from ${TRANSLATION_SOURCE_DIR}")
else()
message( WARNING "Gettext translations requested for ${TRANSLATION_NAME}, but gettext was not found." )
return()
endif()
set( TARGET_NAME calamares-gettext-translations-${NAME} )
if( NOT TARGET "${TARGET_NAME}" )
add_custom_target( "${TARGET_NAME}" ALL )
endif()
set( TRANSLATION_NAME "${NAME}" )
foreach( lang ${CALAMARES_TRANSLATION_LANGUAGES} ) # Global
string( MAKE_C_IDENTIFIER "${TARGET_NAME}-${lang}" TARGET_SUBNAME )
set( lang_po "${TRANSLATION_SOURCE_DIR}/${lang}/LC_MESSAGES/${TRANSLATION_SOURCE_FILENAME}" )
set( lang_mo_dir "${CMAKE_BINARY_DIR}/lang/${lang}/LC_MESSAGES" )
set( lang_mo "${lang_mo_dir}/${TRANSLATION_RENAME}" )
if( lang STREQUAL "en" )
message( STATUS " Skipping ${TRANSLATION_NAME} translations for en_US" )
else()
# We **don't** use the gettext macro's here because the source
# structure doesn't match: we are calling this once per language
# for all of Calamares's languages, while the gettext module
# expects it to be called once, for a given language source-dir.
#
# Using any of the gettext macros just gets us multiple rules
# for python.gmo, and it wants to use msgmerge, besides, which
# doesn't fit our Transifex workflow.
make_directory( ${lang_mo_dir} )
add_custom_command(
OUTPUT ${lang_mo}
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE}
ARGS -o ${lang_mo} ${lang_po}
MAIN_DEPENDENCY ${lang_po}
)
add_custom_target( "${TARGET_SUBNAME}" DEPENDS ${lang_mo} )
add_dependencies( "${TARGET_NAME}" "${TARGET_SUBNAME}" )
install(
FILES ${lang_mo}
DESTINATION ${CMAKE_INSTALL_LOCALEDIR}/${lang}/LC_MESSAGES/
)
endif()
endforeach()
endfunction()
set(_calamares_qrc_translations_qrc_source ${CMAKE_CURRENT_LIST_DIR}/i18n.qrc.in) # Needs to be set outside of function
function(calamares_qrc_translations basename)
set(options "")
set(oneValueArgs SUBDIRECTORY OUTPUT_VARIABLE)
set(multiValueArgs PREFIXES LANGUAGES)
cmake_parse_arguments(_qrt "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT _qrt_OUTPUT_VARIABLE)
message(FATAL_ERROR "No output variable")
endif()
if(NOT _qrt_PREFIXES)
set(_qrt_PREFIXES "${basename}")
endif()
if(NOT _qrt_LANGUAGES)
set(_qrt_LANGUAGES ${CALAMARES_TRANSLATION_LANGUAGES})
endif()
if(NOT _qrt_SUBDIRECTORY)
set(_qrt_SUBDIRECTORY "")
endif()
set(translations_qrc_infile ${CMAKE_CURRENT_BINARY_DIR}/${basename}.qrc)
set(translations_qrc_outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${basename}.cxx)
# Must use this variable name because of the @ substitution
set(calamares_i18n_qrc_content "")
set(calamares_i18n_ts_filelist "")
foreach(lang ${_qrt_LANGUAGES})
foreach(tlsource ${_qrt_PREFIXES})
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_qrt_SUBDIRECTORY}/${tlsource}_${lang}.ts")
string(APPEND calamares_i18n_qrc_content "<file>${tlsource}_${lang}.qm</file>\n")
list(APPEND calamares_i18n_ts_filelist "${CMAKE_CURRENT_SOURCE_DIR}/${_qrt_SUBDIRECTORY}/${tlsource}_${lang}.ts")
endif()
endforeach()
endforeach()
configure_file(${_calamares_qrc_translations_qrc_source} ${translations_qrc_infile} @ONLY)
qt_add_translation(QM_FILES ${calamares_i18n_ts_filelist})
# Run the resource compiler (rcc_options should already be set)
add_custom_command(
OUTPUT ${translations_qrc_outfile}
COMMAND ${qtname}::rcc
ARGS
${rcc_options}
--format-version 1
-name ${basename}
-o ${translations_qrc_outfile}
${translations_qrc_infile}
MAIN_DEPENDENCY ${translations_qrc_infile}
DEPENDS ${QM_FILES}
)
set(${_qrt_OUTPUT_VARIABLE} ${translations_qrc_outfile} PARENT_SCOPE)
endfunction()