From 96100505b0b052a861fda0a98d30851d7372244c Mon Sep 17 00:00:00 2001 From: Jan Jongboom Date: Mon, 30 Oct 2017 13:21:21 +0100 Subject: [PATCH] Add pre-compiled mbed CLI version, remove pip dependency --- prerequisites/download-prerequisites.ps1 | 4 +- source/cliInstall.nsi | 130 +++++++++++++++++++++-- source/pip_install_mbed.bat | 23 ---- 3 files changed, 122 insertions(+), 35 deletions(-) delete mode 100644 source/pip_install_mbed.bat diff --git a/prerequisites/download-prerequisites.ps1 b/prerequisites/download-prerequisites.ps1 index 3a3bcfa..911dfa5 100644 --- a/prerequisites/download-prerequisites.ps1 +++ b/prerequisites/download-prerequisites.ps1 @@ -25,6 +25,6 @@ $url = "https://developer.mbed.org/media/downloads/drivers/mbedWinSerial_16466.e $file = "$storageDir\mbedWinSerial_16466.exe" $webclient.DownloadFile($url,$file) #Download mbed-cli -$url = "https://github.com/ARMmbed/mbed-cli/archive/1.2.2.zip" -$file = "$storageDir\mbed-cli-1.2.2.zip" +$url = "https://raw.githubusercontent.com/ARMmbed/mbed-cli-binaries/60e771045aef34d566dd2bcaadbf021af79eb24f/mbed-cli-win-1.2.2.exe" +$file = "$storageDir\mbed-cli-win-1.2.2.exe" $webclient.DownloadFile($url,$file) diff --git a/source/cliInstall.nsi b/source/cliInstall.nsi index b2f3902..a153fa4 100644 --- a/source/cliInstall.nsi +++ b/source/cliInstall.nsi @@ -45,8 +45,8 @@ ${StrTrimNewLines} ;-------------------------------- ;Config Section !define PRODUCT_NAME "Mbed CLI for Windows" - !define PRODUCT_VERSION "0.4.2" - !define MBED_CLI_ZIP "mbed-cli-1.2.2.zip" + !define PRODUCT_VERSION "0.4.3" + !define MBED_CLI_EXE "mbed-cli-win-1.2.2.exe" !define MBED_CLI_VERSION "mbed-cli-1.2.2" !define PRODUCT_PUBLISHER "Arm Mbed" !define PYTHON_INSTALLER "python-2.7.13.msi" @@ -105,6 +105,118 @@ InstType /CUSTOMSTRING=Advanced InstType /COMPONENTSONLYONCUSTOM InstType "Default" +;-------------------------------- +;Functions from https://www.smartmontools.org/browser/trunk/smartmontools/os_win32/installer.nsi?rev=4110#L636 + +; StrStr - find substring in a string +; +; Usage: +; Push "this is some string" +; Push "some" +; Call StrStr +; Pop $0 ; "some string" + +!macro StrStr un +Function ${un}StrStr + Exch $R1 ; $R1=substring, stack=[old$R1,string,...] + Exch ; stack=[string,old$R1,...] + Exch $R2 ; $R2=string, stack=[old$R2,old$R1,...] + Push $R3 + Push $R4 + Push $R5 + StrLen $R3 $R1 + StrCpy $R4 0 + ; $R1=substring, $R2=string, $R3=strlen(substring) + ; $R4=count, $R5=tmp + loop: + StrCpy $R5 $R2 $R3 $R4 + StrCmp $R5 $R1 done + StrCmp $R5 "" done + IntOp $R4 $R4 + 1 + Goto loop +done: + StrCpy $R1 $R2 "" $R4 + Pop $R5 + Pop $R4 + Pop $R3 + Pop $R2 + Exch $R1 ; $R1=old$R1, stack=[result,...] +FunctionEnd +!macroend +!insertmacro StrStr "" + +!include "WinMessages.nsh" +!define Environ 'HKCU "Environment"' + +Function AddToPath + Exch $0 + Push $1 + Push $2 + Push $3 + Push $4 + + ; NSIS ReadRegStr returns empty string on string overflow + ; Native calls are used here to check actual length of PATH + + ; $4 = RegOpenKey(HKEY_CURRENT_USER, "Environment", &$3) + System::Call "advapi32::RegOpenKey(i 0x80000001, t'Environment', *i.r3) i.r4" + IntCmp $4 0 0 done done + ; $4 = RegQueryValueEx($3, "PATH", (DWORD*)0, (DWORD*)0, &$1, ($2=NSIS_MAX_STRLEN, &$2)) + ; RegCloseKey($3) + System::Call "advapi32::RegQueryValueEx(i $3, t'PATH', i 0, i 0, t.r1, *i ${NSIS_MAX_STRLEN} r2) i.r4" + System::Call "advapi32::RegCloseKey(i $3)" + + IntCmp $4 234 0 +4 +4 ; $4 == ERROR_MORE_DATA + DetailPrint "AddToPath: original length $2 > ${NSIS_MAX_STRLEN}" + MessageBox MB_OK "PATH not updated, original length $2 > ${NSIS_MAX_STRLEN}" + Goto done + + IntCmp $4 0 +5 ; $4 != NO_ERROR + IntCmp $4 2 +3 ; $4 != ERROR_FILE_NOT_FOUND + DetailPrint "AddToPath: unexpected error code $4" + Goto done + StrCpy $1 "" + + ; Check if already in PATH + Push "$1;" + Push "$0;" + Call StrStr + Pop $2 + StrCmp $2 "" 0 done + Push "$1;" + Push "$0\;" + Call StrStr + Pop $2 + StrCmp $2 "" 0 done + + ; Prevent NSIS string overflow + StrLen $2 $0 + StrLen $3 $1 + IntOp $2 $2 + $3 + IntOp $2 $2 + 2 ; $2 = strlen(dir) + strlen(PATH) + sizeof(";") + IntCmp $2 ${NSIS_MAX_STRLEN} +4 +4 0 + DetailPrint "AddToPath: new length $2 > ${NSIS_MAX_STRLEN}" + MessageBox MB_OK "PATH not updated, new length $2 > ${NSIS_MAX_STRLEN}." + Goto done + + ; Append dir to PATH + DetailPrint "Add to PATH: $0" + StrCpy $2 $1 1 -1 + StrCmp $2 ";" 0 +2 + StrCpy $1 $1 -1 ; remove trailing ';' + StrCmp $1 "" +2 ; no leading ';' + StrCpy $0 "$1;$0" + WriteRegExpandStr ${Environ} "PATH" $0 + SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 + +done: + Pop $4 + Pop $3 + Pop $2 + Pop $1 + Pop $0 +FunctionEnd + ;-------------------------------- ;Installer Sections @@ -145,15 +257,13 @@ SectionEnd Section "mbed" SecMbed SectionIn 1 ; --- install Mbed CLI --- - ReadRegStr $0 HKLM "SOFTWARE\Python\PythonCore\2.7\InstallPath" "" - File "..\prerequisites\${MBED_CLI_ZIP}" - nsisunz::Unzip "$INSTDIR\${MBED_CLI_ZIP}" "$INSTDIR\mbed-cli" - DELETE "$INSTDIR\${MBED_CLI_ZIP}" - File "..\source\pip_install_mbed.bat" - nsExec::ExecToStack '$INSTDIR\pip_install_mbed.bat $0 $INSTDIR\mbed-cli\${MBED_CLI_VERSION}' - DELETE "$INSTDIR\pip_install_mbed.bat" + File "..\prerequisites\${MBED_CLI_EXE}" + Rename "$INSTDIR\${MBED_CLI_EXE}" "$INSTDIR\mbed.exe" ; --- add shortcut and batch script to windows --- File "..\source\p.ico" + ; --- add to PATH --- + Push "$INSTDIR" + Call AddToPath SectionEnd Section "git-scm" SecGit @@ -205,11 +315,11 @@ SectionEnd ;-------------------------------- Section "Uninstall" - nsExec::ExecToStack 'pip uninstall -y mbed-cli' ;uninstall mbed-cli RMDir /r "$INSTDIR\mbed-cli" Delete "$INSTDIR\${MBED_SERIAL_DRIVER}" Delete "$INSTDIR\p.ico" Delete "$INSTDIR\mbed_uninstall.exe" + Delete "$INSTDIR\mbed.exe" RMDir "$INSTDIR\" ;remove install folder(only if empty) DeleteRegKey SHCTX "${UNINST_KEY}" SectionEnd diff --git a/source/pip_install_mbed.bat b/source/pip_install_mbed.bat deleted file mode 100644 index bc5dc70..0000000 --- a/source/pip_install_mbed.bat +++ /dev/null @@ -1,23 +0,0 @@ -:: Copyright (c) 2015 ARM Limited. All rights reserved. -:: -:: SPDX-License-Identifier: Apache-2.0 -:: -:: 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. -:: -:: Set python\scripts variable because the environment hasnt been updated since python install. -set PYTHON_PATH=;%1;%1Scripts;%1Tools\Scripts; -set PATH=%PYTHON_PATH%;%PATH%; - -:: ensure that pip is installed -cd %2 -cmd /K "python setup.py install & exit"