From a5afc764a0faf2b38df8a2073683f50e6930b28b Mon Sep 17 00:00:00 2001 From: AndreyFilippov Date: Tue, 13 Sep 2016 21:48:53 -0600 Subject: [PATCH] set up Eclkipse/CDT project --- .gitignore | 14 + Makefile | 27 ++ VERSION | 1 + eclipse_project_setup/.cproject | 93 ++++++ .../SCP apps-editconf to target.launch | 8 + eclipse_project_setup/.project | 41 +++ run_bitbake.sh | 11 + src/Makefile | 42 +++ src/editconf.c | 271 +++++++++++++++++ src/editconf.php | 69 +++++ src/strconf.cpp | 118 ++++++++ src/unescape | Bin 0 -> 13176 bytes src/unescape.c | 49 +++ used_files.py | 280 ++++++++++++++++++ 14 files changed, 1024 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 VERSION create mode 100644 eclipse_project_setup/.cproject create mode 100644 eclipse_project_setup/.externalToolBuilders/SCP apps-editconf to target.launch create mode 100644 eclipse_project_setup/.project create mode 100755 run_bitbake.sh create mode 100644 src/Makefile create mode 100644 src/editconf.c create mode 100644 src/editconf.php create mode 100644 src/strconf.cpp create mode 100755 src/unescape create mode 100644 src/unescape.c create mode 100755 used_files.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fffb27e --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +html/* +attic/* +/.project +/.cproject +/.pydevproject +/.externalToolBuilders +/.settings +.directory +generated* +sysroots +bitbake-logs +/temp +*.o +*.cgi diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..923969e --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +# Runs 'make', 'make install', and 'make clean' in specified subdirectories +SUBDIRS := src +INSTALLDIRS = $(SUBDIRS:%=install-%) +CLEANDIRS = $(SUBDIRS:%=clean-%) + +#TARGETDIR=$(DESTDIR)/www/pages + +all: $(SUBDIRS) + @echo "make all top" + +$(SUBDIRS): + $(MAKE) -C $@ + +install: $(INSTALLDIRS) + @echo "make install top" + +$(INSTALLDIRS): + $(MAKE) -C $(@:install-%=%) install + +clean: $(CLEANDIRS) + @echo "make clean top" + +$(CLEANDIRS): + $(MAKE) -C $(@:clean-%=%) clean + +.PHONY: all install clean $(SUBDIRS) $(INSTALLDIRS) $(CLEANDIRS) + diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..631b9b5 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.0 diff --git a/eclipse_project_setup/.cproject b/eclipse_project_setup/.cproject new file mode 100644 index 0000000..c122aa7 --- /dev/null +++ b/eclipse_project_setup/.cproject @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eclipse_project_setup/.externalToolBuilders/SCP apps-editconf to target.launch b/eclipse_project_setup/.externalToolBuilders/SCP apps-editconf to target.launch new file mode 100644 index 0000000..dda8b61 --- /dev/null +++ b/eclipse_project_setup/.externalToolBuilders/SCP apps-editconf to target.launch @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/eclipse_project_setup/.project b/eclipse_project_setup/.project new file mode 100644 index 0000000..172fafd --- /dev/null +++ b/eclipse_project_setup/.project @@ -0,0 +1,41 @@ + + + elphel-apps-editconf + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + full,incremental, + + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/SCP apps-editconf to target.launch + + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder (2).launch + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/run_bitbake.sh b/run_bitbake.sh new file mode 100755 index 0000000..8e63ac0 --- /dev/null +++ b/run_bitbake.sh @@ -0,0 +1,11 @@ +#!/bin/bash +args="$@" +while (( "$#" )); do + shift +done +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +echo "Launching bitbake $args" +cd $DIR/../../poky +. ./oe-init-build-env +bitbake $args | sed -u 's@| @@' +exit 0 diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..fff5f02 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,42 @@ + +#INSTDIR = $(prefix)/usr/local/bin/ +CGIDIR = /www/pages +BINDIR = /usr/bin/ +INSTMODE = 0755 +INSTOWNER = root +INSTGROUP = root + +PROGS = editconf.cgi unescape strconf.cgi +SRCS = editconf.c unescape.c strconf.cpp +OBJS = editconf.o unescape.o + +OBJS += $(SOURCES:.cpp=.o) + +CFLAGS += -Wall -I$(STAGING_DIR_HOST)/usr/include-uapi + +all: $(PROGS) + +strconf.cgi: strconf.o + $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@ +editconf.cgi: editconf.o + $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ +unescape: unescape.o + $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ + +install: $(PROGS) + $(INSTALL) $(OWN) -d $(DESTDIR) + $(INSTALL) $(OWN) -d $(DESTDIR)$(CGIDIR) + $(INSTALL) $(OWN) -d $(DESTDIR)$(BINDIR) + $(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) strconf.cgi $(DESTDIR)$(CGIDIR) + $(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) editconf.cgi $(DESTDIR)$(CGIDIR) + $(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) unescape $(DESTDIR)$(BINDIR) + $(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) xmlxmt.cgi $(DESTDIR)$(CGIDIR) + $(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) editconf.php $(DESTDIR)$(CGIDIR) +clean: + rm -rf $(PROGS) *.o core +#dependency: +# make depend +#depend: +# makedepend -Y -- $(CFLAGS) -- $(SRCS) 2>/dev/null +# touch dependency +# DO NOT DELETE diff --git a/src/editconf.c b/src/editconf.c new file mode 100644 index 0000000..a4e230b --- /dev/null +++ b/src/editconf.c @@ -0,0 +1,271 @@ +/* +** -----------------------------------------------------------------------------** +** editconf.c +** +** Copyright (C) 2006 Elphel, Inc. +** +** -----------------------------------------------------------------------------** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +** -----------------------------------------------------------------------------** +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define THIS_DEBUG 1 +#define QRY_MAXPARAMS 64 + +char copyQuery [4096]; +const char *uri; +const char *method; +const char *query; + +struct key_value { + char *key; + char *value; +}; + +struct key_value gparams[QRY_MAXPARAMS+1]; + +int unescape(char *, int); +int hexdigit(char); +char * paramValue(struct key_value *, char *); +int parseQuery(struct key_value *, char *); + + +int main(argc, argv) + int argc; + char *argv[]; +{ + int i; //,j,k,a,l; + char fileName[256]; + char confKey[256]; +// char confSection[256]; + char confValue[1024]; + char *confFile=NULL; + char *confFileCopy=NULL; + char * v; + int useEQ=1; + FILE * cfile; + int thisError=0; + size_t fileSize; + char * cp; + char * ep; + char * lineEnd; + char * lineStart; + char * keyStart; + char * valueStart; + + + fileName[0]=0; fileName[sizeof(fileName)-1]=0; + confKey[0]=0; confKey[sizeof(confKey)-1]=0; + confValue[0]=0; confValue[sizeof(confValue)-1]=0; +// short int hsz[2]; + +// struct stat buf; + + method = getenv("REQUEST_METHOD"); + query = getenv("QUERY_STRING"); + uri = getenv("REQUEST_URI"); + if (argc > 1) method = NULL; // to fix a bug when a script is called as CGI and uses editconf as a command line app. + if (method == NULL) { + if (argc<3) {printf("This program should be run as a CGI from the web server or:\n" \ + "editconf filename key - will return a key value if any\n" \ + "editconf filename key value - will set a value to a key (using '=' as separator)" \ + "editconf filename key value 0 - will set a value to a key (using ' ' as separator)"); + exit (0);} + strncpy(fileName,argv[1], sizeof(fileName)); + strncpy(confKey, argv[2], sizeof(confKey)); + if (argc>3) strncpy(confValue,argv[3], sizeof(confValue)); + if (argc>4) useEQ =atoi(argv[4]); + + /* Not a CGI! */ +// printf("This program should be run as a CGI from the web server!\n"); +// exit(1); + } else { + + i= (query)? strlen (query):0; +// fprintf(stderr,"querry length=%d\n", i); + + if (i>(sizeof(copyQuery)-1)) i= sizeof(copyQuery)-1; + if (i>0) strncpy(copyQuery,query, i); + copyQuery[i]=0; + unescape(copyQuery,sizeof(copyQuery)); + + parseQuery(gparams, copyQuery); + + if((v = paramValue(gparams, "file")) != NULL) strncpy(fileName,v, sizeof(fileName)); + if((v = paramValue(gparams, "key")) != NULL) strncpy(confKey,v, sizeof(confKey)); + if((v = paramValue(gparams, "value")) != NULL) strncpy(confValue,v, sizeof(confValue)); + if((v = paramValue(gparams, "eq")) != NULL) useEQ=atoi (v); + +// int keyFound=0; + printf("Content-Type: text/xml\n"); + printf("Pragma: no-cache\n\n"); // 2 new lines! + printf("\n\n"); +// printf("%d\n",argc); +/* + if (fileName[0]) printf("%s\n",fileName); + if (confKey[0]) printf("%s\n",confKey); + if (confValue[0]) printf("%s\n",confValue); + printf("%d\n",useEQ); +*/ + } // end of METHOD==NULL/else +#ifdef THIS_DEBUG + fprintf (stderr,"editconf(file='%s'\n",fileName); + fflush(stderr); +#endif + + unescape (confValue, sizeof(confValue)); + + +// printf("%s\n",fileName); + if ((cfile = fopen(fileName, "r"))==NULL) {thisError=-1;} + else { + fseek(cfile, 0L, SEEK_END); + fileSize= ftell(cfile); + confFile= (char*) malloc(fileSize+1); + fseek(cfile, 0L, SEEK_SET); + i=fread(confFile, 1, fileSize, cfile); + for (i=0; i=cp) && strchr(" \t",lineEnd[0])) { + lineEnd[0]=0; + lineEnd--; + } + lineEnd++; + for (;(strchr(" \t",cp[0])) && (cp%s\n",keyStart,valueStart,keyStart); + } + } // end of for (lineStart=confFile;(lineStart-confFile)%d\n",fileSize); +//printf ("%d\n",(lineStart-confFile)); +//printf ("%d\n",(lineEnd-confFile)); +//printf ("%d\n",(keyStart-confFile)); +//printf ("%d\n",(keyStart-confFile)); + + if (!confValue[0]) { // read value] + if (method == NULL) { + if ((lineStart-confFile)%s\n",valueStart); + else if (confKey[0]) printf ("%d\n",-3); // key not found + } + } else { // modify value + if ((cfile = fopen(fileName, "w"))==NULL) {thisError=-2;} + else { // file opened OK + fwrite(confFileCopy, 1, (lineStart-confFile), cfile); // write everything before the line with a key (if any) + if (confValue[0]!='#') { // replace the key + if ((lineStart>confFile) && (confFileCopy[lineStart-confFile-1] != '\n')) fprintf(cfile,"\n"); + if (useEQ) fprintf(cfile,"%s=%s\n",confKey,confValue); + else fprintf(cfile,"%s %s\n",confKey,confValue); + } + if ((ep-confFile) < fileSize) fwrite(confFileCopy+(ep+1-confFile), 1, (confFile+ fileSize - ep-1), cfile); // write everything after the line with a key (if any) + } + } + } + if (method != NULL) { + if ((confValue[0])&& !thisError) printf("0\n"); + if (confFile) free (confFile); + if (confFileCopy) free (confFileCopy); + if (thisError) printf("%d\n",thisError); + printf("\n"); + } + return 0; +} + +int unescape (char * s, int l) { + int i=0; + int j=0; + while ((i=0) && (i<10)) return i; + i=c-'a'+10; + if ((i>=10) && (i<16)) return i; + i=c-'A'+10; + if ((i>=10) && (i<16)) return i; + return 0; // could be -1?? +} + +char * paramValue(struct key_value * params, char * skey) { // returns pointer to parameter value, NULL if not defined + int i=0; + if (skey) + while ((i. +*! -----------------------------------------------------------------------------** +*! $Log: editconf.php,v $ +*! Revision 1.1 2008/12/09 07:49:32 elphel +*! added editconf.php - supplements editconf.cgi to deal with internal parameters, has the same interface to simplify interfacing from camvc +*! +*! +*/ + $sensor_port=0; + $key=$_GET['key']; + $value=$_GET['key']; + $param=array(); + $param[$_GET['key']]=myval($_GET['value']); + $xml = new SimpleXMLElement(""); + if (array_key_exists('sensor_port',$_GET)) { + $sensor_port = myval($_GET['sensor_port']); + } + if (array_key_exists('key',$_GET)) { + if ($key=='ftp_left_time') { + $param=elphel_get_P_arr($sensor_port,array('FTP_NEXT_TIME'=>0)); + $xml->addChild ('value',$param['FTP_NEXT_TIME']-time()); + } else if (array_key_exists('value',$_GET)) { + $frame=elphel_set_P_arr($sensor_port,$param); + $xml->addChild ('error',$frame?0:-3); + } else { + $param=elphel_get_P_arr($sensor_port,$param); + $xml->addChild ('value',$param[$_GET['key']]); + } + } else { + $xml->addChild ('error',0); + } + if (array_key_exists('sync',$_GET)) { + exec ('sync'); + $xml->addChild ('sync','OK'); + } + $rslt=$xml->asXML(); + header("Content-Type: text/xml"); + header("Content-Length: ".strlen($rslt)."\n"); + header("Pragma: no-cache\n"); + printf($rslt); + + exit (0); +function myval ($s) { + $s=trim($s,"\" "); + if (strtoupper(substr($s,0,2))=="0X") return intval(hexdec($s)); + else return intval($s); +} +//http://192.168.0.7/editconf.php?&key=DAEMON_EN_CCAMFTP&value=1&eq=1&_time=1228790213230 +?> diff --git a/src/strconf.cpp b/src/strconf.cpp new file mode 100644 index 0000000..c021a63 --- /dev/null +++ b/src/strconf.cpp @@ -0,0 +1,118 @@ +#include +#include +#include +#include +#include +#include + +using namespace std; + +void load(string fn, map &c) { + int i; + char *z; + string s; + ifstream ifile(fn.c_str()); + while(!ifile.eof()) { + ifile >> s; + z = const_cast(s.c_str()); + for(i = 0; z[i]; i++) + if(z[i] == '=') { + z[i] = '\0'; + c[&z[0]] = &z[i + 1]; + break; + } + } + ifile.close(); +/* + for(map::iterator it = c.begin(); it != c.end(); it++) + syslog(LOG_ALERT, "|%s|==|%s|\r\n", (*it).first.c_str(), (*it).second.c_str()); +syslog(LOG_ALERT, "//||\\\\--------------------------- %s\r\n", fn.c_str()); +*/ +} + +void save(string fn, map &c) { + string s; + ofstream of(fn.c_str()); +/* + for(map::iterator it = c.begin(); it != c.end(); it++) + syslog(LOG_ALERT, "|%s|==|%s|\r\n", (*it).first.c_str(), (*it).second.c_str()); +*/ + for(map::iterator it = c.begin(); it != c.end(); it++) { + s = (*it).first; + s += "="; + s += (*it).second; + of << s; + of << endl; + } + of.close(); +} + +int main() { + const char *uri; + const char *method; + const char *query; +// map in +// string in; +// string out; + map params; + map in; + map out; + + method = getenv("REQUEST_METHOD"); + query = getenv("QUERY_STRING"); + uri = getenv("REQUEST_URI"); +/* +syslog(LOG_ALERT, "REQUEST_METHOD=|%s|\r\n", method); +syslog(LOG_ALERT, "REQUEST_STRING=|%s|\r\n", query); +syslog(LOG_ALERT, "REQUEST_URI=|%s|\r\n", uri); + +syslog(LOG_ALERT, "strconf!\r\n"); +*/ + // parse GET params + string p_s = query; + char *p = const_cast(p_s.c_str()); +//syslog(LOG_ALERT, "string: |%s|\r\n", p); + int i, j, k; + k = 0; + bool f = false, to_break = false; + for(i = 0; ; i++) { + if(p[i] == '\'') + f = !f; + if((p[i] == '&' || p[i] == '\0') && !f) { + if(p[i] == '\0') + to_break = true; + else + p[i] = '\0'; + for(j = k; p[j]; j++) { + if(p[j] == '=') { + p[j] = '\0'; + params[&p[k]] = &p[j + 1]; + break; + } + } + k = i + 1; + f = false; + } + if(to_break) + break; + } + // load 'in' and 'out' file; + load(params["in"], in); + load(params["out"], out); +///* + in["init_1"] = out["init_1"]; + in["init_2"] = out["init_2"]; +///* + if(params["init_1"] != "''") + in["init_1"] = params["init_1"]; + if(params["init_2"] != "''") + in["init_2"] = params["init_2"]; +//*/ + save(params["out"], in); +//*/ +// for(map::iterator it = params.begin(); it != params.end(); it++) { +// syslog(LOG_ALERT, "param: |%s|==|%s|\r\n", (*it).first.c_str(), (*it).second.c_str()); +// } + + return 0; +} diff --git a/src/unescape b/src/unescape new file mode 100755 index 0000000000000000000000000000000000000000..79e863767f2fe8b4858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5QLgRC{@Efk)+I?kTFQi-?*^0v2+<#S1cfWPjrcFCG z?zDDx_w;Y1y4jn4t8eF(R>e6xuk593cJeSra82%aSbhnx1EcwmstfHhLdg}RaV}5JLwicP2R=aZPH|+UH<1T@6Txaro=MZoWdb(>zf|ld{WE663S_rY0+W;KjiSlC(!F|hN z$no953uOZ37`7r{wv^>^KXV*%gP^&C0V-vn47$uX#u+J7y1Ob zAAt{+l;ir1{{uMXq#=^!(oa(eS|8VOwHO3#6mWpHGW-NV%W-`agWQ??{08KhPW!md zSPeOMeW`=+a|Gfs5&+7n-Lj&|WB5-5=*p>7j19=G(*$CzZypehlYIx|=mQPf*48<4 zgJ9eYSq)mpvN>`uqj8q7QVwXjRdeJ%!lLP1SB16Q`Z;nTY~2rPWr%f_en(FGWdd?V zJt!eZeGI$j=xfF$JO3M?fii@lIdU-^1ai!1(0-xsUDXp$LXKZ(YS1WSS21Gsx%kc) c{#%ChBm(OZMBtp^*0. +** -----------------------------------------------------------------------------** +*/ + +#include +#include + int hexdigit (char c) { + int i; + i=c-'0'; + if ((i>=0) && (i<10)) return i; + i=c-'a'+10; + if ((i>=10) && (i<16)) return i; + i=c-'A'+10; + if ((i>=10) && (i<16)) return i; + return 0; // could be -1?? +} + +int main(argc, argv) + int argc; + char *argv[]; +{ + if (argc<2) {printf("unescape returnes unescaped string (argument) to stdout\n"); return 0; } + int i=0; + while (argv[1][i]) { + if ((argv[1][i]=='%') && argv[1][i+1]) { // behavior from Mozilla + printf("%c", (char) (hexdigit(argv[1][i+1])<<4) | hexdigit(argv[1][i+2])); + i+=3; + } else printf("%c",argv[1][i++]); + } + return 0; +} diff --git a/used_files.py b/used_files.py new file mode 100755 index 0000000..6eb6152 --- /dev/null +++ b/used_files.py @@ -0,0 +1,280 @@ +#!/usr/bin/env python +# encoding: utf-8 +from __future__ import division +from __future__ import print_function +""" +# @file used_files.py +# @brief Extract file access data after build, modify CDT project configuration +# (.cproject) accordingly +# @copyright Copyright (C) 2016, Elphel.inc. +# @param License +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +@author: Andrey Filippov +@license: GPLv3.0+ +@contact: andrey@elphel.coml +@deffield updated: Updated +""" +__author__ = "Andrey Filippov" +__copyright__ = "Copyright 2016, Elphel, Inc." +__license__ = "GPL" +__version__ = "3.0+" +__maintainer__ = "Andrey Filippov" +__email__ = "andrey@elphel.com" +__status__ = "Development" + +import sys +import os +import time +import xml.etree.ElementTree as ET +''' +TODO:Automate, find out why separate touch commands are needed +Run this program twice: +1-st run ./used_files.py linux -1 +and save shown timestamp +Then run (some mystery here) +touch src/drivers/ata/ahci_elphel.c +touch src/drivers/elphel/sensor_common.c +Wait 5 seconds and run (in a different console with appropriate sourcing) +bitbake linux-xlnx -c compile -f +Then again +./used_files.py linux +If somethong went wrong you will need to resore .cproject from eclipse_project_setup directory + +For php: +bitbake php -c cleansstate +bitbake php -c unpack -f +bitbake php -c configure -f +./used_files.py php -1 +bitbake php -c compile -f +./used_files.py php 1471044836.8 + +Doing: +bitbake php -c compile -f +./used_files.py php -1 +bitbake php -c compile -f +./used_files.py php 1471044836.8 +Corrupts make process + +''' +def file_tree(flist): # Each file in list is a file, no directories + ftree={} + for p in flist: + node = ftree + seg_list=p.split(os.sep) + last_i=len(seg_list)-1 + for i,segm in enumerate(seg_list): + if not segm in node: + if i == last_i: + node[segm] = None + else: + node[segm] = {} + node=node[segm] + + return ftree + +def exclude_list(ftree, flist): + mark = "*" # no file/dir name can be "*" + def list_tree_recursive(root): + rslt = [] + if not mark in root: + return [[""]] # convert to trailing "/" for directories + for n in root: + if not n == mark: + if root[n] is None: + rslt.append([n]) + else: + + for l in list_tree_recursive(root[n]): + rslt.append([n]+l) + return rslt + + ftree[mark]=None # mark top level dir + for p in flist: + node = ftree + for segm in p.split(os.sep)[:-1]: + node=node[segm] + node[mark]=None # [mark] means used in flist + del node[p.split(os.sep)[-1]] + #print (ftree) +# for k in ftree: +# print(k) + #Now prune unused directories + #prune_recursive(ftree) # (assuming root is used) + # now create list + files_list_list = list_tree_recursive(ftree) +# print (files_list_list) + #converrt to file paths + pl = [] + for l in files_list_list: + pl.append(os.path.join(*(l[1:]))) + pl = sorted (pl) + return pl + + +def proc_tree(): + DEBUG = True + extensions = [".h",".c",".cpp"] + exclude_start = ["linux"+os.sep+"scripts"+os.sep,"linux"+os.sep+"source"+os.sep+"scripts"+os.sep] + delta_t = 3 # seconds + try: + root_path = sys.argv[1] + except: + print ("Calling %s [timestamp]"%(os.path.basename(sys.argv[0]))) + try: + start_time = float(sys.argv[2]) + except: + start_time = 0.0 + + touch_files= start_time < 0.0 + print ("root_path = %s"%(root_path)) +# root_path = "/home/eyesis/git/poky/linux-elphel/linux/" + lstFiles = [] + # Append files to a list + for path, _, files in os.walk(root_path, followlinks = True): + for f in files: + for ext in extensions: + if f.endswith(ext): + lstFiles.append(os.path.join(path, f)) + break + + all_tree= file_tree(sorted(lstFiles)) + include_lst=[] + lst_a = [] + latest_at=0 + for p in lstFiles: + if touch_files: + if os.path.islink(p): + try: + os.utime(os.path.realpath(p), None) + except: + print("missing linked file: %s"%(os.path.realpath(p))) + else: + os.utime(p, None) + else: +# at = time.ctime(os.stat(p).st_atime) + try: + at = os.stat(p).st_atime + l = None + except: + at = 0 + if os.path.islink(p): + try: + l = os.path.realpath(p) + at = os.stat(l).st_atime + except: + at = 0 # missing file + latest_at = max((latest_at,at)) + if at > (start_time + delta_t): + #Scripts/lexers result in problems + exclude=False + for exStr in exclude_start: + if p.startswith(exStr): + exclude=True + break + if exclude: + break + #exclude_start + lst_a.append([p,at,l]) + include_lst.append(p) + if touch_files: + print (len(lstFiles), "last time = ", time.time()) + return + + excluding = exclude_list(all_tree, include_lst) +# print (all_tree) +# print (sorted(include_lst)) +# print ("|".join(excluding)) + if DEBUG: + with open("all_sources.lst","w" ) as f: + for p in sorted(lstFiles): + try: + at = os.stat(p).st_atime + except: + at = 0 + lnk="" + if os.path.islink(p): + try: + at = os.stat(os.path.realpath(p)).st_atime + except: + at = 0 + lnk = os.path.realpath(p) + print (p,at,lnk, file=f) + with open("excluding.lst","w" ) as f: + for p in excluding: + print (p, file=f) + with open("including.lst","w" ) as f: + for p in include_lst: + print (p, file=f) +# include_tree= file_tree(sorted(include_lst)) +# print(include_tree) + root_dir=include_lst[0].split(os.sep)[0] + print ("root_dir=",root_dir) + + xml= ET.parse(".cproject") + root=xml.getroot() +# for child in root: +# print(child.tag, child.attrib) + + for child in root.iter('sourceEntries'): + for gchild in child: + print(gchild.tag) + + for child in root.iter('sourceEntries'): + for gchild in child: + if gchild.tag == 'entry': + attr = gchild.attrib + try: + if (attr['kind'] == 'sourcePath') and (attr['name'] == root_dir): + child.remove (gchild) + print ("Removed existing entry ",gchild.tag) + break + except: + print ("error matching attributes for ",gchild.tag) + pass + break #after first 'sourceEntries' - should be just one? + ET.SubElement(child, 'entry', {"flags":"VALUE_WORKSPACE_PATH", "kind":"sourcePath", "name":root_dir, "excluding":"|".join(excluding)}) + + for child in root.iter('sourceEntries'): + for gchild in child: + print(gchild.tag) + + oneliner= ET.tostring(root) + #overwrites original .cproject, may change to somethong different + with open(".cproject", "wr") as f: + f.write(""" +""") + f.write(oneliner) + + print (len(lstFiles), len(lst_a), "last access time = ",latest_at) + +if __name__ == '__main__': + proc_tree() + """ +Usage for new applications: +1) add src to sources, remove root folder +2) Do not add sysroots to sources, just add include directory (sysroots/elphel393/usr/include-uapi) - sysroot created with 'bitbake -c unpack' +3) run following steps - they will add sysroots to .cproject, together with the exclude filter +make clean # otherwise compiled files are preserved +bitbake apps-editconf -c cleansstate +bitbake apps-editconf -c unpack -f +bitbake apps-editconf -c configure -f +./used_files.py sysroots -1 +bitbake apps-editconf -c compile -f +./used_files.py sysroots 1473297567.42 # result of previous run +4)Add SCP to target in "builders" "new" "program". +5) remove "configuration builder' in 2 steps - remove it from .externalToolBuilders, run Eclipse again and then remove from builders. +6) copy .externalToolBuilders (just 1 entry), .project and .cproject to eclipse_project_setup +7) make sure .gitignore ignores all what it should + + + """ \ No newline at end of file -- 2.18.1