From e37eafaac54fb5d884a40c4f26b856cf6776c870 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 7 Apr 2008 22:03:33 +0000 Subject: [PATCH] maya2egg wrapper program --- pandatool/src/mayaprogs/Sources.pp | 67 +++++--------- pandatool/src/mayaprogs/mayapath.cxx | 117 ++++++++++++++++++++++++ pandatool/src/mayaprogs/mayapath_script | 14 --- 3 files changed, 142 insertions(+), 56 deletions(-) create mode 100755 pandatool/src/mayaprogs/mayapath.cxx delete mode 100644 pandatool/src/mayaprogs/mayapath_script diff --git a/pandatool/src/mayaprogs/Sources.pp b/pandatool/src/mayaprogs/Sources.pp index 1dff2490e2..d0ac7dcce8 100644 --- a/pandatool/src/mayaprogs/Sources.pp +++ b/pandatool/src/mayaprogs/Sources.pp @@ -1,49 +1,16 @@ #define BUILD_DIRECTORY $[HAVE_MAYA] -#define maya2egg maya2egg -#define egg2maya egg2maya -#define mayacopy mayacopy - -#if $[UNIX_PLATFORM] - // On Unix, we need maya2egg to be a script that sets the - // LD_LIBRARY_PATH variable and then invokes the application. On - // Windows, this path seems to get built into the executable so - // there's no need. (Don't know why they didn't decide to compile - // it in also on Unix.) - -#set maya2egg maya2egg_bin -#set egg2maya egg2maya_bin -#set mayacopy mayacopy_bin - -#begin sed_bin_target +#begin bin_target #define TARGET maya2egg - - #define SOURCE mayapath_script - #define COMMAND s:xxx:$[MAYA_LOCATION]:g;s:yyy:$[TARGET]:g;s+zzz+$[MAYA_LICENSE_FILE]+g; - -#end sed_bin_target - -#begin sed_bin_target - #define TARGET egg2maya - - #define SOURCE mayapath_script - #define COMMAND s:xxx:$[MAYA_LOCATION]:g;s:yyy:$[TARGET]:g;s+zzz+$[MAYA_LICENSE_FILE]+g; - -#end sed_bin_target - -#begin sed_bin_target - #define TARGET mayacopy - - #define SOURCE mayapath_script - #define COMMAND s:xxx:$[MAYA_LOCATION]:g;s:yyy:$[TARGET]:g;s+zzz+$[MAYA_LICENSE_FILE]+g; - -#end sed_bin_target - -#endif // $[UNIX_PLATFORM] + #define OTHER_LIBS \ + dtoolbase:c dtoolutil:c dtool:m + #define SOURCES \ + mayapath.cxx +#end bin_target #begin bin_target #define USE_PACKAGES maya - #define TARGET $[maya2egg] + #define TARGET maya2egg_bin #define LOCAL_LIBS \ mayabase mayaegg eggbase progbase #define OTHER_LIBS \ @@ -62,9 +29,17 @@ #end bin_target +#begin bin_target + #define TARGET egg2maya + #define OTHER_LIBS \ + dtoolbase:c dtoolutil:c dtool:m + #define SOURCES \ + mayapath.cxx +#end bin_target + #begin bin_target #define USE_PACKAGES maya - #define TARGET $[egg2maya] + #define TARGET egg2maya_bin #define LOCAL_LIBS \ mayabase mayaegg eggbase progbase #define OTHER_LIBS \ @@ -84,9 +59,17 @@ #end bin_target +#begin bin_target + #define TARGET mayacopy + #define OTHER_LIBS \ + dtoolbase:c dtoolutil:c dtool:m + #define SOURCES \ + mayapath.cxx +#end bin_target + #begin bin_target #define USE_PACKAGES maya - #define TARGET $[mayacopy] + #define TARGET mayacopy_bin #define LOCAL_LIBS cvscopy mayabase progbase #define OTHER_LIBS \ diff --git a/pandatool/src/mayaprogs/mayapath.cxx b/pandatool/src/mayaprogs/mayapath.cxx new file mode 100755 index 0000000000..fcb4a12855 --- /dev/null +++ b/pandatool/src/mayaprogs/mayapath.cxx @@ -0,0 +1,117 @@ +// Filename: mayapath.cxx +// Created by: drose (07Apr08) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +// This program works as a stub to launch maya2egg, egg2maya, and +// similar programs that invoke OpenMaya and require certain +// environment variables to be set first. + +#include "dtoolbase.h" +#include "filename.h" +#include + +#if defined(_WIN32) +#define WIN32_LEAN_AND_MEAN +#include +#endif + +int +main(int argc, char *argv[]) { + // First, get the command line and append _bin, so we will actually + // run maya2egg_bin.exe, egg2maya_bin.exe, etc. + Filename command = Filename::from_os_specific(argv[0]); + +#ifdef _WIN32 + if (command.get_extension() == "exe") { + command.set_extension(""); + } +#endif + + command = command.get_fullpath() + string("_bin"); +#ifdef _WIN32 + command.set_extension("exe"); +#endif + string os_command = command.to_os_specific(); + + + // Now look up $MAYA_LOCATION. We insist that it be set and + // pointing to an actual Maya installation. + Filename maya_location = Filename::expand_from("$MAYA_LOCATION"); + if (maya_location.empty()) { + cerr << "$MAYA_LOCATION is not set!\n"; + exit(1); + } + if (!maya_location.is_directory()) { + cerr << "The directory referred to by $MAYA_LOCATION does not exist!\n"; + exit(1); + } + + // Look for OpenMaya.dll as a sanity check. + Filename openMaya = Filename::dso_filename(Filename(maya_location, "bin/OpenMaya.so")); + if (!openMaya.is_regular_file()) { + cerr << "Could not find $MAYA_LOCATION/bin/" << Filename(openMaya.get_basename()).to_os_specific() << "!\n"; + exit(1); + } + + // Now set PYTHONHOME & PYTHONPATH. Maya2008 requires this to be + // set and pointing within $MAYA_LOCATION, or it might get itself + // confused with another Python installation (e.g. Panda's). + Filename python = Filename(maya_location, "Python"); + if (python.is_directory()) { + { + string putenv_str = "PYTHONHOME=" + python.to_os_specific(); + char *putenv_cstr = strdup(putenv_str.c_str()); + putenv(putenv_cstr); + } + { + string putenv_str = "PYTHONPATH=" + python.to_os_specific(); + char *putenv_cstr = strdup(putenv_str.c_str()); + putenv(putenv_cstr); + } + } + + // Now that we have set up the environment variables properly, chain + // to the actual maya2egg_bin (or whichever) executable. + +#ifdef _WIN32 + // Windows case. + char *command_line = strdup(GetCommandLine()); + STARTUPINFO startup_info; + PROCESS_INFORMATION process_info; + GetStartupInfo(&startup_info); + BOOL result = CreateProcess(os_command.c_str(), + command_line, + NULL, NULL, true, 0, + NULL, NULL, + &startup_info, + &process_info); + if (result) { + WaitForSingleObject(process_info.hProcess, INFINITE); + CloseHandle(process_info.hProcess); + CloseHandle(process_info.hThread); + exit(0); + } + cerr << "Couldn't execute " << command << ": " << GetLastError() << "\n"; + +#else + // Unix case. + execvp(os_command.c_str(), argv); +#endif + + // Couldn't execute for some reason. + return 1; +} diff --git a/pandatool/src/mayaprogs/mayapath_script b/pandatool/src/mayaprogs/mayapath_script deleted file mode 100644 index 38a2fb41b5..0000000000 --- a/pandatool/src/mayaprogs/mayapath_script +++ /dev/null @@ -1,14 +0,0 @@ -#! /bin/sh -MAYA_LOCATION=xxx -export MAYA_LOCATION -if test "$LD_LIBRARY_PATH" = ""; then - LD_LIBRARY_PATH=$MAYA_LOCATION/lib -else - LD_LIBRARY_PATH=$MAYA_LOCATION/lib:$LD_LIBRARY_PATH -fi -if test "zzz" != ""; then - LM_LICENSE_FILE="zzz" - export LM_LICENSE_FILE -fi -export LD_LIBRARY_PATH -exec `dirname $0`/yyy_bin "$@"