diff options
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/bomtool/main.c | 35 | ||||
| -rw-r--r-- | cli/main.c | 21 | ||||
| -rw-r--r-- | cli/spdxtool/util.c | 29 | ||||
| -rw-r--r-- | cli/spdxtool/util.h | 3 |
4 files changed, 37 insertions, 51 deletions
diff --git a/cli/bomtool/main.c b/cli/bomtool/main.c index 136d7c1ce2ca..106820a41230 100644 --- a/cli/bomtool/main.c +++ b/cli/bomtool/main.c @@ -29,10 +29,12 @@ #define PKG_HELP (((uint64_t) 1) << 3) #define PKG_OUTPUT (((uint64_t) 1) << 4) #define PKG_DEFINE_VARIABLE (((uint64_t) 1) << 5) +#define PKG_CREATION_TIME (((uint64_t) 1) << 6) static const char *spdx_version = "SPDX-2.2"; static const char *bom_license = "CC0-1.0"; static const char *document_ref = "SPDXRef-DOCUMENT"; +static const char *creation_time = NULL; static pkgconf_client_t pkg_client; static uint64_t want_flags; @@ -148,13 +150,26 @@ write_sbom_header(pkgconf_client_t *client, pkgconf_pkg_t *world) free(docname); - OUTPUT_OR_RET_FALSE(client, sbom_out, "DocumentNamespace: https://spdx.org/spdxdocs/bomtool-%s\n", PACKAGE_VERSION); - OUTPUT_OR_RET_FALSE(client, sbom_out, "Creator: Tool: bomtool %s\n", PACKAGE_VERSION); + OUTPUT_OR_RET_FALSE(client, sbom_out, "DocumentNamespace: https://spdx.org/spdxdocs/bomtool\n"); + OUTPUT_OR_RET_FALSE(client, sbom_out, "Creator: Tool: bomtool\n"); - t = time(NULL); - tm = gmtime(&t); - strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", tm); - OUTPUT_OR_RET_FALSE(client, sbom_out, "Created: %s\n", buf); + if (creation_time != NULL) + { + OUTPUT_OR_RET_FALSE(client, sbom_out, "Created: %s\n", creation_time); + } + else + { + const char *source_date_epoch = getenv("SOURCE_DATE_EPOCH"); + + if (source_date_epoch != NULL && *source_date_epoch != '\0') + t = (time_t) strtoll(source_date_epoch, NULL, 10); + else + t = time(NULL); + + tm = gmtime(&t); + strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", tm); + OUTPUT_OR_RET_FALSE(client, sbom_out, "Created: %s\n", buf); + } OUTPUT_OR_RET_FALSE(client, sbom_out, "\n\n"); @@ -338,8 +353,7 @@ static int about(void) { printf("bomtool (%s %s)\n", PACKAGE_NAME, PACKAGE_VERSION); - printf("Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021\n"); - printf(" pkgconf authors (see AUTHORS in documentation directory).\n\n"); + printf("Copyright (c) 2011-2026 pkgconf authors (see AUTHORS in documentation directory)\n\n"); printf("Permission to use, copy, modify, and/or distribute this software for any\n"); printf("purpose with or without fee is hereby granted, provided that the above\n"); printf("copyright notice and this permission notice appear in all copies.\n\n"); @@ -362,6 +376,7 @@ usage(void) printf(" --version print bomtool version to stdout\n"); printf(" --output FILE output SBOM text to FILE\n"); printf(" --define-variable=varname=value define variable 'varname' as 'value'\n"); + printf(" --creation-time Use string as creation time (Should be in ISO8601 format) [default: current time]\n"); return EXIT_SUCCESS; } @@ -388,6 +403,7 @@ main(int argc, char *argv[]) { "help", no_argument, &want_flags, PKG_HELP, }, { "output", required_argument, NULL, PKG_OUTPUT, }, { "define-variable", required_argument, NULL, PKG_DEFINE_VARIABLE, }, + { "creation-time", required_argument, NULL, PKG_CREATION_TIME, }, { NULL, 0, NULL, 0 } }; @@ -407,6 +423,9 @@ main(int argc, char *argv[]) case PKG_DEFINE_VARIABLE: pkgconf_tuple_define_global(&pkg_client, pkg_optarg); break; + case PKG_CREATION_TIME: + creation_time = pkg_optarg; + break; case '?': case ':': return EXIT_FAILURE; diff --git a/cli/main.c b/cli/main.c index 7959737b9913..060e54983333 100644 --- a/cli/main.c +++ b/cli/main.c @@ -54,19 +54,6 @@ unveil_handler(const pkgconf_client_t *client, const char *path, const char *per } } -static void -relocate_path(const char *path) -{ - pkgconf_buffer_t pathbuf = PKGCONF_BUFFER_INITIALIZER; - - pkgconf_buffer_append(&pathbuf, path); - pkgconf_path_relocate(&pathbuf); - - printf("%s\n", pkgconf_buffer_str(&pathbuf)); - - pkgconf_buffer_finalize(&pathbuf); -} - #ifndef PKGCONF_LITE static pkgconf_cross_personality_t * deduce_personality(char *argv[]) @@ -121,8 +108,7 @@ static void about(void) { printf("%s %s\n", PACKAGE_NAME, PACKAGE_VERSION); - printf("Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021\n"); - printf(" pkgconf authors (see AUTHORS in documentation directory).\n\n"); + printf("Copyright (c) 2011-2026 pkgconf authors (see AUTHORS in documentation directory)\n\n"); printf("Permission to use, copy, modify, and/or distribute this software for any\n"); printf("purpose with or without fee is hereby granted, provided that the above\n"); printf("copyright notice and this permission notice appear in all copies.\n\n"); @@ -163,7 +149,6 @@ usage(void) printf(" --dont-define-prefix do not override the prefix variable under any circumstances\n"); printf(" --prefix-variable=varname sets the name of the variable that pkgconf considers\n"); printf(" to be the package prefix\n"); - printf(" --relocate=path relocates a path and exits (mostly for testsuite)\n"); printf(" --dont-relocate-paths disables path relocation support\n"); #ifndef PKGCONF_LITE @@ -332,7 +317,6 @@ main(int argc, char *argv[]) { "with-path", required_argument, NULL, 42 }, { "prefix-variable", required_argument, NULL, 43 }, { "define-prefix", no_argument, &state.want_flags, PKG_DEFINE_PREFIX }, - { "relocate", required_argument, NULL, 45 }, { "dont-define-prefix", no_argument, &state.want_flags, PKG_DONT_DEFINE_PREFIX }, { "dont-relocate-paths", no_argument, &state.want_flags, PKG_DONT_RELOCATE_PATHS }, { "env", required_argument, NULL, 48 }, @@ -401,9 +385,6 @@ main(int argc, char *argv[]) case 43: pkgconf_client_set_prefix_varname(&state.pkg_client, pkg_optarg); break; - case 45: - relocate_path(pkg_optarg); - return EXIT_SUCCESS; case 48: state.want_env_prefix = pkg_optarg; break; diff --git a/cli/spdxtool/util.c b/cli/spdxtool/util.c index e47bf0a1e61f..fa717aaa6102 100644 --- a/cli/spdxtool/util.c +++ b/cli/spdxtool/util.c @@ -163,24 +163,6 @@ spdxtool_util_set_spdx_license(pkgconf_client_t *client, const char *spdx_licens /* * !doc * - * .. c:function:: const char *spdxtool_util_get_spdx_license(pkgconf_client_t *client) - * - * Get license which SBOM is release in - * - * :param pkgconf_client_t* client: The pkgconf client being accessed. - * :return: SPDX license - */ -const char * -spdxtool_util_get_spdx_license(pkgconf_client_t *client) -{ - return pkgconf_tuple_find_global(client, "spdx_license"); -} - -static size_t last_id = 0; - -/* - * !doc - * * .. c:function:: char *spdxtool_util_get_spdx_id_int(pkgconf_client_t *client, char *part) * * Get spdxId with current URI. @@ -193,6 +175,7 @@ static size_t last_id = 0; char * spdxtool_util_get_spdx_id_int(pkgconf_client_t *client, const char *part) { + static size_t last_id = 0; const char *global_xsd_any_uri = spdxtool_util_get_uri_root(client); char sep = spdxtool_util_get_uri_separator(client); pkgconf_buffer_t current_uri = PKGCONF_BUFFER_INITIALIZER; @@ -260,7 +243,7 @@ spdxtool_util_get_iso8601_time(time_t *wanted_time) * * .. c:function:: char *spdxtool_util_get_current_iso8601_time(void) * - * Get ISO8601 current timestamp + * Get ISO8601 current timestamp, honouring SOURCE_DATE_EPOCH when set * * :return: Time string in ISO8601 format */ @@ -268,7 +251,13 @@ char * spdxtool_util_get_current_iso8601_time(void) { time_t now; - time(&now); + const char *source_date_epoch = getenv("SOURCE_DATE_EPOCH"); + + if (source_date_epoch != NULL && *source_date_epoch != '\0') + now = (time_t) strtoll(source_date_epoch, NULL, 10); + else + time(&now); + return spdxtool_util_get_iso8601_time(&now); } diff --git a/cli/spdxtool/util.h b/cli/spdxtool/util.h index be86d6e154d7..e39c173e64c5 100644 --- a/cli/spdxtool/util.h +++ b/cli/spdxtool/util.h @@ -102,9 +102,6 @@ spdxtool_util_get_spdx_version(pkgconf_client_t *client); void spdxtool_util_set_spdx_license(pkgconf_client_t *client, const char *spdx_license); -const char * -spdxtool_util_get_spdx_license(pkgconf_client_t *client); - char * spdxtool_util_get_spdx_id_int(pkgconf_client_t *client, const char *part); |
