Commit e536476b authored by pastarmovj's avatar pastarmovj Committed by Commit bot

Re-enable building both 32 and 64 bit version of the GCP port monitor.

BUG=629512
TEST=Builds both 32 and 64 bit dlls on a 32bit build system.

Review-Url: https://codereview.chromium.org/2590433003
Cr-Commit-Position: refs/heads/master@{#439796}
parent a97b4417
......@@ -114,6 +114,7 @@ if (is_win) {
"//chrome/installer/gcapi",
"//chrome/installer/mini_installer",
"//cloud_print",
"//cloud_print/virtual_driver/win/port_monitor:copy_gcp_portmon_binaries",
"//components/policy:pack_policy_templates",
"//courgette",
"//courgette:copy_courgette_binaries",
......
......@@ -436,39 +436,39 @@ FILES = [
# Cloud Print files:
{
'filename': 'gcp_portmon.dll',
'arch': ['64bit'],
'buildtype': ['official'],
'archive': 'cloud_print.zip',
'filegroup': ['symsrc'],
},
{
'filename': 'gcp_portmon.dll.pdb',
'arch': ['64bit'],
'buildtype': ['official'],
'archive': 'cloud_print.zip',
},
{
'filename': 'gcp_portmon64.dll',
'buildtype': ['official'],
'archive': 'cloud_print.zip',
'filegroup': ['symsrc'],
},
{
'filename': 'gcp_driver.inf',
'arch': ['64bit'],
'buildtype': ['official'],
'archive': 'cloud_print.zip',
},
{
'filename': 'gcp_driver.gpd',
'arch': ['64bit'],
'buildtype': ['official'],
'archive': 'cloud_print.zip',
},
{
'filename': 'virtual_driver_setup.exe',
'arch': ['64bit'],
'buildtype': ['official'],
'archive': 'cloud_print.zip',
'filegroup': ['symsrc'],
},
{
'filename': 'virtual_driver_setup.exe.pdb',
'arch': ['64bit'],
'buildtype': ['official'],
'archive': 'cloud_print.zip',
},
......
......@@ -53,8 +53,21 @@ base::FilePath GetSystemPath(const base::string16& binary) {
return path.Append(binary);
}
base::FilePath GetNativeSystemPath(const base::string16& binary) {
if (!IsSystem64Bit())
return GetSystemPath(binary);
base::FilePath path;
// Sysnative will bypass filesystem redirection and give us
// the location of the 64bit system32 from a 32 bit process.
if (!PathService::Get(base::DIR_WINDOWS, &path)) {
LOG(ERROR) << "Unable to get windows path.";
return path;
}
return path.Append(L"sysnative").Append(binary);
}
void SpoolerServiceCommand(const char* command) {
base::FilePath net_path = GetSystemPath(L"net");
base::FilePath net_path = GetNativeSystemPath(L"net");
if (net_path.empty())
return;
base::CommandLine command_line(net_path);
......@@ -71,13 +84,13 @@ void SpoolerServiceCommand(const char* command) {
HRESULT RegisterPortMonitor(bool install, const base::FilePath& install_path) {
DCHECK(install || install_path.empty());
base::FilePath target_path = GetSystemPath(L"gcp_portmon.dll");
base::FilePath target_path = GetNativeSystemPath(GetPortMonitorDllName());
if (target_path.empty()) {
LOG(ERROR) << "Unable to get port monitor target path.";
return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
}
if (install) {
base::FilePath source_path = install_path.Append(L"gcp_portmon.dll");
base::FilePath source_path = install_path.Append(GetPortMonitorDllName());
if (!base::CopyFile(source_path, target_path)) {
LOG(ERROR) << "Unable copy port monitor dll from " << source_path.value()
<< " to " << target_path.value();
......@@ -88,7 +101,7 @@ HRESULT RegisterPortMonitor(bool install, const base::FilePath& install_path) {
return S_OK;
}
base::FilePath regsvr32_path = GetSystemPath(L"regsvr32.exe");
base::FilePath regsvr32_path = GetNativeSystemPath(L"regsvr32.exe");
if (regsvr32_path.empty()) {
LOG(ERROR) << "Can't find regsvr32.exe.";
return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
......@@ -101,7 +114,7 @@ HRESULT RegisterPortMonitor(bool install, const base::FilePath& install_path) {
}
// Use system32 path here because otherwise ::AddMonitor would fail.
command_line.AppendArgPath(GetSystemPath(L"gcp_portmon.dll"));
command_line.AppendArgPath(GetSystemPath(GetPortMonitorDllName()));
base::LaunchOptions options;
options.wait = true;
......
......@@ -14,6 +14,9 @@ group("port_monitor") {
shared_library("port_monitor_dll") {
output_name = "gcp_portmon"
if (current_cpu == "x64") {
output_name = "gcp_portmon64"
}
sources = [
"port_monitor.def",
......@@ -33,6 +36,51 @@ shared_library("port_monitor_dll") {
libs = [ "userenv.lib" ]
}
group("copy_gcp_portmon_binaries") {
deps = [
":copy_gcp_portmon_dll",
]
# TODO(pastarmovj): Find some way to reference the pdb file for the 64bit dll
# simply using it in the sources directive causes gn to error when generating
# the build files.
}
if (current_cpu == "x64") {
copy("copy_gcp_portmon_dll") {
sources = [
"$root_out_dir/gcp_portmon64.dll",
]
outputs = [
"$root_out_dir/gcp_portmon.dll",
]
deps = [
":port_monitor_dll",
]
}
} else {
# Make sure that we have a copy of gcp_portmon64.dll in the root out
# directory.
copy("copy_gcp_portmon_dll") {
if (is_clang) {
gcp_portmon64_toolchain = "//build/toolchain/win:clang_x64"
} else {
gcp_portmon64_toolchain = "//build/toolchain/win:x64"
}
gcp_portmon64_label = ":port_monitor_dll($gcp_portmon64_toolchain)"
gcp_portmon64_out_dir = get_label_info(gcp_portmon64_label, "root_out_dir")
sources = [
"$gcp_portmon64_out_dir/gcp_portmon64.dll",
]
outputs = [
"$root_out_dir/{{source_file_part}}",
]
deps = [
gcp_portmon64_label,
]
}
}
source_set("lib") {
sources = [
"port_monitor.cc",
......
......@@ -629,7 +629,7 @@ DWORD WINAPI Monitor2XcvDataPort(HANDLE xcv_handle,
// dynamic creation of ports.
if (lstrcmp(L"MonitorUI", data_name) == 0) {
DWORD dll_path_len = 0;
base::FilePath dll_path(L"gcp_portmon.dll");
base::FilePath dll_path(cloud_print::GetPortMonitorDllName());
dll_path_len = static_cast<DWORD>(dll_path.value().length());
if (output_data_bytes_needed != NULL) {
*output_data_bytes_needed = dll_path_len;
......
......@@ -74,7 +74,7 @@ HRESULT WINAPI DllRegisterServer(void) {
MONITOR_INFO_2 monitor_info = {0};
// YUCK!!! I can either copy the constant, const_cast, or define my own
// MONITOR_INFO_2 that will take const strings.
base::FilePath dll_path(L"gcp_portmon.dll");
base::FilePath dll_path(cloud_print::GetPortMonitorDllName());
monitor_info.pDLLName = const_cast<LPWSTR>(dll_path.value().c_str());
monitor_info.pName = const_cast<LPWSTR>(dll_path.value().c_str());
if (AddMonitor(NULL, 2, reinterpret_cast<BYTE*>(&monitor_info))) {
......@@ -88,7 +88,7 @@ HRESULT WINAPI DllUnregisterServer(void) {
if (!cloud_print::CanRegister()) {
return E_ACCESSDENIED;
}
base::FilePath dll_path(L"gcp_portmon.dll");
base::FilePath dll_path(cloud_print::GetPortMonitorDllName());
if (DeleteMonitor(NULL, NULL, const_cast<LPWSTR>(dll_path.value().c_str()))) {
return S_OK;
}
......
......@@ -21,6 +21,14 @@ void DisplayWindowsMessage(HWND hwnd,
::MessageBox(hwnd, GetErrorMessage(hr).c_str(), caption.c_str(), MB_OK);
}
base::string16 GetPortMonitorDllName() {
if (IsSystem64Bit()) {
return base::string16(L"gcp_portmon64.dll");
} else {
return base::string16(L"gcp_portmon.dll");
}
}
HRESULT GetPrinterDriverDir(base::FilePath* path) {
BYTE driver_dir_buffer[MAX_PATH * sizeof(wchar_t)];
DWORD needed = 0;
......@@ -36,4 +44,11 @@ HRESULT GetPrinterDriverDir(base::FilePath* path) {
*path = path->Append(L"3");
return S_OK;
}
bool IsSystem64Bit() {
base::win::OSInfo::WindowsArchitecture arch =
base::win::OSInfo::GetInstance()->architecture();
return (arch == base::win::OSInfo::X64_ARCHITECTURE) ||
(arch == base::win::OSInfo::IA64_ARCHITECTURE);
}
} // namespace cloud_print
......@@ -20,9 +20,15 @@ void DisplayWindowsMessage(HWND hwnd,
HRESULT hr,
const base::string16& caption);
// Returns the correct port monitor DLL file name for the current machine.
base::string16 GetPortMonitorDllName();
// Gets the standard install path for "version 3" print drivers.
HRESULT GetPrinterDriverDir(base::FilePath* path);
// Returns TRUE if the current OS is 64 bit.
bool IsSystem64Bit();
} // namespace cloud_print
#endif // CLOUD_PRINT_VIRTUAL_DRIVER_WIN_VIRTUAL_DRIVER_HELPERS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment