-
Notifications
You must be signed in to change notification settings - Fork 731
system/nxpkg: add a basic package lifecycle helper #3474
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
Draft
aviralgarg05
wants to merge
6
commits into
apache:master
Choose a base branch
from
aviralgarg05:gsoc/nxpkg-app-pr1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
075c826
system/pkg: add lifecycle helper skeleton
aviralgarg05 e260c75
system/pkg: add metadata and store foundation
aviralgarg05 fa22ef6
system/pkg: add local install and list path
aviralgarg05 e0d6b58
system/nxpkg: rename package helper and keep runtime fixes
aviralgarg05 7ccf43e
system/nxpkg: drop temporary debug logs and simplify usage
aviralgarg05 901096e
system/nxpkg: use /etc and /var package layout
aviralgarg05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # ############################################################################## | ||
| # apps/system/nxpkg/CMakeLists.txt | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more contributor | ||
| # license agreements. See the NOTICE file distributed with this work for | ||
| # additional information regarding copyright ownership. The ASF licenses this | ||
| # file to you 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. | ||
| # | ||
| # ############################################################################## | ||
|
|
||
| if(CONFIG_SYSTEM_NXPKG) | ||
| nuttx_add_application( | ||
| MODULE | ||
| ${CONFIG_SYSTEM_NXPKG} | ||
| NAME | ||
| ${CONFIG_SYSTEM_NXPKG_PROGNAME} | ||
| STACKSIZE | ||
| ${CONFIG_SYSTEM_NXPKG_STACKSIZE} | ||
| PRIORITY | ||
| ${CONFIG_SYSTEM_NXPKG_PRIORITY} | ||
| SRCS | ||
| pkg_main.c | ||
| pkg_compat.c | ||
| pkg_hash.c | ||
| pkg_install.c | ||
| pkg_log.c | ||
| pkg_manifest.c | ||
| pkg_metadata.c | ||
| pkg_store.c | ||
| pkg_txn.c) | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # | ||
| # For a description of the syntax of this configuration file, | ||
| # see the file kconfig-language.txt in the NuttX tools repository. | ||
| # | ||
|
|
||
| config SYSTEM_NXPKG | ||
| tristate "'nxpkg' lifecycle helper" | ||
| default n | ||
| select NETUTILS_CJSON | ||
| ---help--- | ||
| Enable the thin package lifecycle helper proposed for the | ||
| Dynamic ELF distribution work. | ||
|
|
||
| if SYSTEM_NXPKG | ||
|
|
||
| config SYSTEM_NXPKG_PROGNAME | ||
| string "Program name" | ||
| default "nxpkg" | ||
| ---help--- | ||
| This is the name of the program that will be used when the | ||
| nxpkg tool is installed. | ||
|
|
||
| config SYSTEM_NXPKG_PRIORITY | ||
| int "'nxpkg' task priority" | ||
| default 100 | ||
|
|
||
| config SYSTEM_NXPKG_STACKSIZE | ||
| int "'nxpkg' stack size" | ||
| default 16384 | ||
|
|
||
| endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| ############################################################################ | ||
| # apps/system/nxpkg/Make.defs | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. The | ||
| # ASF licenses this file to you 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. | ||
| # | ||
| ############################################################################ | ||
|
|
||
| ifneq ($(CONFIG_SYSTEM_NXPKG),) | ||
| CONFIGURED_APPS += $(APPDIR)/system/nxpkg | ||
| endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| ############################################################################ | ||
| # apps/system/nxpkg/Makefile | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. The | ||
| # ASF licenses this file to you 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. | ||
| # | ||
| ############################################################################ | ||
|
|
||
| include $(APPDIR)/Make.defs | ||
|
|
||
| PROGNAME = $(CONFIG_SYSTEM_NXPKG_PROGNAME) | ||
| PRIORITY = $(CONFIG_SYSTEM_NXPKG_PRIORITY) | ||
| STACKSIZE = $(CONFIG_SYSTEM_NXPKG_STACKSIZE) | ||
| MODULE = $(CONFIG_SYSTEM_NXPKG) | ||
|
|
||
| CSRCS = pkg_compat.c pkg_hash.c pkg_install.c pkg_log.c pkg_manifest.c | ||
| CSRCS += pkg_metadata.c pkg_store.c pkg_txn.c | ||
| MAINSRC = pkg_main.c | ||
|
|
||
| include $(APPDIR)/Application.mk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| /**************************************************************************** | ||
| * apps/system/nxpkg/pkg.h | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. The | ||
| * ASF licenses this file to you 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. | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| #ifndef __APPS_SYSTEM_NXPKG_PKG_H | ||
| #define __APPS_SYSTEM_NXPKG_PKG_H | ||
|
|
||
| /**************************************************************************** | ||
| * Included Files | ||
| ****************************************************************************/ | ||
|
|
||
| #include <limits.h> | ||
| #include <stdbool.h> | ||
| #include <stddef.h> | ||
| #include <stdio.h> | ||
|
|
||
| /**************************************************************************** | ||
| * Pre-processor Definitions | ||
| ****************************************************************************/ | ||
|
|
||
| #define PKG_REPO_DIR "/etc/nxpkg" | ||
| #define PKG_REPO_INDEX "/etc/nxpkg/index.json" | ||
| #define PKG_REPO_INSTALLED "/var/lib/nxpkg/installed.json" | ||
| #define PKG_STORE_DIR "/var/lib/nxpkg/pkgs" | ||
| #define PKG_TMP_DIR "/var/cache/nxpkg" | ||
| #define PKG_TMP_PKG_DIR "/var/cache/nxpkg/pkg" | ||
|
|
||
| #define PKG_NAME_MAX 63 | ||
| #define PKG_VERSION_MAX 31 | ||
| #define PKG_ARCH_MAX 31 | ||
| #define PKG_COMPAT_MAX 63 | ||
| #define PKG_HASH_HEX_LEN 64 | ||
| #define PKG_INDEX_MAX 32 | ||
| #define PKG_INSTALLED_MAX 16 | ||
| #define PKG_INSTALLED_VERSIONS_MAX 8 | ||
|
|
||
| /**************************************************************************** | ||
| * Public Types | ||
| ****************************************************************************/ | ||
|
|
||
| enum pkg_payload_type_e | ||
| { | ||
| PKG_PAYLOAD_ELF = 0, | ||
| PKG_PAYLOAD_SHARED_LIB | ||
| }; | ||
|
|
||
| enum pkg_txn_state_e | ||
| { | ||
| PKG_TXN_IDLE = 0, | ||
| PKG_TXN_FETCHING, | ||
| PKG_TXN_VERIFIED, | ||
| PKG_TXN_STAGED, | ||
| PKG_TXN_COMPAT_OK, | ||
| PKG_TXN_ACTIVATED, | ||
| PKG_TXN_CLEANUP, | ||
| PKG_TXN_FAILED, | ||
| PKG_TXN_RESTORE | ||
| }; | ||
|
|
||
| struct pkg_manifest_s | ||
| { | ||
| char name[PKG_NAME_MAX + 1]; | ||
| char version[PKG_VERSION_MAX + 1]; | ||
| char arch[PKG_ARCH_MAX + 1]; | ||
| char compat[PKG_COMPAT_MAX + 1]; | ||
| char artifact[PATH_MAX]; | ||
| char sha256[PKG_HASH_HEX_LEN + 1]; | ||
| enum pkg_payload_type_e type; | ||
| }; | ||
|
|
||
| struct pkg_index_s | ||
| { | ||
| struct pkg_manifest_s manifests[PKG_INDEX_MAX]; | ||
| size_t count; | ||
| }; | ||
|
|
||
| struct pkg_installed_entry_s | ||
| { | ||
| char name[PKG_NAME_MAX + 1]; | ||
| char current[PKG_VERSION_MAX + 1]; | ||
| char previous[PKG_VERSION_MAX + 1]; | ||
| char arch[PKG_ARCH_MAX + 1]; | ||
| char compat[PKG_COMPAT_MAX + 1]; | ||
| char versions[PKG_INSTALLED_VERSIONS_MAX][PKG_VERSION_MAX + 1]; | ||
| enum pkg_payload_type_e type; | ||
| size_t version_count; | ||
| }; | ||
|
|
||
| struct pkg_installed_db_s | ||
| { | ||
| struct pkg_installed_entry_s entries[PKG_INSTALLED_MAX]; | ||
| size_t count; | ||
| }; | ||
|
|
||
| /**************************************************************************** | ||
| * Public Function Prototypes | ||
| ****************************************************************************/ | ||
|
|
||
| const char *pkg_manifest_type_str(enum pkg_payload_type_e type); | ||
| int pkg_manifest_validate(FAR const struct pkg_manifest_s *manifest); | ||
| int pkg_manifest_parse_type(FAR const char *value, | ||
| FAR enum pkg_payload_type_e *type); | ||
|
|
||
| int pkg_store_prepare_layout(void); | ||
| int pkg_store_ensure_package_root(FAR const char *name); | ||
| int pkg_store_ensure_version_dir(FAR const char *name, | ||
| FAR const char *version); | ||
| int pkg_store_format_index_path(FAR char *buffer, size_t size); | ||
| int pkg_store_format_installed_path(FAR char *buffer, size_t size); | ||
| int pkg_store_format_package_root(FAR char *buffer, size_t size, | ||
| FAR const char *name); | ||
| int pkg_store_format_version_path(FAR char *buffer, size_t size, | ||
| FAR const char *name, | ||
| FAR const char *version); | ||
| int pkg_store_format_current_path(FAR char *buffer, size_t size, | ||
| FAR const char *name); | ||
| int pkg_store_format_previous_path(FAR char *buffer, size_t size, | ||
| FAR const char *name); | ||
| int pkg_store_format_txn_path(FAR char *buffer, size_t size, | ||
| FAR const char *name); | ||
| int pkg_store_format_lock_path(FAR char *buffer, size_t size, | ||
| FAR const char *name); | ||
| int pkg_store_format_download_path(FAR char *buffer, size_t size, | ||
| FAR const char *name, | ||
| FAR const char *version); | ||
| int pkg_store_format_payload_path(FAR char *buffer, size_t size, | ||
| FAR const char *name, | ||
| FAR const char *version, | ||
| FAR const char *artifact); | ||
| int pkg_store_format_manifest_path(FAR char *buffer, size_t size, | ||
| FAR const char *name, | ||
| FAR const char *version); | ||
| int pkg_store_read_text(FAR const char *path, FAR char **buffer); | ||
| int pkg_store_write_text_atomic(FAR const char *path, FAR const char *text); | ||
| int pkg_store_copy_file(FAR const char *src, FAR const char *dest); | ||
| int pkg_store_remove_file(FAR const char *path); | ||
|
|
||
| const char *pkg_runtime_arch(void); | ||
| const char *pkg_runtime_compat(void); | ||
| int pkg_compat_check(FAR const struct pkg_manifest_s *manifest); | ||
|
|
||
| int pkg_hash_file_sha256(FAR const char *path, | ||
| FAR char digest[PKG_HASH_HEX_LEN + 1]); | ||
|
|
||
| int pkg_metadata_load_index(FAR struct pkg_index_s *index); | ||
| FAR const struct pkg_manifest_s * | ||
| pkg_metadata_find_latest(FAR const struct pkg_index_s *index, | ||
| FAR const char *name); | ||
| int pkg_metadata_load_installed(FAR struct pkg_installed_db_s *db); | ||
| int pkg_metadata_save_installed(FAR const struct pkg_installed_db_s *db); | ||
| FAR struct pkg_installed_entry_s * | ||
| pkg_metadata_find_installed(FAR struct pkg_installed_db_s *db, | ||
| FAR const char *name); | ||
| int pkg_metadata_write_manifest(FAR const char *path, | ||
| FAR const struct pkg_manifest_s *manifest); | ||
| int pkg_metadata_print_installed(FAR FILE *stream, | ||
| FAR const struct pkg_installed_db_s *db); | ||
|
|
||
| const char *pkg_txn_state_str(enum pkg_txn_state_e state); | ||
| int pkg_txn_write_state(FAR const char *name, enum pkg_txn_state_e state); | ||
| int pkg_txn_clear_state(FAR const char *name); | ||
|
|
||
| int pkg_install(FAR const char *name); | ||
| int pkg_list(FAR FILE *stream); | ||
|
|
||
| void pkg_error(FAR const char *fmt, ...); | ||
| void pkg_info(FAR const char *fmt, ...); | ||
|
|
||
| #endif /* __APPS_SYSTEM_NXPKG_PKG_H */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /**************************************************************************** | ||
| * apps/system/nxpkg/pkg_compat.c | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. The | ||
| * ASF licenses this file to you 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. | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| /**************************************************************************** | ||
| * Included Files | ||
| ****************************************************************************/ | ||
|
|
||
| #include <errno.h> | ||
| #include <string.h> | ||
|
|
||
| #include "pkg.h" | ||
|
|
||
| /**************************************************************************** | ||
| * Public Functions | ||
| ****************************************************************************/ | ||
|
|
||
| const char *pkg_runtime_arch(void) | ||
| { | ||
| return CONFIG_ARCH; | ||
| } | ||
|
|
||
| const char *pkg_runtime_compat(void) | ||
| { | ||
| return CONFIG_ARCH_BOARD; | ||
| } | ||
|
|
||
| int pkg_compat_check(FAR const struct pkg_manifest_s *manifest) | ||
| { | ||
| if (manifest == NULL) | ||
| { | ||
| return -EINVAL; | ||
| } | ||
|
|
||
| if (strcmp(manifest->arch, pkg_runtime_arch()) != 0) | ||
| { | ||
| return -ENOEXEC; | ||
| } | ||
|
|
||
| if (strcmp(manifest->compat, pkg_runtime_compat()) != 0) | ||
| { | ||
| return -EXDEV; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.