Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port: 2 to 3 #118

Merged
merged 8 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_FEATURES",
"GZ_ROOT",
"GZ_VISIBILITY",
"gz_configure_header",
"gz_export_header",
"gz_include_header",
)
load("@rules_license//rules:license.bzl", "license")

package(
default_applicable_licenses = [GZ_ROOT + "utils:license"],
default_visibility = GZ_VISIBILITY,
features = GZ_FEATURES,
)

licenses(["notice"]) # Apache-2.0
license(
name = "license",
package_name = "gz-utils",
)

licenses(["notice"])

exports_files(["LICENSE"])

Expand All @@ -39,8 +47,8 @@ gz_include_header(
name = "utilshh_genrule",
out = "include/gz/utils.hh",
hdrs = public_headers_no_gen + [
"include/gz/utils/config.hh",
"include/gz/utils/Export.hh",
"include/gz/utils/config.hh",
],
)

Expand All @@ -54,6 +62,7 @@ cc_library(
name = "utils",
srcs = ["src/Environment.cc"],
hdrs = public_headers,
copts = ["-fexceptions"],
includes = ["include"],
)

Expand All @@ -72,6 +81,7 @@ cc_library(

cc_test(
name = "ImplPtr_TEST",
size = "small",
srcs = ["test/integration/implptr/ImplPtr_TEST.cc"],
deps = [
":implptr_test_classes",
Expand All @@ -93,6 +103,7 @@ cc_test(
cc_test(
name = "NeverDestroyed_TEST",
srcs = ["src/NeverDestroyed_TEST.cc"],
copts = ["-fexceptions"],
deps = [
":utils",
"@gtest",
Expand Down
20 changes: 20 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@

## Gazebo Utils 2.x

## Gazebo Utils 2.2.0 (2023-11-08)

1. Make the single argument constructor inherit the env
* [Pull request #113](https://github.com/gazebosim/gz-utils/pull/113)

1. Add new functions for manipulating the environment
* [Pull request #114](https://github.com/gazebosim/gz-utils/pull/114)

1. Add license checking support to bazel
* [Pull request #108](https://github.com/gazebosim/gz-utils/pull/108)

1. Include what you use
* [Pull request #107](https://github.com/gazebosim/gz-utils/pull/107)

1. Ensure all licenses are reflected in the LICENSE file
* [Pull request #106](https://github.com/gazebosim/gz-utils/pull/106)

1. Not sure why this was here, but it is unused
* [Pull request #105](https://github.com/gazebosim/gz-utils/pull/105)

## Gazebo Utils 2.1.0 (2023-09-26)

1. Documentation fixes
Expand Down
59 changes: 58 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,61 @@

END OF TERMS AND CONDITIONS


------------------

Files: cli/include/vendored-cli/*

CLI11 1.8 Copyright (c) 2017-2019 University of Cincinnati, developed by Henry
Schreiner under NSF AWARD 1414736. All rights reserved.

Redistribution and use in source and binary forms of CLI11, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

------------------

Files: include/gz/utils/detail/subprocess.h

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>
17 changes: 16 additions & 1 deletion cli/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_ROOT",
"GZ_VISIBILITY",
)
load("@rules_license//rules:license.bzl", "license")

package(
default_applicable_licenses = [GZ_ROOT + "utils/cli:license"],
)

license(
name = "license",
package_name = "gz-utils-cli",
)

public_headers = [
"include/gz/utils/cli/GzFormatter.hpp",
Expand All @@ -12,10 +23,14 @@ public_headers = [
cc_library(
name = "cli",
hdrs = public_headers,
copts = ["-fexceptions"],
includes = [
"include",
"include/external-cli",
],
visibility = GZ_VISIBILITY,
deps = ["@cli11"],
deps = [
GZ_ROOT + "utils:utils",
"@cli11"
],
)
2 changes: 2 additions & 0 deletions cli/include/gz/utils/cli/GzFormatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
#define GZ_UTILS_CLI_GZ_FORMATTER_HPP_

#include <algorithm>
#include <iterator>
#include <string>
#include <sstream>
#include <vector>
#include <unordered_map>

#include "gz/utils/cli/App.hpp"
#include "gz/utils/cli/FormatterFwd.hpp"
#include "gz/utils/cli/StringTools.hpp"
#include "gz/utils/Export.hh"

//////////////////////////////////////////////////
Expand Down
63 changes: 62 additions & 1 deletion include/gz/utils/Environment.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <gz/utils/Export.hh>

#include <string>
#include <unordered_map>
#include <vector>

namespace gz
{
Expand Down Expand Up @@ -66,7 +68,66 @@ bool GZ_UTILS_VISIBLE setenv(
/// \return True if the variable was unset or false otherwise.
bool GZ_UTILS_VISIBLE unsetenv(const std::string &_name);

}
/// \brief Unset all environment variables
///
/// Note: This function is not thread-safe and should not be called
/// concurrently with `env` or `setenv`
///
/// \return True if the environment was unset or false otherwise.
bool GZ_UTILS_VISIBLE clearenv();

/// \brief Type alias for a collection of environment variables
using EnvironmentMap = std::unordered_map<std::string, std::string>;

/// \brief Type alias for a collection of environment variables
/// Each entry is of the form KEY=VAL
using EnvironmentStrings = std::vector<std::string>;

/// \brief Convert a vector of environment variables to a map
///
/// \param[in] _envStrings Vector collection of environment variables
/// \return Mapped collection of environment variables.
EnvironmentMap GZ_UTILS_VISIBLE envStringsToMap(
const EnvironmentStrings &_envStrings);

/// \brief Convert a map of environment variables to a vector
///
/// \param[in] _envMap Collection of mapped environment variables.
/// \return Vector collection of environment variables.
EnvironmentStrings GZ_UTILS_VISIBLE envMapToStrings(
const EnvironmentMap &_envMap);

/// \brief Retrieve all current environment variables
///
/// Note: This function is not thread-safe and should not be called
/// concurrently with `setenv` or `unsetenv`
///
/// \return A collection of current environment variables
EnvironmentMap GZ_UTILS_VISIBLE env();

/// \brief Set the environment variable '_name'.
///
/// Note: On Windows setting an empty string (_value=="")
/// is the equivalent of unsetting the variable.
//
/// Note: This function is not thread-safe and should not be called
/// concurrently with `env` or `unsetenv`
///
/// \param[in] _vars Collection of environment variables to set
/// \return True if all variables were set or false otherwise.
bool GZ_UTILS_VISIBLE setenv(const EnvironmentMap &_vars);

/// \brief Print the entire current environment to a string
///
/// This prints each variable in the form KEY=VALUE\n
///
/// Note: This function is not thread-safe and should not be called
/// concurrently with `setenv` or `unsetenv`
///
/// \return A string containing all environment variables
/// NOLINTNEXTLINE - This is incorrectly parsed as a global variable
std::string GZ_UTILS_VISIBLE printenv();
} // namespace GZ_UTILS_VERSION_NAMESPACE
} // namespace utils
} // namespace gz

Expand Down
Loading
Loading