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

Lcmgen emit version #496

Merged
merged 3 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions lcm/lcm_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@
#define LCM_MAJOR_VERSION LCM_VERSION_MAJOR
#define LCM_MINOR_VERSION LCM_VERSION_MINOR
#define LCM_MICRO_VERSION LCM_VERSION_PATCH

// Macro required indirection.
#define _MACRO_LCM_STRINGIFY(x) #x
/// Surround x in quotes. x may be the result of another macro.
#define MACRO_LCM_STRINGIFY(x) _MACRO_LCM_STRINGIFY(x)

/// "x.y.z"
#define LCM_VERSION_STRING \
MACRO_LCM_STRINGIFY(LCM_VERSION_MAJOR) \
"." MACRO_LCM_STRINGIFY(LCM_VERSION_MINOR) "." MACRO_LCM_STRINGIFY(LCM_VERSION_PATCH)
3 changes: 2 additions & 1 deletion lcmgen/emit_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#endif
#include <inttypes.h>

#include "../lcm/lcm_version.h"
#include "lcmgen.h"

#define INDENT(n) (4 * (n))
Expand Down Expand Up @@ -78,7 +79,7 @@ static void emit_auto_generated_warning(FILE *f)
"// THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY\n"
"// BY HAND!!\n"
"//\n"
"// Generated by lcm-gen\n\n");
"// Generated by lcm-gen " LCM_VERSION_STRING "\n\n");
}

// Some types do not have a 1:1 mapping from lcm types to native C
Expand Down
4 changes: 3 additions & 1 deletion lcmgen/emit_cpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <sys/stat.h>
#include <sys/types.h>

#include "../lcm/lcm_version.h"
#include "lcmgen.h"

#define INDENT(n) (4 * (n))
Expand Down Expand Up @@ -149,7 +150,8 @@ static void emit_auto_generated_warning(FILE *f)
"/** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY\n"
" * BY HAND!!\n"
" *\n"
" * Generated by lcm-gen\n"
" * Generated by lcm-gen " LCM_VERSION_STRING
"\n"
" **/\n\n");
}

Expand Down
4 changes: 3 additions & 1 deletion lcmgen/emit_csharp.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <sys/stat.h>
#include <sys/types.h>

#include "../lcm/lcm_version.h"
#include "getopt.h"
#include "lcmgen.h"

Expand Down Expand Up @@ -346,7 +347,8 @@ int emit_csharp(lcmgen_t *lcm)

emit(0,
"/* LCM type definition class file\n"
" * This file was automatically generated by lcm-gen\n"
" * This file was automatically generated by lcm-gen " LCM_VERSION_STRING
"\n"
" * DO NOT MODIFY BY HAND!!!!\n"
" */\n");

Expand Down
3 changes: 2 additions & 1 deletion lcmgen/emit_go.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define __STDC_FORMAT_MACROS // Enable integer types
#endif

#include "../lcm/lcm_version.h"
#include "lcmgen.h"

#define TABS "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"
Expand Down Expand Up @@ -382,7 +383,7 @@ static void emit_auto_generated_warning(FILE *f)
"// THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY\n"
"// BY HAND!!\n"
"//\n"
"// Generated by lcm-gen\n\n");
"// Generated by lcm-gen " LCM_VERSION_STRING "\n\n");
}

/*
Expand Down
3 changes: 3 additions & 0 deletions lcmgen/emit_java.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <sys/stat.h>
#include <sys/types.h>

#include "../lcm/lcm_version.h"
#include "getopt.h"
#include "lcmgen.h"

Expand Down Expand Up @@ -499,6 +500,8 @@ int emit_java(lcmgen_t *lcm)
"/* LCM type definition class file\n"
" * This file was automatically generated by lcm-gen\n"
" * DO NOT MODIFY BY HAND!!!!\n"
" * lcm-gen " LCM_VERSION_STRING
"\n"
" */\n");

if (strlen(lr->structname->package) > 0)
Expand Down
6 changes: 5 additions & 1 deletion lcmgen/emit_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sys/types.h>
#include <unistd.h>

#include "../lcm/lcm_version.h"
#include "lcmgen.h"

// lua uses just 2 spaces per indent
Expand Down Expand Up @@ -922,6 +923,8 @@ static int emit_package(lcmgen_t *lcm, _package_contents_t *pc)
"LCM package init.lua file\n"
"This file automatically generated by lcm-gen.\n"
"DO NOT MODIFY BY HAND!!!!\n"
"lcm-gen " LCM_VERSION_STRING
"\n"
"--]]\n"
"\n"
"local M = {}\n"
Expand Down Expand Up @@ -1059,7 +1062,8 @@ static int emit_package(lcmgen_t *lcm, _package_contents_t *pc)
fprintf(f,
"--[[\n"
"LCM type definitions\n"
"This file automatically generated by lcm.\n"
"This file automatically generated by lcm " LCM_VERSION_STRING
".\n"
"DO NOT MODIFY BY HAND!!!!\n"
"--]]\n"
"\n"
Expand Down
21 changes: 15 additions & 6 deletions lcmgen/emit_python.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sys/types.h>
#include <unistd.h>

#include "../lcm/lcm_version.h"
#include "lcmgen.h"

#define INDENT(n) (4 * (n))
Expand Down Expand Up @@ -647,27 +648,33 @@ static void emit_python_fingerprint(const lcmgen_t *lcm, FILE *f, lcm_struct_t *
static void
emit_python_dependencies (const lcmgen_t *lcm, FILE *f, lcm_struct_t *structure, int write_init_py )
{
// Find the set of types to import
GHashTable *dependencies = g_hash_table_new (g_str_hash, g_str_equal);
for (unsigned int m=0; m < structure->members->len; m++) {
lcm_member_t *member = (lcm_member_t *) g_ptr_array_index (structure->members, m);
if (write_init_py) {
if (lcm_is_primitive_type(member->type->lctypename)){
continue;
}
int no_package = g_str_equal(member->type->package, "");
if (write_init_py && !no_package) {
// pyright (The vscode python static analyzer) refuses to understand
// `import foo.bar` in cases where `import foo` works.
// https://github.com/microsoft/pyright/issues/6674
if (! lcm_is_primitive_type (member->type->lctypename) &&
! g_hash_table_lookup (dependencies, member->type->package)) {
// Therefore, when __init__.py is generated, import only the package name.
if (! g_hash_table_lookup (dependencies, member->type->package)) {
g_hash_table_insert (dependencies, member->type->package,
member->type->package);
}
} else {
if (! lcm_is_primitive_type (member->type->lctypename) &&
! g_hash_table_lookup (dependencies, member->type->lctypename)) {
} else {
// Otherwise import each full type.
if (! g_hash_table_lookup (dependencies, member->type->lctypename)) {
g_hash_table_insert (dependencies, member->type->lctypename,
member->type->lctypename);
}
}
}

// Emit the set of imports.
GPtrArray *deps = _hash_table_get_vals (dependencies);
for (int i=0; i < deps->len; i++) {
const char *package = (char *) g_ptr_array_index (deps, i);
Expand Down Expand Up @@ -802,6 +809,7 @@ emit_package (lcmgen_t *lcm, _package_contents_t *package)
fprintf (init_py_fp, "\"\"\"LCM package __init__.py file\n"
"This file automatically generated by lcm-gen.\n"
"DO NOT MODIFY BY HAND!!!!\n"
"lcm-gen " LCM_VERSION_STRING "\n"
"\"\"\"\n\n");
} else {
while(!feof(init_py_fp)) {
Expand Down Expand Up @@ -856,6 +864,7 @@ emit_package (lcmgen_t *lcm, _package_contents_t *package)
fprintf(f, "\"\"\"LCM type definitions\n"
"This file automatically generated by lcm.\n"
"DO NOT MODIFY BY HAND!!!!\n"
"lcm-gen " LCM_VERSION_STRING "\n"
"\"\"\"\n"
"\n"
"from io import BytesIO\n"
Expand Down
Loading