00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014 #include "wx/wxprec.h"
00015
00016 #ifdef __BORLANDC__
00017 #pragma hdrstop
00018 #endif
00019
00020 #ifndef WX_PRECOMP
00021 #include "wx/wx.h"
00022 #endif
00023
00024
00025 #include <wx/fileconf.h>
00026 #include <wx/filename.h>
00027 #include <wx/process.h>
00028
00029 #include "wxp/packagecmd.h"
00030
00031
00032
00033
00034 IMPLEMENT_DYNAMIC_CLASS(wxPackageCommand, wxObject)
00035
00036
00037
00038 #include <wx/arrimpl.cpp> // this is a magic incantation which must be done!
00039 WX_DEFINE_OBJARRAY(wxPackageCommandArrayHelper);
00040
00041
00042
00043 wxPackageCommand wxEmptyPackageCommand;
00044 wxPackageCommandArray wxEmptyPackageCommandArray;
00045
00046
00047
00048
00049
00050
00051
00052 wxString wxPackageCommand::GetProgram() const
00053 {
00054
00055
00056 wxString cmd = GetCommand();
00057
00058 #ifdef __WXMSW__
00059 size_t n = cmd.Find(wxT(".exe"));
00060 cmd = cmd.Left(n == wxNOT_FOUND ? 0 : n+4);
00061 #else
00062 cmd = cmd.BeforeFirst(wxT(' '));
00063 #endif
00064
00065 return cmd;
00066 }
00067
00068 wxString wxPackageCommand::GetProgramWithPath(const wxCompilerSettings &sett) const
00069 {
00070 return sett.GetToolPath(GetProgram());
00071 }
00072
00073 wxString wxPackageCommand::GetProgramArguments() const
00074 {
00075
00076
00077 wxString cmd = GetCommand();
00078 #ifdef __WXMSW__
00079 size_t n = cmd.Find(wxT(".exe"));
00080 return cmd.Mid(n == wxNOT_FOUND ? 0 : n+4);
00081 #else
00082 return cmd.AfterFirst(wxT(' '));
00083 #endif
00084 }
00085
00086 void wxPackageCommand::UpdateWorkingDirectory(const wxString &decompressionpath) const
00087 {
00088
00089
00090
00091 wxFileName path(GetWorkingPath() + wxT("/"), wxPATH_UNIX);
00092
00093 if (path.MakeAbsolute(decompressionpath) && path.DirExists())
00094 wxSetWorkingDirectory(path.GetFullPath());
00095 else
00096 wxSetWorkingDirectory(decompressionpath);
00097 }
00098
00099 long wxPackageCommand::Run(wxProcess *proc) const
00100 {
00101 if (proc) proc->Redirect();
00102
00103
00104
00105 wxString cmd = GetCommand();
00106 wxLogDebug(wxT("Launching command '%s' in dir '%s'"),
00107 cmd.c_str(), wxGetCwd().c_str());
00108
00109
00110 return wxExecute(cmd, wxEXEC_ASYNC|wxEXEC_MAKE_GROUP_LEADER, proc);
00111 }
00112
00113
00114
00115
00116
00117
00118 wxPackageCommand wxPackageCommandArray::GetSubstitutedCmd(size_t n) const
00119 {
00120 wxPackageCommand ret(Item(n));
00121
00122
00123 wxString text(ret.GetCommand());
00124 text.Replace(wxT("$(target)"), GetSelectedTarget());
00125
00126 ret.SetCommand(text);
00127 return ret;
00128 }
00129
00130 wxPackageCommandArray wxPackageCommandArray::GetValidCommandsFor(const wxPackage &pkg) const
00131 {
00132 wxPackageCommandArray ret;
00133 for (size_t i=0; i<GetCount(); i++)
00134 if (Item(i).GetCondition().IsValidForPackage(pkg))
00135 ret.Add(Item(i));
00136
00137 ret.CopyTargets(*this);
00138 return ret;
00139 }
00140
00141
00142
00143
00144
00145
00146
00147
00148 bool wxPackageCommandSet::IsUsedBy(const wxPackageCommandArray *arrays,
00149 wxStringHashMap &touse) const
00150 {
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 size_t checked[wxPBSS_MAX] = { 0, 0, 0, 0 };
00162 for (size_t j=0; j<GetCount(); j++)
00163 {
00164 for (size_t i=0; i<wxPBSS_MAX; i++)
00165 {
00166 if (Item(j).GetCondition().IsValidForStage(wxIdx2PackageBuildSystemStage(i)))
00167 {
00168
00169
00170
00171
00172
00173 if (arrays[i].GetCount() <= checked[i])
00174 return false;
00175
00176
00177 if (arrays[i].Item(checked[i]) != Item(j))
00178 return false;
00179 else
00180 checked[i]++;
00181 }
00182 }
00183 }
00184
00185
00186
00187
00188 wxASSERT(GetCount() > 0);
00189 touse = arrays[0].Item(0).GetKeywords();
00190
00191 return true;
00192 }