Mailinglist Archive: zypp-commit (171 mails)

< Previous Next >
[zypp-commit] <libzypp> master : Allow building libzypp without HAL (limited device detection).
  • From: Michael Andres <ma@xxxxxxx>
  • Date: Wed, 17 Jun 2009 15:48:18 +0200
  • Message-id: <E1MGvVu-0002sE-9q@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit c92d367cadaeda00a786a2bdc44a531d5ef05f95
Author: Michael Andres <ma@xxxxxxx>
Date: Wed Jun 17 15:48:18 2009 +0200

Allow building libzypp without HAL (limited device detection).
---
CMakeLists.txt | 11 +++++++--
zypp/media/MediaCD.cc | 41 ++++++++++++++++++++++++++++++++-------
zypp/target/hal/HalContext.cc | 35 ++++++++++++++++++++++++++++-----
zypp/target/hal/HalException.h | 4 +++
4 files changed, 74 insertions(+), 17 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7a411aa..9fb552d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -74,11 +74,16 @@ ELSE (GETTEXT_FOUND)
ENDIF (GETTEXT_FOUND)

FIND_PACKAGE(Hal REQUIRED)
-IF ( NOT HAL_FOUND)
- MESSAGE( FATAL_ERROR " Hal not found" )
+IF ( NOT HAL_FOUND )
+ MESSAGE( WARNING " Package 'hal' not found. HAL is mainly used for CD/DVD
device detection." )
+ MESSAGE( WARNING " If you build libzypp without HAL, this will result in a
limited" )
+ MESSAGE( WARNING " CD/DVD device detection (/dev/dvd,/dev/cdrom)." )
+ SET(HAL_LIBRARY "")
+ SET(HAL_STORAGE_LIBRARY "")
+ ADD_DEFINITIONS(-DNO_HAL)
ELSE ( NOT HAL_FOUND)
INCLUDE_DIRECTORIES(${HAL_INCLUDE_DIR})
-# hal/libhal-storage.h is broken grrr
+ # hal/libhal-storage.h is broken grrr
INCLUDE_DIRECTORIES(${HAL_INCLUDE_DIR}/hal)
ENDIF( NOT HAL_FOUND)

diff --git a/zypp/media/MediaCD.cc b/zypp/media/MediaCD.cc
index 6e8455a..53843d2 100644
--- a/zypp/media/MediaCD.cc
+++ b/zypp/media/MediaCD.cc
@@ -166,13 +166,13 @@ namespace zypp {
cmd[1] = device_r.c_str();
cmd[2] = NULL;
ExternalProgram eject(cmd, ExternalProgram::Stderr_To_Stdout);
-
+
for(std::string out( eject.receiveLine());
out.length(); out = eject.receiveLine())
{
DBG << " " << out;
}
-
+
if(eject.close() != 0)
{
WAR << "Eject of " << device_r << " failed." << std::endl;
@@ -218,21 +218,22 @@ namespace zypp {
MediaCD::DeviceList
MediaCD::detectDevices(bool supportingDVD) const
{
- using namespace zypp::target::hal;
-
DeviceList detected;
+
+#ifndef NO_HALa
+ using namespace zypp::target::hal;
try
{
HalContext hal(true);

std::vector<std::string> drv_udis;
drv_udis = hal.findDevicesByCapability("storage.cdrom");
-
+
DBG << "Found " << drv_udis.size() << " cdrom drive udis" << std::endl;
for(size_t d = 0; d < drv_udis.size(); d++)
{
HalDrive drv( hal.getDriveFromUDI( drv_udis[d]));
-
+
if( drv)
{
bool supportsDVD=false;
@@ -275,7 +276,25 @@ namespace zypp {
{
ZYPP_CAUGHT(e);
}
-
+#else // NO_HAL
+#warning Poor CDROM devices detection without HAL
+ WAR << "Cdrom drive detection without HAL! " << std::endl;
+ PathInfo dvdinfo( "/dev/dvd" );
+ PathInfo cdrinfo( "/dev/cdrom" );
+ if ( dvdinfo.isBlk() )
+ {
+ MediaSource media( "cdrom", dvdinfo.path().asString(), dvdinfo.major(),
dvdinfo.minor() );
+ DBG << "Found (NO_HAL): " << media << std::endl;
+ detected.push_back( media );
+ }
+ if ( cdrinfo.isBlk()
+ && ! ( cdrinfo.major() == dvdinfo.major() && cdrinfo.minor() ==
dvdinfo.minor() ) )
+ {
+ MediaSource media( "cdrom", cdrinfo.path().asString(), cdrinfo.major(),
cdrinfo.minor() );
+ DBG << "Found (NO_HAL): " << media << std::endl;
+ detected.push_back( media );
+ }
+#endif
return detected;
}

@@ -698,8 +717,8 @@ namespace zypp {
bool is_automounted = false;
if( media.mediaSource && !media.mediaSource->name.empty())
{
+#ifndef NO_HAL
using namespace zypp::target::hal;
-
try
{
HalContext hal(true);
@@ -742,6 +761,12 @@ namespace zypp {
{
ZYPP_CAUGHT(e);
}
+#else // NO_HAL
+#warning Can not detect automounted media without HAL
+ INT << "Can not detect automounted media without HAL!" << endl;
+ // ma@: This codepath is probably unused due to 'REUSE_FOREIGN_MOUNTS == 2'
+ // Maybe we should cleanup all this automount-specail-handling.
+#endif
}
DBG << "Media " << media.mediaSource->asString()
<< " attached on " << media.attachPoint->path
diff --git a/zypp/target/hal/HalContext.cc b/zypp/target/hal/HalContext.cc
index 640902d..c80367d 100644
--- a/zypp/target/hal/HalContext.cc
+++ b/zypp/target/hal/HalContext.cc
@@ -10,7 +10,30 @@
*
* \brief Hardware abstaction layer library wrapper implementation.
*/
-#ifndef FAKE_HAL // disables zypp's HAL dependency
+#include <zypp/target/hal/HalException.h>
+//////////////////////////////////////////////////////////////////////
+namespace zypp
+{ ////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////
+ namespace target
+ { //////////////////////////////////////////////////////////////////
+ //////////////////////////////////////////////////////////////////
+ namespace hal
+ { ////////////////////////////////////////////////////////////////
+ NoHalException::NoHalException()
+ : Exception(_("Sorry, but this version of libzypp was built without
HAL support."))
+ {}
+ ////////////////////////////////////////////////////////////////
+ } // namespace hal
+ //////////////////////////////////////////////////////////////////
+ //////////////////////////////////////////////////////////////////
+ } // namespace target
+ ////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////
+} // namespace zypp
+//////////////////////////////////////////////////////////////////////
+
+#ifndef NO_HAL // disables zypp's HAL dependency

#include <zypp/target/hal/HalContext.h>
#include <zypp/thread/Mutex.h>
@@ -1076,7 +1099,7 @@ namespace zypp
////////////////////////////////////////////////////////////////////
} // namespace zypp
//////////////////////////////////////////////////////////////////////
-#else // FAKE_HAL
+#else // NO_HAL
#include <zypp/target/hal/HalContext.h>
#include <zypp/target/hal/HalException.h>
namespace zypp
@@ -1102,7 +1125,7 @@ namespace zypp

// --------------------------------------------------------------
HalContext::HalContext(bool)
- {}
+ { ZYPP_THROW( NoHalException() ); }
HalContext::~HalContext()
{}
HalContext &
@@ -1142,7 +1165,7 @@ namespace zypp
{ return ""; }
// --------------------------------------------------------------
HalDrive::HalDrive()
- {}
+ { ZYPP_THROW( NoHalException() ); }
HalDrive::~HalDrive()
{}
HalDrive &
@@ -1177,7 +1200,7 @@ namespace zypp

// --------------------------------------------------------------
HalVolume::HalVolume()
- {}
+ { ZYPP_THROW( NoHalException() ); }
HalVolume::~HalVolume()
{}
HalVolume &
@@ -1225,7 +1248,7 @@ namespace zypp
////////////////////////////////////////////////////////////////////
} // namespace zypp
//////////////////////////////////////////////////////////////////////
-#endif // FAKE_HAL
+#endif // NO_HAL

/*
** vim: set ts=2 sts=2 sw=2 ai et:
diff --git a/zypp/target/hal/HalException.h b/zypp/target/hal/HalException.h
index 3ea3189..4b957b8 100644
--- a/zypp/target/hal/HalException.h
+++ b/zypp/target/hal/HalException.h
@@ -94,6 +94,10 @@ namespace zypp
std::string e_msg;
};

+ /** Exception thrown if we were built without hal support (-DNO_HAL).
+ */
+ struct NoHalException: public Exception
+ { NoHalException(); };

////////////////////////////////////////////////////////////////
} // namespace hal
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages