FOSSology  4.4.0
Open Source License Compliance by Open Source Software
fo_integration.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2011 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
33 {
34  public $srcPath;
35  public $logPath;
36  protected $LOGFD;
37 
38  public function __construct($sourcePath, $logPath=NULL)
39  {
40  if(empty($sourcePath))
41  {
42  $this->srcPath = getcwd();
43  }
44  else
45  {
46  $this->srcPath = $sourcePath;
47  }
48  if(is_NULL($logPath))
49  {
50  $this->logPath = getcwd() . "/fo_integration.log";
51  }
52  else
53  {
54  $this->logPath = $logPath;
55  }
56  echo "DB: logpath is:$this->logPath\n";
57 
58  $this->LOGFD = fopen($this->logPath, 'a+');
59  if($this->LOGFD === false)
60  {
61  $error = "Error! cannot open $this->logPath" . " File: " . __FILE__ .
62  " on line: " . __LINE__;
63  throw new exception($error);
64  }
65 
66  } // __construct
67 
78  protected function log($message)
79  {
80  if(fwrite($this->LOGFD, $message) === false)
81  {
82  // remove the warning? and have caller do it?
83  echo "WARNING! cannot write to log file, there may be no log messages\n";
84  return false;
85  }
86  return true;
87  } // log
88 
89 } //fo_integration
90 
91 
110 class Build extends FoIntegration
111 {
112 
122  function __construct($srcPath, $logPath=NULL)
123  {
124  parent::__construct($srcPath,$logPath);
125  if (!chdir($this->srcPath))
126  {
127  throw new exception("FATAL! can't cd to $this->srcPath\n");
128  }
129  $this->log("Executing Make Clean\n");
130  $mcLast = exec('make clean > make-clean.out 2>&1', $results, $rtn);
131  //print "results of the make clean are:$rtn, $mcLast\n";
132  $this->log("Executing Make all\n");
133  $makeLast = exec('make > make.out 2>&1', $results, $rtn);
134  //print "results of the make are:$rtn, $makeLast\n"; print_r($results) . "\n";
135  if ($rtn == 0)
136  {
137  //print "results of the make are:\n"; print_r($results) . "\n";
138  if (array_search('Error', $results))
139  {
140  //print "Found Error string in the Make output\n";
141  // TODO: write results out to: make.out ?? what ??
142  throw new exception("Errors in make, inspect make.out for details\n");
143  }
144  }
145  else
146  {
147  throw new exception("Errors in make, inspect make.out for details\n");
148  }
149  } // makeFossology
150 
151 } // build
make fossology, check for warnings and errors
__construct($srcPath, $logPath=NULL)
make fossology
base class for fossology integration.
log($message)
log a message in a file