Skip to content

Commit

Permalink
Merge branch 'bugfix/tools_installer_fixes' into 'master'
Browse files Browse the repository at this point in the history
tools: fixes for idf_tools.py and Windows tools installer

Closes IDFGH-1545 and IDFGH-1544

See merge request espressif/esp-idf!5595
  • Loading branch information
igrr committed Jul 25, 2019
2 parents 308d034 + 80ad09f commit c191068
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 10 deletions.
5 changes: 4 additions & 1 deletion install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ set IDF_PATH=%IDF_PATH:~0,-1%

echo Installing ESP-IDF tools
python.exe %IDF_PATH%\tools\idf_tools.py install
if %errorlevel% neq 0 goto :end

echo Setting up Python environment
python.exe %IDF_PATH%\tools\idf_tools.py install-python-env
if %errorlevel% neq 0 goto :end

echo All done! You can now run:
echo export.bat
:: Clean up

:end
6 changes: 6 additions & 0 deletions tools/idf_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ def check_version(self, extra_paths=None):
def get_install_type(self):
return self._current_options.install

def compatible_with_platform(self):
return any([v.compatible_with_platform() for v in self.versions.values()])

def get_recommended_version(self):
recommended_versions = [k for k, v in self.versions.items()
if v.status == IDFToolVersion.STATUS_RECOMMENDED
Expand Down Expand Up @@ -1030,6 +1033,9 @@ def action_install(args):
fatal('unknown tool name: {}'.format(tool_name))
raise SystemExit(1)
tool_obj = tools_info[tool_name]
if not tool_obj.compatible_with_platform():
fatal('tool {} does not have versions compatible with platform {}'.format(tool_name, CURRENT_PLATFORM))
raise SystemExit(1)
if tool_version is not None and tool_version not in tool_obj.versions:
fatal('unknown version for tool {}: {}'.format(tool_name, tool_version))
raise SystemExit(1)
Expand Down
18 changes: 18 additions & 0 deletions tools/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@
"install": "always",
"license": "GPL-2.0-or-later",
"name": "esp32ulp-elf",
"platform_overrides": [
{
"install": "on_request",
"platforms": [
"linux-armel",
"linux-i686"
]
}
],
"version_cmd": [
"esp32ulp-elf-as",
"--version"
Expand Down Expand Up @@ -182,6 +191,15 @@
"install": "always",
"license": "GPL-2.0-only",
"name": "openocd-esp32",
"platform_overrides": [
{
"install": "on_request",
"platforms": [
"linux-armel",
"linux-i686"
]
}
],
"version_cmd": [
"openocd",
"--version"
Expand Down
6 changes: 3 additions & 3 deletions tools/windows/tool_setup/idf_cmd_init.bat
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ if "%~2"=="" (
goto :end
)

set IDF_PYTHON_DIR=%1
set IDF_GIT_DIR=%2
set "IDF_PYTHON_DIR=%1"
set "IDF_GIT_DIR=%2"

:: Strip quoutes
set "IDF_PYTHON_DIR=%IDF_PYTHON_DIR:"=%"
Expand Down Expand Up @@ -69,7 +69,7 @@ echo Adding ESP-IDF tools to PATH...
:: It is possible to do this without a temporary file (running idf_tools.py from for /r command),
:: but that way it is impossible to get the exit code of idf_tools.py.
set "IDF_TOOLS_EXPORTS_FILE=%TEMP%\idf_export_vars.tmp"
python.exe %IDF_TOOLS_PY_PATH% --tools-json %IDF_TOOLS_JSON_PATH% export --format key-value >"%IDF_TOOLS_EXPORTS_FILE%"
python.exe "%IDF_TOOLS_PY_PATH%" --tools-json "%IDF_TOOLS_JSON_PATH%" export --format key-value >"%IDF_TOOLS_EXPORTS_FILE%"
if %errorlevel% neq 0 goto :end

for /f "usebackq tokens=1,2 eol=# delims==" %%a in ("%IDF_TOOLS_EXPORTS_FILE%") do (
Expand Down
9 changes: 8 additions & 1 deletion tools/windows/tool_setup/idf_download_page.iss.inc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ var
Page: TInputOptionWizardPage;
IDFPath: String;
begin
Result := False;
Page := TInputOptionWizardPage(Sender);
Log('OnIDFDownloadPageValidate index=' + IntToStr(Page.SelectedValueIndex));

Expand All @@ -110,7 +111,13 @@ begin
begin
MsgBox('Directory already exists and is not empty:' + #13#10 +
IDFPath + #13#10 + 'Please choose a different directory.', mbError, MB_OK);
Result := False;
exit;
end;

if Pos(' ', IDFPath) <> 0 then
begin
MsgBox('ESP-IDF build system does not support spaces in paths.' + #13#10
'Please choose a different directory.', mbError, MB_OK);
exit;
end;

Expand Down
7 changes: 7 additions & 0 deletions tools/windows/tool_setup/idf_page.iss.inc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ begin
exit;
end;

if Pos(' ', IDFPath) <> 0 then
begin
MsgBox('ESP-IDF build system does not support spaces in paths.' + #13#10
'Please choose a different directory.', mbError, MB_OK);
exit;
end;

IDFPyPath := IDFPath + '\tools\idf.py';
if not FileExists(IDFPyPath) then
begin
Expand Down
10 changes: 6 additions & 4 deletions tools/windows/tool_setup/idf_setup.iss.inc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ begin
end;

ExtractTemporaryFile('7za.exe')
CmdLine := ExpandConstant('{tmp}\7za.exe x -o' + ExpandConstant('{tmp}') + ' -r -aoa ' + IDFZIPFileName);
CmdLine := ExpandConstant('{tmp}\7za.exe x -o' + ExpandConstant('{tmp}') + ' -r -aoa "' + IDFZIPFileName + '"');
IDFTempPath := ExpandConstant('{tmp}\esp-idf-') + IDFZIPFileVersion;
Log('Extracting ESP-IDF reference repository: ' + CmdLine);
Log('Reference repository path: ' + IDFTempPath);
Expand Down Expand Up @@ -212,9 +212,9 @@ begin
end else begin
Log('idf_tools.py does not exist in IDF directory, using a fallback version');
IDFToolsPyCmd := ExpandConstant(PythonExecutablePath
+ ' {app}\idf_tools_fallback.py'
+ ' "{app}\idf_tools_fallback.py"'
+ ' --idf-path ' + IDFPath
+ ' --tools {app}\tools_fallback.json');
+ ' --tools "{app}\tools_fallback.json"');
end;

Log('idf_tools.py command: ' + IDFToolsPyCmd);
Expand All @@ -238,7 +238,9 @@ begin
ForceDirectories(ExpandConstant('{group}'));
Destination := ExpandConstant('{group}\{#IDFCmdExeShortcutFile}');
Description := '{#IDFCmdExeShortcutDescription}';
Command := ExpandConstant('/k {app}\idf_cmd_init.bat "') + PythonPath + '" "' + GitPath + '"';
{ If cmd.exe command argument starts with a quote, the first and last quote chars in the command
will be removed by cmd.exe; each argument needs to be surrounded by quotes as well. }
Command := ExpandConstant('/k ""{app}\idf_cmd_init.bat" "') + PythonPath + '" "' + GitPath + '""';
Log('CreateShellLink Destination=' + Destination + ' Description=' + Description + ' Command=' + Command)
try
CreateShellLink(
Expand Down
3 changes: 2 additions & 1 deletion tools/windows/tool_setup/idf_tool_setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={%USERPROFILE}\.espressif
UsePreviousAppDir=no
DirExistsWarning=no
DefaultGroupName=ESP-IDF
DisableProgramGroupPage=yes
Expand Down Expand Up @@ -78,7 +79,7 @@ Filename: "{group}\{#IDFCmdExeShortcutFile}"; Flags: postinstall shellexec; Desc

[Registry]
Root: HKCU; Subkey: "Environment"; ValueType: string; ValueName: "IDF_TOOLS_PATH"; \
ValueData: "{app}"; Flags: preservestringtype createvalueifdoesntexist;
ValueData: "{app}"; Flags: preservestringtype createvalueifdoesntexist uninsdeletevalue deletevalue;

[Code]
Expand Down
22 changes: 22 additions & 0 deletions tools/windows/tool_setup/main.iss.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ begin
idpDownloadAfter(wpReady);
end;

{ If IDF_TOOLS_PATH is set in the environment,
set the default installation directory accordingly.
Note: here we read IDF_TOOLS_PATH using GetEnv rather than
by getting it from registry, in case the user has set
IDF_TOOLS_PATH as a system environment variable manually. }
<event('InitializeWizard')>
procedure UpdateInstallDir();
var
EnvToolsPath: String;
begin
EnvToolsPath := GetEnv('IDF_TOOLS_PATH');
if EnvToolsPath <> '' then
begin
WizardForm.DirEdit.Text := EnvToolsPath;
end;
end;

<event('NextButtonClick')>
function PreInstallSteps(CurPageID: Integer): Boolean;
var
Expand Down Expand Up @@ -75,6 +92,11 @@ begin
Log('Setting PATH for this process: ' + EnvPath);
SetEnvironmentVariable('PATH', EnvPath);

{ Set IDF_TOOLS_PATH variable, in case it was set to a different value in the environment.
The installer will set the variable to the new value in the registry, but we also need the
new value to be visible to this process. }
SetEnvironmentVariable('IDF_TOOLS_PATH', ExpandConstant('{app}'))

{ Log and clear PYTHONPATH variable, as it might point to libraries of another Python version}
PythonLibPath := GetEnv('PYTHONPATH')
Log('PYTHONPATH=' + PythonLibPath)
Expand Down

0 comments on commit c191068

Please sign in to comment.