-
Notifications
You must be signed in to change notification settings - Fork 93
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
Add os_type and os_version keys to erlang:system_info/1 #1117
base: release-0.6
Are you sure you want to change the base?
Changes from all commits
381c85b
f60343a
be3a105
2b0c468
11ea578
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,12 +45,15 @@ | |
#include "sys_mbedtls.h" | ||
#endif | ||
|
||
#include <ctype.h> | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <limits.h> | ||
#include <signal.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <sys/time.h> | ||
#include <sys/utsname.h> | ||
#include <time.h> | ||
#include <unistd.h> | ||
|
||
|
@@ -550,8 +553,67 @@ Context *sys_create_port(GlobalContext *glb, const char *driver_name, term opts) | |
|
||
term sys_get_info(Context *ctx, term key) | ||
{ | ||
UNUSED(ctx); | ||
UNUSED(key); | ||
if (key == globalcontext_make_atom(ctx->global, ATOM_STR("\x7", "os_type"))) { | ||
struct utsname buf; | ||
errno = 0; | ||
if (uname(&buf) != 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return ERROR_ATOM; | ||
} | ||
|
||
const char *sys_name; | ||
|
||
if (strcmp(buf.sysname, "Linux") == 0) { | ||
sys_name = ATOM_STR("\x5", "linux"); | ||
} else if (strcmp(buf.sysname, "Darwin") == 0) { | ||
sys_name = ATOM_STR("\x6", "darwin"); | ||
} else if (strcmp(buf.sysname, "FreeBSD") == 0) { | ||
sys_name = ATOM_STR("\x7", "freebsd"); | ||
} else if (strcmp(buf.sysname, "NetBSB") == 0) { | ||
sys_name = ATOM_STR("\x7", "netbsd"); | ||
} else if (strcmp(buf.sysname, "OpenBSB") == 0) { | ||
sys_name = ATOM_STR("\x7", "openbsd"); | ||
} else if (strcmp(buf.sysname, "Firefly") == 0) { | ||
sys_name = ATOM_STR("\x7", "firefly"); | ||
} else { | ||
sys_name = ATOM_STR("\x7", "unknown"); | ||
} | ||
|
||
if (memory_ensure_free(ctx, TUPLE_SIZE(2)) != MEMORY_GC_OK) { | ||
return OUT_OF_MEMORY_ATOM; | ||
} | ||
term os = term_alloc_tuple(2, &ctx->heap); | ||
term_put_tuple_element(os, 0, globalcontext_make_atom(ctx->global, ATOM_STR("\x4", "unix"))); | ||
term_put_tuple_element(os, 1, globalcontext_make_atom(ctx->global, sys_name)); | ||
return os; | ||
} | ||
if (key == globalcontext_make_atom(ctx->global, ATOM_STR("\xA", "os_version"))) { | ||
struct utsname buf; | ||
char *p; | ||
int ver[3] = { 0 }; | ||
int i = 0; | ||
|
||
errno = 0; | ||
if (uname(&buf) != 0) { | ||
return ERROR_ATOM; | ||
} | ||
p = buf.release; | ||
while ((*p) && i < 3) { | ||
if (isdigit(*p)) { | ||
ver[i] = strtol(p, &p, 10); | ||
i++; | ||
} else { | ||
p++; | ||
} | ||
} | ||
if (memory_ensure_free(ctx, TUPLE_SIZE(3)) != MEMORY_GC_OK) { | ||
return OUT_OF_MEMORY_ATOM; | ||
} | ||
term os_ver = term_alloc_tuple(3, &ctx->heap); | ||
term_put_tuple_element(os_ver, 0, term_from_int(ver[0])); | ||
term_put_tuple_element(os_ver, 1, term_from_int(ver[1])); | ||
term_put_tuple_element(os_ver, 2, term_from_int(ver[2])); | ||
return os_ver; | ||
} | ||
return UNDEFINED_ATOM; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
|
||
cmake_minimum_required (VERSION 3.13) | ||
|
||
include(${PICO_SDK_PATH}/pico_sdk_version.cmake) | ||
|
||
set(HEADER_FILES | ||
gpiodriver.h | ||
platform_defaultatoms.h | ||
|
@@ -44,6 +46,10 @@ set( | |
${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR} | ||
) | ||
|
||
add_compile_definitions(OS_VERSION_MAJOR=${PICO_SDK_VERSION_MAJOR}) | ||
add_compile_definitions(OS_VERSION_MINOR=${PICO_SDK_VERSION_MINOR}) | ||
add_compile_definitions(OS_VERSION_PATCH=${PICO_SDK_VERSION_REVISION}) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's double-check. @pguyot are you aware of a cleaner approach? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find anything better, it looks like the usual approach. Also, we may want an additional avm_ or atomvm_* key for the chip versions. Pico SDK has functions to query chip and rom versions. This could be in another PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This would be good. Perhaps at the same time the ESP32 key There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But maybe that kind of breakage needs to be based on main (0.7.0)? Or add a deprecation warning and support both versions of the key on esp32 for a cycle... |
||
add_library(libAtomVM${PLATFORM_LIB_SUFFIX} STATIC ${SOURCE_FILES} ${HEADER_FILES}) | ||
target_compile_features(libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC c_std_11) | ||
if(CMAKE_COMPILER_IS_GNUCC) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# | ||
# This file is part of AtomVM. | ||
# | ||
# Copyright 2024 Winford (Uncle Grumpy) <[email protected]> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later | ||
# | ||
|
||
function( version_from_git ) | ||
|
||
# Find Git | ||
find_package(Git) | ||
if(!Git_FOUND) | ||
message( FATAL_ERROR "Git not found" ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would make unsupported source only releases (without a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not consider that specific possibility, but there is no way exposed from libopencm3 to determine the version used for the build. If a source code release of libopencm3 was used, then the version returned would be |
||
endif(!Git_FOUND) | ||
|
||
# Git tag | ||
execute_process( | ||
COMMAND "${GIT_EXECUTABLE}" describe --exact-match | ||
WORKING_DIRECTORY "${LIBOPENCM3_DIR}" | ||
RESULT_VARIABLE git_result | ||
OUTPUT_VARIABLE git_tag | ||
ERROR_VARIABLE git_error | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_STRIP_TRAILING_WHITESPACE | ||
) | ||
if( NOT git_result EQUAL 0 ) | ||
message( FATAL_ERROR "Failed to execute Git: ${git_error}" ) | ||
endif() | ||
|
||
if( git_tag MATCHES "^v([0-9]+)[.]([0-9]+)[.]([0-9]+).*$" ) | ||
set( ide_version_major "${CMAKE_MATCH_1}" ) | ||
set( ide_version_minor "${CMAKE_MATCH_2}" ) | ||
set( ide_version_patch "${CMAKE_MATCH_3}" ) | ||
else() | ||
set( ide_version_major "undefined" ) | ||
set( ide_version_minor "undefined" ) | ||
set( ide_version_patch "undefined" ) | ||
endif() | ||
|
||
# Set parent scope variables | ||
set( IDE_VERSION_MAJOR ${ide_version_major} PARENT_SCOPE) | ||
set( IDE_VERSION_MINOR ${ide_version_minor} PARENT_SCOPE) | ||
set( IDE_VERSION_PATCH ${ide_version_patch} PARENT_SCOPE) | ||
|
||
endfunction( version_from_git ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest using
interop_atom_term_select_int
for future-proofing, or anyway no need to make an atom for comparing it,globalcontext_is_term_equal_to_atom_string
can be used instead.