Skip to content

Commit 7945e7d

Browse files
committed
slighlty reorganzid the tag checkout. main functions now listed in index.php
1 parent 8201795 commit 7945e7d

File tree

5 files changed

+178
-25
lines changed

5 files changed

+178
-25
lines changed

InstallLibrary.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/bash
2+
3+
BASEDIR=$(readlink -f $0 | xargs dirname)
4+
CFGFILE="$BASEDIR""/config/ALFA_settings.sh"
5+
source "$CFGFILE"
6+
7+
IFS="
8+
"
9+
10+
echo $BASEDIR
11+
echo $CFGFILE
12+
echo $LIBRARY_DIR
13+
14+
15+
REPO="$1"
16+
VERSION="$2"
17+
cd "$LIBRARY_DIR"
18+
19+
#git clone "$REPO"
20+
RDIR=$(basename "$REPO" ".git")
21+
cd "$RDIR"
22+
23+
tags=$(git tag | grep "^""$VERSION")
24+
if [ "$tags" == "" ]
25+
then
26+
tags=$(git tag | grep -i "^v""$VERSION")
27+
fi
28+
29+
if [ "$tags" != "" ]
30+
then
31+
git checkout "tags/""$tags"
32+
fi

config/ALFA_settings.sh

100644100755
+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/bin/bash
22

33
#If you installed arduino-cli with brew this should be fine
4-
#Otherwise please
4+
#Otherwise please set to the correct directories
5+
6+
export ARDUINO_CLI_BIN=$(which arduino-cli)
7+
export ARDUINO_HOME_DIR=~/Arduino/
8+
export LIBRARY_DIR="$ARDUINO_HOME_DIR""libraries/"
59

6-
ARDUINO_CLI_BIN=$(which arduino-cli)
7-
ARDUINO_HOME_DIR=~/Arduino/
810

index.php

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,45 @@
1-
<php
1+
<?php
22
include_once("php/init.php");
33

4+
5+
//Delete all libraries and make an empty sketch
6+
if(false){
7+
CreateSketch();
8+
}
9+
10+
// add a new library
11+
if(false){
12+
$url = "https://github.com/MHeironimus/ArduinoJoystickLibrary";
13+
$tmp = fAddNewLibrary($url);
14+
}
15+
16+
// test a library by known ID
17+
if(false){
18+
$id = 29824;
19+
$platform = 1;
20+
TestLibraryByID($id, $platform );
21+
}
22+
23+
// test a library by known Name
24+
if(false){
25+
26+
}
27+
28+
29+
//CreateSketch();
30+
//$prog_space = 0;
31+
//$dyn_space = 0;
32+
33+
//CompileSketch($prog_space,$dyn_space);
34+
35+
36+
//ClearAllLibraries();
37+
38+
39+
//InstallLibrary("Adafruit SHT31 Library","1.1.8");
40+
//InstallLibrary("SIKTEC_AVR_Controller","1.0.6");
41+
//TestLibraryByID(18428);
42+
//TestNewestLibraryByName("Better Joystick");
43+
44+
445
?>

php/includes/common_functions.php

+89-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Composer\InstalledVersions;
34

45
$installed = array();
56

@@ -89,6 +90,35 @@ function InstallLibrary($libraryname, $version , $blank = true){
8990
$tmp = `$callstring`;
9091
}
9192

93+
function InstallLibraryByID($libraryID , $blank = true){
94+
global $Settings;
95+
global $installed;
96+
//echo "Already installed :::::::::::::" . PHP_EOL;
97+
//print_r($installed);
98+
if($blank) {
99+
ClearAllLibraries();
100+
$installed = array();
101+
}
102+
$libdata = DB::queryFirstRow("Select * from libs WHERE id = %i",$libraryID);
103+
$version = $libdata['lib_version'];
104+
$libraryname = $libdata['lib_name'];
105+
106+
if(in_array($libraryname,$installed)) return true;
107+
echo "Installing $libraryname " . PHP_EOL;
108+
$installed[] = $libraryname;
109+
110+
//print_r($libdata);
111+
//$callstring = "cd " . $Settings['arduino_library'] . " && git clone -b '$version' " . str_replace('https://github.com/','[email protected]:',$libdata['lib_url']) . " 2>/dev/null";
112+
//echo $callstring . PHP_EOL;
113+
GitCheckoutTag($libdata['lib_url'],$version);
114+
if(strlen($libdata['lib_depends'])> 0){
115+
$libs = explode(",",$libdata['lib_depends']);
116+
for($x=0; $x< count($libs);$x++){
117+
if(!in_array($libs[$x],$installed)) InstallNewestLibrary($libs[$x],false);
118+
}
119+
}
120+
//$tmp = `$callstring`;
121+
}
92122

93123
function InstallNewestLibrary($libraryname,$IsNewInstall = true){
94124
$libdata = DB::queryFirstRow("Select * from libs WHERE lib_name LIKE %s ORDER by lib_version DESC",$libraryname);
@@ -115,8 +145,9 @@ function TestLibraryByID($id, $platform = 1){
115145
$offDyn = $Settings['platformdata'][$platform]['platform_emptydyn'] ;
116146
global $Settings;
117147
$libdata = DB::queryFirstRow("Select * from libs WHERE id LIKE %i",$id);
118-
InstallNewestLibrary($libdata['lib_name'],true);
119148
if(!is_array($libdata)) return false;
149+
// InstallNewestLibrary($libdata['lib_name'],true);
150+
InstallLibraryByID($id);
120151
$examples = FindLibraryExamples($libdata['lib_url']);
121152
$completed = false;
122153
$minPS = 999999999;
@@ -182,11 +213,11 @@ function fIsLibraryChecked($liburl){
182213
return false;
183214
}
184215

185-
function fGetLibraryDetails($liburl){
216+
function fAddNewLibrary($liburl){
186217
global $Settings;
187-
//ClearAllLibraries();
188-
//$callstring = "cd " . $Settings['arduino_library'] . " && git clone " . str_replace('https://github.com/','[email protected]:',$liburl) . " 2>/dev/null";
189-
//$tmp = `$callstring`;
218+
ClearAllLibraries();
219+
$callstring = "cd " . $Settings['arduino_library'] . " && git clone " . str_replace('https://github.com/','[email protected]:',$liburl) . " 2>/dev/null";
220+
$tmp = `$callstring`;
190221
$callstring = "find " . $Settings['arduino_library'] . " -name 'library.properties'" ;
191222
//echo $callstring . PHP_EOL;
192223
$pf = str_replace("\n","",`$callstring`);
@@ -201,36 +232,75 @@ function fGetLibraryDetails($liburl){
201232
$pf = array();
202233

203234
for($y=0;$y < count($tags);$y++){
204-
$pf[$tag] = "";
235+
$pf[$tags[$y]] = "";
205236
}
206237

207238
for($x = 0; $x < count($lines);$x++){
208239
$line = $lines[$x];
209-
240+
echo "--->" . $line . PHP_EOL;
210241
for($y=0;$y < count($tags);$y++){
211242
$tag = $tags[$y];
212243
if(strlen($line)>strlen($tag ."=")) if(substr($line,0,strlen($tag . "=")) == $tag . "=") $pf[$tag] = explode("=",$line,2)[1];
213-
244+
214245
}
215246

216247
print_r(substr($line,0,strlen("version=")));
217248
echo PHP_EOL;
218249
}
219250

251+
$snippet['architectures'] = array();
252+
if(strlen($pf['architectures'])> 0){
253+
$snippet['architectures'] = explode(",",$pf['architectures']);
254+
}
255+
256+
$depends = "";
257+
$snippet['depends'] = array();
258+
if(strlen($pf['depends'])> 0){
259+
260+
$snippet['depends'] = explode(",",$pf['depends']);
261+
for($x = 0; $x < count($snippet['depends']);$x++){
262+
$snippet['depends'][$x] = trim($snippet['depends'][$x]);
263+
}
264+
}
265+
$depends = implode(",",$snippet['depends']);
266+
267+
268+
$data = [
269+
'lib_name' => $pf['name'],
270+
'lib_url' => $liburl,
271+
'lib_version' => $pf['version'],
272+
'lib_depends' => $depends,
273+
'lib_architectures' => "," . implode(",",$snippet['architectures']) . ",",
274+
'lib_sentence' => $pf['sentence'],
275+
//'pf' => $pf
276+
];
277+
db::insertIgnore("libs",$data);
278+
$pf = $data;
220279

221280
}
281+
282+
222283
return $pf;
223284
}
224285

225286

226-
/*
227-
version=1.7.0
228-
author=Arduino
229-
maintainer=Arduino <[email protected]>
230-
sentence=Enables communication between the Linux processor and the microcontroller. For Arduino Yún, Yún Shield and TRE only.
231-
paragraph=The Bridge library features: access to the shared storage, run and manage Linux processes, open a remote console, access to the Linux file system, including the SD card, establish HTTP clients or servers.
232-
category=Communication
233-
url=http://www.arduino.cc/en/Reference/YunBridgeLibrary
234-
architectures=*
235-
236-
*/
287+
function GitCheckoutTag($liburl,$version){
288+
global $Settings;
289+
$callstring = "cd " . $Settings['arduino_library'] . " && git clone " . str_replace('https://github.com/','[email protected]:',$liburl) . " 2>/dev/null";
290+
$bnc = "basename '$liburl' '.git'";
291+
$bn = str_replace("\n","", `$bnc`);
292+
$tmp = `$callstring`;
293+
$callstring = "cd '" . $Settings['arduino_library'] . $bn . "' && git tag";
294+
$tmp = `$callstring`;
295+
$finaltag="";
296+
$tags = explode("\n",$tmp);
297+
for($x=0;$x<count($tags);$x++){
298+
if ( $version == $tags[$x] || "v" . $version == $tags[$x] || "v." . $version == $tags[$x] ){
299+
$finaltag = $tags[$x];
300+
}
301+
}
302+
if(strlen($finaltag)>0){
303+
$callstring = "cd '" . $Settings['arduino_library'] . $bn . "' && git checkout 'tags/$finaltag'";
304+
$tmp = `$callstring`;
305+
}
306+
}

php/subworker.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33

44
include_once( __DIR__ . "/init.php");
55

6+
$url = 'https://github.com/arduino-libraries/Bridge.git';
7+
$url = "https://github.com/adafruit/Adafruit_VL53L0X";
8+
$url = "https://github.com/MHeironimus/ArduinoJoystickLibrary";
9+
//$tmp = fAddNewLibrary($url);
10+
11+
//print_r($tmp);
12+
13+
//GitCheckoutTag( "[email protected]:MHeironimus/ArduinoJoystickLibrary.git" ,"2.1.1");
14+
15+
616

7-
$tmp = fGetLibraryDetails('https://github.com/arduino-libraries/Bridge.git');
817

9-
print_r($tmp);
1018
/*
1119
$sql = "SELECT * from libs WHERE lib_platform = 1 AND (lib_mindynspace <= 149 OR lib_minprogspace <= 3462) ";
1220

0 commit comments

Comments
 (0)