[Gambas-user] Multi-purpose SHELL process in gambas2-2.0.0

M0E Lnx m0e.lnx at ...626...
Mon Mar 3 14:30:04 CET 2008


Anybody?? Please?

On Fri, Feb 29, 2008 at 2:39 PM, M0E Lnx <m0e.lnx at ...626...> wrote:
> Hello again fellow gambasian coders...
>
> I'm kinda stuck and require your expertise on a problem I'm having...
> I've been trying this for a couple of days, with the same results,
> trying to see if anyone's got a good suggestiongthat might help me
>
> Here is the idea.
> This application is supposed to build software from source. From that
> we gather that there are several steps to be taken from extracting the
> source, to installing the resulting binaries.
> In the previous versions of this application, I used one(1) process
> for each step of the build process (up to 4). This is sort of messy
> and hard to track, but I made it work.
> In an effort to consolidate the code, and offer better error checking
> and more accurary, I'm trying to have ONLY ONE(1) process and have
> functions to tell the process what to do.
>
> It almost works, But i'm having problems where it's not triggering the
> right sequence, and it seems to not be executing all of the code in
> the process_kill() event.
>
> Please look at this piece of code...
>
> 'Gambas class file
> PUBLIC hBuildProc AS Process
> PUBLIC iBuildState AS Integer ' Enumerated build state (0 - 5)
> PUBLIC sBuildType AS String PRIVATE sShellCmd AS String
>
> PUBLIC SUB process_read()
> DIM iReturnvalue AS Integer
> DIM sLine AS String
> READ #LAST, sLine, -256
> ' Insert the buffer read into the text area for the user to see
> FrmBuildView.taTerm.pos = Len(FrmBuildView.taTerm.text)
> FrmBuildView.taTerm.Insert(sLine)
> END
>
> PUBLIC SUB process_error(errormessage AS String)
> FrmBuildView.taTerm.pos = Len(FrmBuildView.taTerm.text)
> FrmBuildView.taTerm.Insert(errormessage)
> END
>
>
> PUBLIC SUB Process_kill()
> DIM iRetval AS Integer
> DIM iNextStepNum AS Integer
>
> iRetval = ME.QUICK_ERROR_CHECK(FrmBuildView.taTerm.text, "FAILED")
>
> SELECT CASE iRetval
> CASE 1 ' Error was found
>  MdlMain.WRITE_TO_BUILD_LOG("Error detected in the build process... aborting")
>
>    FrmBuildView.tmProgress.Enabled = FALSE
>    ME.TOGGLE_CANCEL_BUTTON(FALSE)
>    STOP EVENT
> CASE 0 ' All clear... go to the next step
>
>     SELECT CASE ME.iBuildState
>        CASE 0 ' extraction is done
>          ME.GUESS_SRC_TYPE(ClsGlobal.sTMP_DIR &/ ClsBuildVars.sName &
> "-" & ClsBuildVars.sVersion)
>        CASE ELSE
>        'iNextStepNum = ME.iBuildState + 1
>          SELECT CASE ME.sBuildType
>            CASE "GNU"
>                'WHILE iBuildState < 4
>                IF ibuildstate < 4
>              ME.BUILD_C(ClsBuildVars.sName, ClsBuildVars.sVersion,
> ClsBuildVars.sSlackDesc, ME.iBuildState + 1)
>                'WEND
>                END IF
>          END SELECT
>
>    END SELECT
>
> END SELECT
>
> END
>
>
> PUBLIC FUNCTION BUILD_C(sName AS String, sVer AS String, sPkgDescPath
> AS String, iBuildStep AS Integer)
>
>  'Assumes GNU style build will be used (determined by the type of source found)
>
>  DIM sArch AS String = ClsBuildVars.sArch
>  DIM sRel AS String = ClsBuildVars.sRel
>  DIM sTag AS String = ClsBuildVars.sTag
>  DIM sConfig AS String = ClsBuildVars.sConfig
>  DIM sCFLAGS AS String = ClsBuildVars.sCFLAGS
>  DIM sPkgType AS String = ClsBuildVars.sType
>  DIM sFullPackageName AS String = sName & "-" & sVer & "-" & sArch &
> "-" & sRel & sTag & "." & sPkgType
>  DIM sTmpSpace AS String = ClsGlobal.sTMP_DIR
>  DIM sBuildDir AS String = sTmpSpace &/ sName & "-" & sVer &/ "build"
>  'DIM sShellCmd AS String
>  DIM sPKG AS String = sBuildDir &/ "PKG"
>  DIM sLackDescDest AS String = sPKG &/ "install"
>
>  'message.Info(iBuildStep)
>
>  SELECT CASE iBuildStep
>
>    'CASE 0 ' Guess
>
>    CASE 1 ' Configure the source
>        IF IsDir(sBuildDir) = FALSE THEN
>          PRINT "Creating build directory"
>          TRY MKDIR sBuildDir
>        END IF
>        MdlMain.WRITE_TO_BUILD_LOG("Begin configure process...")
>    sShellCmd = "cd " & sBuildDir & " && ../configure " & sConfig & "
> CFLAGS=\'" & sCFLAGS & "\' || echo \'FAILED\'"
>      FrmBuildView.PbBuildProg.value = 0.25
>    'RETURN
>    CASE 2 ' Run make
>      MdlMain.WRITE_TO_BUILD_LOG("Run make")
>    sShellCmd = "cd " & sBuildDir & " && make || echo \'FAILED\'"
>    FrmBuildView.PbBuildProg.value = 0.50
>    'RETURN
>    CASE 3 ' make install
>        MdlMain.WRITE_TO_BUILD_LOG("Run make install")
>        IF IsDir(sPkg) = FALSE THEN
>          MKDIR sPKG
>        END IF
>
>    ' insert the slack-desc into the package
>      IF IsDir(sLackDescDest) = FALSE THEN
>        MKDIR sLackDescDest
>      END IF
>        ME.INSERT_DESC(ClsBuildVars.sSlackDesc, sLackDescDest)
>    sShellCmd = "cd " & sBuildDir & " && make DESTDIR=" & sPKG & "
> install || echo \'FAILED\'"
>
>    FrmBuildView.PbBuildProg.value = 0.75
>    'RETURN
>    CASE 4
>      MdlMain.WRITE_TO_BUILD_LOG("Package built source")
>    ME.PACKAGE(sBuildDir &/ "PKG")
>    CASE 101 ' on error
>    sShellCmd = ""
>    STOP EVENT
>    RETURN
>
>
>
>  END SELECT
>
> EXECUTE_PROCESS(iBuildStep)
>
>
> END
>
>
>
> PUBLIC FUNCTION QUICK_ERROR_CHECK(sRawText AS String, sMatch AS
> String) AS Integer
> IF InStr(sRawText, sMatch) > 0 THEN
> FrmBuildView.tmProgress.Enabled = FALSE   ' Found an error, stop the timer
> RETURN 1
> ELSE
> RETURN 0
> END IF
> END
>
> ______________________ END OF MODULE _______________________________
>
> Whew!.. that was a lot of code.
>
> Basically, in a nutshell, what this is supposed to do is this
> I have a function that assigns a different value to a variable
> (sShellCmd) every time it is ran (the value is based on the results of
> the previous step)
> After this variable is assigned the new value, the same function
> triggers the process.
> When the process ends (using the process_kill() event for this), I run
> an error check (using the QUICK_ERROR_CHECK function avobe) This
> function decides wether the process will continue or not.
>
>
> PLEASE HELP
> You are more than welcome to checkout the full source code and take a
> look at how everything works (or at least is supposed to work)
> together.
> svn co http://vpackager.googlecode.com/svn/branches/1.0.11/trunk
> or browse it online... Here is a link to the FULL MODULE
> http://code.google.com/p/vpackager/source/browse/branches/1.0.11/trunk/MdlBuild.module
>
> Again, Using gambas-2.2.0.0
> Thanks
>




More information about the User mailing list