mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
tools: move idf_exe out of IDF
Source code moved into https://github.com/espressif/idf_py_exe_tool, so that releases can be built in CI and hosted on Github.
This commit is contained in:
parent
f23dcd3555
commit
07644ee5cd
@ -377,31 +377,6 @@ build_docker:
|
||||
# Therefore, build a copy of the example located inside the container.
|
||||
- docker run --rm --workdir /opt/esp/idf/examples/get-started/blink ${DOCKER_TMP_IMAGE_NAME} idf.py build
|
||||
|
||||
.test-on-windows:
|
||||
extends:
|
||||
- .before_script_minimal
|
||||
- .rules:build:windows
|
||||
stage: host_test
|
||||
needs: []
|
||||
image: $CI_DOCKER_REGISTRY/esp32-toolchain-win-cross
|
||||
tags:
|
||||
- build
|
||||
script:
|
||||
- cd $TEST_DIR
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-i686-w64-mingw32.cmake -DCMAKE_BUILD_TYPE=Release ..
|
||||
- cmake --build .
|
||||
|
||||
build_idf_exe:
|
||||
extends: .test-on-windows
|
||||
artifacts:
|
||||
paths:
|
||||
- tools/windows/idf_exe/build/idf-exe-v*.zip
|
||||
expire_in: 4 days
|
||||
variables:
|
||||
TEST_DIR: tools/windows/idf_exe
|
||||
|
||||
# This job builds template app with permutations of targets and optimization levels
|
||||
build_template_app:
|
||||
extends:
|
||||
|
@ -1,26 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(idfexe)
|
||||
|
||||
set(VERSION 1.0.2)
|
||||
set(ARCHIVE_NAME idf-exe-v${VERSION}.zip)
|
||||
|
||||
add_executable(idf idf_main.c)
|
||||
target_compile_definitions(idf PRIVATE -DVERSION=\"${VERSION}\")
|
||||
set_target_properties(idf PROPERTIES C_STANDARD 99)
|
||||
target_link_libraries(idf "shlwapi")
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL Release)
|
||||
add_custom_command(TARGET idf
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_STRIP} idf.exe)
|
||||
endif()
|
||||
|
||||
add_custom_target(dist ALL DEPENDS idf)
|
||||
|
||||
add_custom_command(
|
||||
TARGET dist
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${CMAKE_CURRENT_BINARY_DIR}/idf.exe" "${CMAKE_CURRENT_BINARY_DIR}/idf.py.exe"
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E tar cfv ${ARCHIVE_NAME} --format=zip
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/idf.py.exe"
|
||||
)
|
@ -1,34 +0,0 @@
|
||||
# IDF wrapper tool (idf.py.exe)
|
||||
|
||||
This tools helps invoke idf.py in Windows CMD shell.
|
||||
|
||||
In Windows CMD shell, python scripts can be executed directly (by typing their name) if `.py` extension is associated with Python. The issue with such association is that it is incompatible with virtual environments. That is, if `.py` extension is associated with a global (or user-specific) copy of `python.exe`, then the virtual environment will not be used when running the script. [Python Launcher](https://www.python.org/dev/peps/pep-0397/) solves this issue, but it is installed by default only with Python 3.6 and newer. In addition to that, the user may choose not to install Python Launcher (for example, to keep `.py` files associated with an editor).
|
||||
|
||||
Hence, `idf.py.exe` is introduced. It is a simple program which forwards the command line arguments to `idf.py`. That is,
|
||||
|
||||
```
|
||||
idf.py args...
|
||||
```
|
||||
has the same effect as:
|
||||
|
||||
```
|
||||
python.exe %IDF_PATH%\tools\idf.py args...
|
||||
```
|
||||
|
||||
`python.exe` location is determined using the default search rules, which include searching the directories in `%PATH%`. Standard I/O streams are forwarded between `idf.py.exe` and `python.exe` processes. The exit code of `idf.py.exe` is the same as the exit code of `python.exe` process.
|
||||
|
||||
For compatibility with `idf_tools.py`, a flag to obtain the version of `idf.py.exe` is provided: `idf.py.exe -v` or `idf.py.exe --version`. Note that this flag only works when `idf.py.exe` is started by the full name (with `.exe` extension). Running `idf.py -v` results in same behavior as `python idf.py -v`, that is `-v` argument is propagated to the Python script.
|
||||
|
||||
## Building
|
||||
|
||||
On Linux/Mac, install mingw-w64 toolchain (`i686-w64-mingw32-gcc`). Then build `idf.py.exe` using CMake:
|
||||
|
||||
```
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-i686-w64-mingw32.cmake -DCMAKE_BUILD_TYPE=Release ..
|
||||
cmake --build .
|
||||
```
|
||||
|
||||
On Windows, it is also possible to build using Visual Studio, with CMake support installed.
|
||||
|
@ -1,121 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <shlwapi.h>
|
||||
#include <strsafe.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define LINESIZE 1024
|
||||
|
||||
#ifdef __GNUC__
|
||||
static void fail(LPCSTR message, ...) __attribute__((noreturn));
|
||||
#else
|
||||
__declspec(noreturn) static void fail(LPCSTR message, ...);
|
||||
#endif
|
||||
|
||||
static void fail(LPCSTR message, ...)
|
||||
{
|
||||
DWORD written;
|
||||
char msg[LINESIZE];
|
||||
va_list args = NULL;
|
||||
va_start(args, message);
|
||||
StringCchVPrintfA(msg, sizeof(msg), message, args);
|
||||
WriteFile(GetStdHandle(STD_ERROR_HANDLE), message, lstrlen(msg), &written, NULL);
|
||||
ExitProcess(1);
|
||||
}
|
||||
|
||||
BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
|
||||
{
|
||||
switch (fdwCtrlType) {
|
||||
// Handle the CTRL-C signal.
|
||||
case CTRL_C_EVENT:
|
||||
return TRUE;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, LPTSTR argv[])
|
||||
{
|
||||
/* Print the version of this wrapper tool, but only if invoked as "idf.exe".
|
||||
* "idf -v" will invoke idf.py as expected.
|
||||
*/
|
||||
|
||||
LPCTSTR cmdname = PathFindFileName(argv[0]);
|
||||
int cmdname_length = strlen(cmdname);
|
||||
|
||||
if (argc == 2 &&
|
||||
cmdname_length > 4 &&
|
||||
StrCmp(cmdname + cmdname_length - 4, TEXT(".exe")) == 0 &&
|
||||
(StrCmp(argv[1], TEXT("--version")) == 0 ||
|
||||
StrCmp(argv[1], TEXT("-v")) == 0)) {
|
||||
LPCSTR msg = VERSION "\n";
|
||||
DWORD written;
|
||||
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msg, lstrlen(msg), &written, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LPCTSTR idfpy_script_name = TEXT("idf.py");
|
||||
|
||||
/* Get IDF_PATH */
|
||||
TCHAR idf_path[LINESIZE] = { 0 };
|
||||
if (GetEnvironmentVariable(TEXT("IDF_PATH"), idf_path, sizeof(idf_path)) == 0) {
|
||||
DWORD err = GetLastError();
|
||||
if (err == ERROR_ENVVAR_NOT_FOUND) {
|
||||
fail("IDF_PATH environment variable needs to be set to use this tool\n");
|
||||
} else {
|
||||
fail("Unknown error (%u)\n", err);
|
||||
}
|
||||
}
|
||||
|
||||
/* Prepare the command line: python.exe "%IDF_PATH%\\tools\idf.py" <rest of the args> */
|
||||
TCHAR cmdline[LINESIZE] = { 0 };
|
||||
StringCchCat(cmdline, sizeof(cmdline), TEXT("python.exe \""));
|
||||
StringCchCat(cmdline, sizeof(cmdline), idf_path);
|
||||
StringCchCat(cmdline, sizeof(cmdline), TEXT("\\tools\\"));
|
||||
StringCchCat(cmdline, sizeof(cmdline), idfpy_script_name);
|
||||
StringCchCat(cmdline, sizeof(cmdline), TEXT("\" "));
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
StringCchCat(cmdline, sizeof(cmdline), argv[i]);
|
||||
StringCchCat(cmdline, sizeof(cmdline), TEXT(" "));
|
||||
}
|
||||
|
||||
SetEnvironmentVariable(TEXT("IDF_PY_PROGRAM_NAME"), idfpy_script_name);
|
||||
|
||||
// Add processing for Ctrl+C
|
||||
SetConsoleCtrlHandler(CtrlHandler, TRUE);
|
||||
|
||||
/* Reuse the standard streams of this process */
|
||||
STARTUPINFO start_info = {
|
||||
.cb = sizeof(STARTUPINFO),
|
||||
.hStdError = GetStdHandle(STD_ERROR_HANDLE),
|
||||
.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE),
|
||||
.hStdInput = GetStdHandle(STD_INPUT_HANDLE),
|
||||
.dwFlags = STARTF_USESTDHANDLES
|
||||
};
|
||||
|
||||
/* Run the child process */
|
||||
PROCESS_INFORMATION child_process;
|
||||
if (!CreateProcess(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &start_info, &child_process)) {
|
||||
DWORD err = GetLastError();
|
||||
if (err == ERROR_FILE_NOT_FOUND) {
|
||||
fail("Can not find Python\n");
|
||||
} else {
|
||||
fail("Unknown error (%u)\n", err);
|
||||
}
|
||||
}
|
||||
|
||||
/* Wait for it to complete */
|
||||
WaitForSingleObject(child_process.hProcess, INFINITE);
|
||||
|
||||
/* Return with the exit code of the child process */
|
||||
DWORD exitcode;
|
||||
if (!GetExitCodeProcess(child_process.hProcess, &exitcode)) {
|
||||
fail("Couldn't get the exit code (%u)\n", GetLastError());
|
||||
}
|
||||
return exitcode;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_PROCESSOR x86)
|
||||
set(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
|
||||
set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
Loading…
x
Reference in New Issue
Block a user