From ce7078517f2ecfd2ca5268cbf8e2c23c14265eaf Mon Sep 17 00:00:00 2001 From: anders_k Date: Sun, 14 May 2017 16:16:30 +0000 Subject: [PATCH] Include CPU architecture in the RegTool filename so Library.nsh always picks the correct version git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6859 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/Library/RegTool/RegTool.cpp | 2 +- Contrib/Library/RegTool/SConscript | 6 ++++-- Include/Library.nsh | 12 +++--------- Include/UpgradeDLL.nsh | 12 +++--------- SConstruct | 16 ++++++++-------- Source/build.cpp | 7 +++++-- Source/util.h | 2 +- 7 files changed, 25 insertions(+), 32 deletions(-) diff --git a/Contrib/Library/RegTool/RegTool.cpp b/Contrib/Library/RegTool/RegTool.cpp index c1ae72f9..724ddcc3 100644 --- a/Contrib/Library/RegTool/RegTool.cpp +++ b/Contrib/Library/RegTool/RegTool.cpp @@ -49,7 +49,7 @@ template BOOL CreateProcess(const T*p1,const T*p2,LPSECURITY_ATTRIBUTES static bool IsWinNT() { -#ifdef _WIN64 +#if defined(_WIN64) || (defined(_M_ARM) || defined(__arm__)) return true; #else LPCWSTR str = L"count"; // Using this string because it's already used in other parts of the code diff --git a/Contrib/Library/RegTool/SConscript b/Contrib/Library/RegTool/SConscript index df4e4bde..570f0b81 100644 --- a/Contrib/Library/RegTool/SConscript +++ b/Contrib/Library/RegTool/SConscript @@ -12,6 +12,8 @@ libs = Split(""" ole32 """) -Import('BuildUtil') +Import('BuildUtil env GetArcCPU') -BuildUtil(target, files, libs, entry = 'NSISWinMainNOCRT', nodeflib = True, file_name = 'RegTool.bin') +filename = 'RegTool-' + GetArcCPU(env) + '.bin' + +BuildUtil(target, files, libs, entry = 'NSISWinMainNOCRT', nodeflib = True, file_name = filename) diff --git a/Include/Library.nsh b/Include/Library.nsh index ad24afea..ba554819 100644 --- a/Include/Library.nsh +++ b/Include/Library.nsh @@ -121,21 +121,15 @@ ;------------------------ ;Setup RegTool - !ifdef NSIS_MAKENSIS64 - !if "${NSIS_PTR_SIZE}" < 8 - !error "Incompatible RegTool bitness, compile with 32-bit NSIS!" ; 64-bit RegTool on 32-bit Windows - !endif - !else - !if "${NSIS_PTR_SIZE}" > 4 - !warning "Incompatible RegTool bitness!" ; 32-bit RegTool will probably fail to register 64-bit library - !endif + !if ! /FileExists "${NSISDIR}\Bin\RegTool-${NSIS_CPU}.bin" + !error "Missing RegTool for ${NSIS_CPU}!" !endif ReadRegStr $R3 HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" "${REGTOOL_KEY}" StrCpy $R3 $R3 -4 1 IfFileExists $R3 +3 - File /oname=$R2\${REGTOOL_KEY}.$__INSTALLLLIB_SESSIONGUID.exe "${NSISDIR}\Bin\RegTool.bin" + File /oname=$R2\${REGTOOL_KEY}.$__INSTALLLLIB_SESSIONGUID.exe "${NSISDIR}\Bin\RegTool-${NSIS_CPU}.bin" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \ "${REGTOOL_KEY}" '"$R2\${REGTOOL_KEY}.$__INSTALLLLIB_SESSIONGUID.exe" /S' diff --git a/Include/UpgradeDLL.nsh b/Include/UpgradeDLL.nsh index 6548d488..cfb29471 100644 --- a/Include/UpgradeDLL.nsh +++ b/Include/UpgradeDLL.nsh @@ -67,21 +67,15 @@ Example: ;------------------------ ;Setup RegTool - !ifdef NSIS_MAKENSIS64 - !if "${NSIS_PTR_SIZE}" < 8 - !error "Incompatible RegTool bitness, compile with 32-bit NSIS!" ; 64-bit RegTool on 32-bit Windows - !endif - !else - !if "${NSIS_PTR_SIZE}" > 4 - !warning "Incompatible RegTool bitness!" ; 32-bit RegTool will probably fail to register 64-bit library - !endif + !if ! /FileExists "${NSISDIR}\Bin\RegTool-${NSIS_CPU}.bin" + !error "Missing RegTool for ${NSIS_CPU}!" !endif ReadRegStr $R3 HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" "NSIS.Library.RegTool.v3" StrCpy $R3 $R3 -4 1 IfFileExists $R3 +3 - File /oname=$R2\NSIS.Library.RegTool.v3.$HWNDPARENT.exe "${NSISDIR}\Bin\RegTool.bin" + File /oname=$R2\NSIS.Library.RegTool.v3.$HWNDPARENT.exe "${NSISDIR}\Bin\RegTool-${NSIS_CPU}.bin" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \ "NSIS.Library.RegTool.v3" '"$R2\NSIS.Library.RegTool.v3.$HWNDPARENT.exe" /S' diff --git a/SConstruct b/SConstruct index e4efb16c..411ac05f 100644 --- a/SConstruct +++ b/SConstruct @@ -207,13 +207,13 @@ if defenv['DEBUG']: defenv.Append(CPPDEFINES = ['DEBUG']) # add prefixes defines -if 'NSIS_CONFIG_CONST_DATA_PATH' in defenv['NSIS_CPPDEFINES']: - defenv.Append(NSIS_CPPDEFINES = [('PREFIX_CONF', '"%s"' % defenv.subst('$PREFIX_CONF'))]) - defenv.Append(NSIS_CPPDEFINES = [('PREFIX_DATA', '"%s"' % defenv.subst('$PREFIX_DATA'))]) - defenv.Append(NSIS_CPPDEFINES = [('PREFIX_DOC', '"%s"' % defenv.subst('$PREFIX_DOC'))]) - -# Need this early for the config header files to be placed in -if defenv['UNICODE']: +if 'NSIS_CONFIG_CONST_DATA_PATH' in defenv['NSIS_CPPDEFINES']: + defenv.Append(NSIS_CPPDEFINES = [('PREFIX_CONF', '"%s"' % defenv.subst('$PREFIX_CONF'))]) + defenv.Append(NSIS_CPPDEFINES = [('PREFIX_DATA', '"%s"' % defenv.subst('$PREFIX_DATA'))]) + defenv.Append(NSIS_CPPDEFINES = [('PREFIX_DOC', '"%s"' % defenv.subst('$PREFIX_DOC'))]) + +# Need this early for the config header files to be placed in +if defenv['UNICODE']: if defenv['DEBUG']: defenv.Replace(BUILD_PREFIX = 'build/udebug') else: @@ -791,7 +791,7 @@ for util in utils: path = 'Contrib/' + util build_dir = '$BUILD_PREFIX/' + util - exports = {'BuildUtil' : BuildUtil, 'BuildUtilEnv' : BuildUtilEnv, 'env' : util_env} + exports = {'BuildUtil' : BuildUtil, 'BuildUtilEnv' : BuildUtilEnv, 'env' : util_env, 'GetArcCPU' : GetArcCPU} defenv.SConscript(dirs = path, variant_dir = build_dir, duplicate = False, exports = exports) diff --git a/Source/build.cpp b/Source/build.cpp index 8707255d..f4fc676f 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -134,7 +134,7 @@ CEXEBuild::CEXEBuild(signed char pponly) : m_target_type=TARGET_X86ANSI; #ifdef _WIN32 - if (sizeof(void*) > 4) m_target_type = TARGET_AMD64; // BUGBUG: There is no instruction to select it so we force + if (sizeof(void*) > 4) m_target_type = TARGET_AMD64; // BUGBUG: scons 'TARGET_ARCH' should specify the default #endif build_unicode=TARGET_X86ANSI != m_target_type; build_lockedunicodetarget=false; @@ -3844,7 +3844,7 @@ bool CEXEBuild::IsIntOrUserVar(const LineParser &line, int token) const } int succ; line.gettoken_int(token, &succ); - return !!succ; + return succ != false; } int CEXEBuild::set_target_architecture_data() @@ -3863,6 +3863,9 @@ int CEXEBuild::set_target_architecture_data() } definedlist.set(_T("NSIS_PTR_SIZE"), is_target_64bit() ? _T("8") : _T("4")); + tstring cpu = get_string_prefix(get_target_suffix(m_target_type), _T("-")); + definedlist.set(_T("NSIS_CPU"), cpu.c_str()); // Used by Library.nsh to pick the correct RegTool + definedlist.del(_T("NSIS_IX86")); definedlist.del(_T("NSIS_AMD64")); if (TARGET_AMD64 == m_target_type) diff --git a/Source/util.h b/Source/util.h index 36c9b26c..1ecde3f2 100644 --- a/Source/util.h +++ b/Source/util.h @@ -34,7 +34,7 @@ extern double my_wtof(const wchar_t *str); extern size_t my_strncpy(TCHAR*Dest, const TCHAR*Src, size_t cchMax); -static bool strtrycpy(TCHAR*Dest, const TCHAR*Src, size_t cchCap) { size_t c = my_strncpy(Dest, Src, cchCap); return c < cchCap && !Src[c]; } +template bool strtrycpy(T*Dest, const T*Src, size_t cchCap) { size_t c = my_strncpy(Dest, Src, cchCap); return c < cchCap && !Src[c]; } size_t my_strftime(TCHAR *s, size_t max, const TCHAR *fmt, const struct tm *tm); // Adds the bitmap in filename using resource editor re as id id.