Browse Source

support panda-package-version and panda-package-host-url for dev convenience

David Rose 15 years ago
parent
commit
9be238b149

+ 53 - 0
dtool/src/dtoolutil/pandaSystem.cxx

@@ -32,6 +32,11 @@ PandaSystem() :
   _systems(get_class_type())
 {
   _system_names_dirty = false;
+
+  // These are settable via Config.prc, but only in development
+  // (!NDEBUG) mode, and only if they are not already defined.
+  _package_version_string = PANDA_PACKAGE_VERSION_STR;
+  _package_host_url = PANDA_PACKAGE_HOST_URL;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -81,7 +86,11 @@ get_version_string() {
 ////////////////////////////////////////////////////////////////////
 string PandaSystem::
 get_package_version_string() {
+#ifdef NDEBUG
   return PANDA_PACKAGE_VERSION_STR;
+#else
+  return get_global_ptr()->_package_version_string;
+#endif
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -102,7 +111,11 @@ get_package_version_string() {
 ////////////////////////////////////////////////////////////////////
 string PandaSystem::
 get_package_host_url() {
+#ifdef NDEBUG
   return PANDA_PACKAGE_HOST_URL;
+#else
+  return get_global_ptr()->_package_host_url;
+#endif
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -447,3 +460,43 @@ reset_system_names() {
   
   _system_names_dirty = false;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: PandaSystem::set_package_version_string
+//       Access: Private
+//  Description: Loads the value returned by
+//               get_package_version_string().  This is intended to be
+//               called by ConfigPageManager to preload the value from
+//               the panda-package-version config variable, for
+//               developer's convenience.  This has no effect if the
+//               PANDA_PACKAGE_VERSION_STR configure variable is
+//               defined at compilation time.  This also has no effect
+//               in NDEBUG mode.
+////////////////////////////////////////////////////////////////////
+void PandaSystem::
+set_package_version_string(const string &package_version_string) {
+  _package_version_string = PANDA_PACKAGE_VERSION_STR;
+  if (_package_version_string.empty()) {
+    _package_version_string = package_version_string;
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PandaSystem::set_package_host_url
+//       Access: Private
+//  Description: Loads the value returned by
+//               get_package_host_url().  This is intended to be
+//               called by ConfigPageManager to preload the value from
+//               the panda-package-host-url config variable, for
+//               developer's convenience.  This has no effect if the
+//               PANDA_PACKAGE_HOST_URL configure variable is defined
+//               at compilation time.  This also has no effect in
+//               NDEBUG mode.
+////////////////////////////////////////////////////////////////////
+void PandaSystem::
+set_package_host_url(const string &package_host_url) {
+  _package_host_url = PANDA_PACKAGE_HOST_URL;
+  if (_package_host_url.empty()) {
+    _package_host_url = package_host_url;
+  }
+}

+ 8 - 0
dtool/src/dtoolutil/pandaSystem.h

@@ -67,6 +67,9 @@ PUBLISHED:
 private:
   void reset_system_names();
 
+  void set_package_version_string(const string &package_version_string);
+  void set_package_host_url(const string &package_host_url);
+
   typedef pmap<string, string> SystemTags;
   typedef pmap<string, SystemTags> Systems;
   typedef pvector<string> SystemNames;
@@ -75,6 +78,9 @@ private:
   SystemNames _system_names;
   bool _system_names_dirty;
 
+  string _package_version_string;
+  string _package_host_url;
+
   static PandaSystem *_global_ptr;
 
 public:
@@ -87,6 +93,8 @@ public:
 
 private:
   static TypeHandle _type_handle;
+
+  friend class ConfigPageManager;
 };
 
 inline ostream &operator << (ostream &out, const PandaSystem &ps) {

+ 38 - 1
dtool/src/prc/configPageManager.cxx

@@ -14,12 +14,14 @@
 
 #include "configPageManager.h"
 #include "configDeclaration.h"
+#include "configVariableString.h"
 #include "configPage.h"
 #include "prcKeyRegistry.h"
 #include "dSearchPath.h"
 #include "executionEnvironment.h"
 #include "config_prc.h"
 #include "pfstream.h"
+#include "pandaSystem.h"
 
 // This file is generated by ppremake.
 #include "prc_parameters.h"
@@ -373,7 +375,7 @@ reload_implicit_pages() {
   }
 
   if (!_loaded_implicit) {
-    Notify::ptr()->config_initialized();
+    config_initialized();
     _loaded_implicit = true;
   }
 
@@ -646,3 +648,38 @@ scan_up_from(Filename &result, const Filename &dir,
   // Recursively try again on the parent.
   return scan_up_from(result, parent, suffix);
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: ConfigPageManager::config_initialized
+//       Access: Private
+//  Description: This is called once, at startup, the first time that
+//               the config system has been initialized and is ready
+//               to read config variables.  It's intended to be a
+//               place to initialize values that are defined at a
+//               lower level than the config system itself.
+////////////////////////////////////////////////////////////////////
+void ConfigPageManager::
+config_initialized() {
+  Notify::ptr()->config_initialized();
+
+#ifndef NDEBUG
+  ConfigVariableString panda_package_version
+    ("panda-package-version", "",
+     PRC_DESC("This can be used to specify the value returned by "
+              "PandaSystem::get_package_version_str(), in development mode only, "
+              "and only if another value has not already been compiled in.  This "
+              "is intended for developer convenience, to masquerade a development "
+              "build of Panda as a different runtime version.  Use with caution."));
+  ConfigVariableString panda_package_host_url
+    ("panda-package-host-url", "",
+     PRC_DESC("This can be used to specify the value returned by "
+              "PandaSystem::get_package_url_url(), in development mode only, "
+              "and only if another value has not already been compiled in.  This "
+              "is intended for developer convenience, to masquerade a development "
+              "build of Panda as a different runtime version.  Use with caution."));
+
+  PandaSystem *panda_sys = PandaSystem::get_global_ptr();
+  panda_sys->set_package_version_string(panda_package_version);
+  panda_sys->set_package_host_url(panda_package_host_url);
+#endif  // NDEBUG
+}

+ 2 - 0
dtool/src/prc/configPageManager.h

@@ -74,6 +74,8 @@ private:
   bool scan_up_from(Filename &result, const Filename &dir, 
                     const Filename &suffix) const;
 
+  void config_initialized();
+
   typedef vector<ConfigPage *> Pages;
   Pages _implicit_pages;
   Pages _explicit_pages;