Skip to content
Open
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ include(tools/external.cmake)
add_subdirectory(src)

if (NOT "${TOIT_SYSTEM_NAME}" MATCHES "esp32")
# Mention the default packages so they are downloaded.
toit_project(default_packages "${CMAKE_CURRENT_LIST_DIR}/packages-default")

add_subdirectory(tools)
add_subdirectory(system/extensions/host)

Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,12 @@ install-sdk:
install -m 755 "$$f" "$(DESTDIR)$(prefix)"/vessels; \
done
mkdir -p "$(DESTDIR)$(prefix)"/lib
cp -R "$(CURDIR)"/lib/* "$(DESTDIR)$(prefix)"/lib
cp -R "$(CURDIR)"/lib/. "$(DESTDIR)$(prefix)"/lib
find "$(DESTDIR)$(prefix)"/lib -type f -exec chmod 644 {} \;
mkdir -p "$(DESTDIR)$(prefix)"/packages-default
cp -R "$(CURDIR)"/packages-default/. "$(DESTDIR)$(prefix)"/packages-default
find "$(DESTDIR)$(prefix)"/packages-default -type f -exec chmod 644 {} \;
find "$(DESTDIR)$(prefix)"/packages-default -type d -name '.git' -prune -exec rm -rf {} \;

install: install-sdk

Expand Down
5 changes: 5 additions & 0 deletions packages-default/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Default packages

This directory contains the default packages that are distributed with
the current SDK. Applications that don't have any 'package.yaml' or
'package.lock' file will use these packages.
15 changes: 15 additions & 0 deletions packages-default/package.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
sdk: ^2.0.0-alpha.145
prefixes:
host: pkg-host
http: pkg-http
packages:
pkg-host:
url: github.com/toitlang/pkg-host
name: host
version: 1.15.1
hash: ff187c2c19d695e66c3dc1d9c09b4dc6bec09088
pkg-http:
url: github.com/toitlang/pkg-http
name: http
version: 2.7.2
hash: 614dd0f374e70aab09f12e9466a35b779b9a8d63
7 changes: 7 additions & 0 deletions packages-default/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencies:
host:
url: github.com/toitlang/pkg-host
version: ^1.15.1
http:
url: github.com/toitlang/pkg-http
version: ^2.7.2
15 changes: 15 additions & 0 deletions src/compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,18 @@ add_custom_target(
)

add_dependencies(toit.compile generate-lib-symlink)

set(TOIT_DEFAULT_PROJECT_DIR "${CMAKE_BINARY_DIR}/sdk/packages-default")

add_custom_command(
OUTPUT ${TOIT_DEFAULT_PROJECT_DIR}
COMMAND ${CMAKE_COMMAND} -E create_symlink ${TOIT_SDK_SOURCE_DIR}/packages-default ${TOIT_DEFAULT_PROJECT_DIR}
VERBATIM
)

add_custom_target(
generate-default-project-symlink
DEPENDS ${TOIT_DEFAULT_PROJECT_DIR}
)

add_dependencies(toit.compile generate-default-project-symlink)
4 changes: 4 additions & 0 deletions src/compiler/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,10 @@ PackageLock Pipeline::load_package_lock(const List<const char*> source_paths) {
} else {
lock_file = find_lock_file(entry_path, filesystem());
}
if (lock_file.empty()) {
// Use the default lock-file instead.
lock_file = find_lock_file_at(filesystem()->default_project_root(), filesystem());
}
return PackageLock::read(lock_file,
entry_path,
source_manager(),
Expand Down
24 changes: 23 additions & 1 deletion src/compiler/filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const char* Filesystem::library_root() {
library_root_ = builder.strdup();
} else {
builder.reset_to(sdk_length);
builder.join("..", "lib");
builder.join("..", LIB_SUFFIX);
builder.canonicalize();
// Always assign the string, without testing.
// If the path is wrong there will be an error very soon, because the compiler can't
Expand All @@ -65,6 +65,28 @@ const char* Filesystem::library_root() {
return library_root_;
}

const char* Filesystem::default_project_root() {
if (default_project_root_ == null) {
auto sdk = sdk_path();
const char* DEFAULT_PROJECT_SUFFIX = "packages-default";
PathBuilder builder(this);
builder.join(sdk);
int sdk_length = builder.length();
builder.join(DEFAULT_PROJECT_SUFFIX);
if (is_directory(builder.c_str())) {
default_project_root_ = builder.strdup();
} else {
builder.reset_to(sdk_length);
builder.join("..", DEFAULT_PROJECT_SUFFIX);
builder.canonicalize();
// Always assign the string, without testing.
// If the installation isn't correct, then we just won't find any default packages.
default_project_root_ = builder.strdup();
}
}
return default_project_root_;
}

const char* Filesystem::vessel_root() {
if (vessel_root_ == null) {
auto sdk = sdk_path();
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Filesystem {

const char* library_root();
const char* vessel_root();
const char* default_project_root();

/// Registers an intercepted file.
/// The path must be absolute.
Expand Down Expand Up @@ -124,6 +125,7 @@ class Filesystem {

UnorderedMap<std::string, InterceptedFile> intercepted_;
const char* library_root_ = null;
const char* default_project_root_ = null;
const char* vessel_root_ = null;
const char* cwd_ = null;
};
Expand Down