Linux-Sparse Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v1] sindex: allow indexing outside the project tree
@ 2020-07-30 13:20 Alexey Gladkov
  2020-07-30 15:22 ` Oleg Nesterov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alexey Gladkov @ 2020-07-30 13:20 UTC (permalink / raw)
  To: linux-sparse; +Cc: Eric W. Biederman, Oleg Nesterov, Luc Van Oostenryck

One possible way to compile the linux kernel is by using the O=<DIR>
parameter to place all generated files outside the source tree.

Prior to this patch, sindex filters processed sources to exclude system
files. The base directory of the project was the current directory.

When compiled outside of the source tree, this may not be the case.
This patch adds a parameter and an environment variable to specify
the source tree.

You can use it like this:

$ make O=$PWD-build C=2 CHECK="sindex -B $PWD add --"

This parameter is also needed for searching if you want to display
the source code line because sindex does not store lines in the database
but reads them from source files.

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
---
 sindex.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/sindex.c b/sindex.c
index 22836a95..bff6d8c4 100644
--- a/sindex.c
+++ b/sindex.c
@@ -101,11 +101,13 @@ static void show_help(int ret)
 	    "\n"
 	    "Options:\n"
 	    "  -D, --database=FILE    Specify database file (default: %2$s);\n"
+	    "  -B, --basedir=DIR      Define project top directory (default is the current directory);\n"
 	    "  -v, --verbose          Show information about what is being done;\n"
 	    "  -h, --help             Show this text and exit.\n"
 	    "\n"
 	    "Environment:\n"
 	    "  SINDEX_DATABASE        Database file location.\n"
+	    "  SINDEX_BASEDIR         Project top directory.\n"
 	    "\n"
 	    "Report bugs to authors.\n"
 	    "\n",
@@ -125,9 +127,6 @@ static void show_help_add(int ret)
 	    "  -v, --verbose          Show information about what is being done;\n"
 	    "  -h, --help             Show this text and exit.\n"
 	    "\n"
-	    "Environment:\n"
-	    "  SINDEX_BASEDIRE        Project top directory.\n"
-	    "\n"
 	    "Report bugs to authors.\n"
 	    "\n",
 	    progname);
@@ -251,21 +250,26 @@ static void parse_cmdline(int argc, char **argv)
 {
 	static const struct option long_options[] = {
 		{ "database", required_argument, NULL, 'D' },
+		{ "basedir", required_argument, NULL, 'B' },
 		{ "verbose", no_argument, NULL, 'v' },
 		{ "help", no_argument, NULL, 'h' },
 		{ NULL }
 	};
 	int c;
+	char *basedir = getenv("SINDEX_BASEDIR");
 	char *env;
 
 	if ((env = getenv("SINDEX_DATABASE")) != NULL)
 		sindex_dbfile = env;
 
-	while ((c = getopt_long(argc, argv, "+D:vh", long_options, NULL)) != -1) {
+	while ((c = getopt_long(argc, argv, "+B:D:vh", long_options, NULL)) != -1) {
 		switch (c) {
 			case 'D':
 				sindex_dbfile = optarg;
 				break;
+			case 'B':
+				basedir = optarg;
+				break;
 			case 'v':
 				sindex_verbose++;
 				break;
@@ -278,6 +282,12 @@ static void parse_cmdline(int argc, char **argv)
 		message("command required");
 		show_usage();
 	}
+
+	if (basedir) {
+		if (!realpath(basedir, cwd))
+			sindex_error(1, errno, "unable to get project base directory");
+		n_cwd = strlen(cwd);
+	}
 }
 
 static void parse_cmdline_add(int argc, char **argv)
@@ -1016,6 +1026,9 @@ static void command_search(int argc, char **argv)
 	char *dberr = NULL;
 	sqlite3_str *query = sqlite3_str_new(sindex_db);
 
+	if (chdir(cwd) < 0)
+		sindex_error(1, errno, "unable to change directory: %s", cwd);
+
 	if (query_appendf(query,
 	                  "SELECT"
 	                  " file.name,"
-- 
2.25.4


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] sindex: allow indexing outside the project tree
  2020-07-30 13:20 [PATCH v1] sindex: allow indexing outside the project tree Alexey Gladkov
@ 2020-07-30 15:22 ` Oleg Nesterov
  2020-07-30 20:06 ` Luc Van Oostenryck
  2020-07-30 21:02 ` Eric W. Biederman
  2 siblings, 0 replies; 4+ messages in thread
From: Oleg Nesterov @ 2020-07-30 15:22 UTC (permalink / raw)
  To: Alexey Gladkov; +Cc: linux-sparse, Eric W. Biederman, Luc Van Oostenryck

On 07/30, Alexey Gladkov wrote:
>
> One possible way to compile the linux kernel is by using the O=<DIR>
> parameter to place all generated files outside the source tree.
>
> Prior to this patch, sindex filters processed sources to exclude system
> files. The base directory of the project was the current directory.
>
> When compiled outside of the source tree, this may not be the case.
> This patch adds a parameter and an environment variable to specify
> the source tree.
>
> You can use it like this:
>
> $ make O=$PWD-build C=2 CHECK="sindex -B $PWD add --"
>
> This parameter is also needed for searching if you want to display
> the source code line because sindex does not store lines in the database
> but reads them from source files.

Thanks, looks good to me.

Oleg.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] sindex: allow indexing outside the project tree
  2020-07-30 13:20 [PATCH v1] sindex: allow indexing outside the project tree Alexey Gladkov
  2020-07-30 15:22 ` Oleg Nesterov
@ 2020-07-30 20:06 ` Luc Van Oostenryck
  2020-07-30 21:02 ` Eric W. Biederman
  2 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2020-07-30 20:06 UTC (permalink / raw)
  To: Alexey Gladkov; +Cc: linux-sparse, Eric W. Biederman, Oleg Nesterov

On Thu, Jul 30, 2020 at 03:20:33PM +0200, Alexey Gladkov wrote:
> One possible way to compile the linux kernel is by using the O=<DIR>
> parameter to place all generated files outside the source tree.
> 
> Prior to this patch, sindex filters processed sources to exclude system
> files. The base directory of the project was the current directory.
> 
> When compiled outside of the source tree, this may not be the case.
> This patch adds a parameter and an environment variable to specify
> the source tree.
> 
> You can use it like this:
> 
> $ make O=$PWD-build C=2 CHECK="sindex -B $PWD add --"
> 
> This parameter is also needed for searching if you want to display
> the source code line because sindex does not store lines in the database
> but reads them from source files.

Thanks. Applied & pushed.

-- Luc 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] sindex: allow indexing outside the project tree
  2020-07-30 13:20 [PATCH v1] sindex: allow indexing outside the project tree Alexey Gladkov
  2020-07-30 15:22 ` Oleg Nesterov
  2020-07-30 20:06 ` Luc Van Oostenryck
@ 2020-07-30 21:02 ` Eric W. Biederman
  2 siblings, 0 replies; 4+ messages in thread
From: Eric W. Biederman @ 2020-07-30 21:02 UTC (permalink / raw)
  To: Alexey Gladkov; +Cc: linux-sparse, Oleg Nesterov, Luc Van Oostenryck

Alexey Gladkov <gladkov.alexey@gmail.com> writes:

> One possible way to compile the linux kernel is by using the O=<DIR>
> parameter to place all generated files outside the source tree.
>
> Prior to this patch, sindex filters processed sources to exclude system
> files. The base directory of the project was the current directory.
>
> When compiled outside of the source tree, this may not be the case.
> This patch adds a parameter and an environment variable to specify
> the source tree.
>
> You can use it like this:
>
> $ make O=$PWD-build C=2 CHECK="sindex -B $PWD add --"
>
> This parameter is also needed for searching if you want to display
> the source code line because sindex does not store lines in the database
> but reads them from source files.

Tested-by: "Eric W. Biederman" <ebiederm@xmission.com>

This simple little example search now works for me:

sindex --database=$PWD-build/sindex.sqlite search -m w task_struct.pid 

> Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
> ---
>  sindex.c | 21 +++++++++++++++++----
>  1 file changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/sindex.c b/sindex.c
> index 22836a95..bff6d8c4 100644
> --- a/sindex.c
> +++ b/sindex.c
> @@ -101,11 +101,13 @@ static void show_help(int ret)
>  	    "\n"
>  	    "Options:\n"
>  	    "  -D, --database=FILE    Specify database file (default: %2$s);\n"
> +	    "  -B, --basedir=DIR      Define project top directory (default is the current directory);\n"
>  	    "  -v, --verbose          Show information about what is being done;\n"
>  	    "  -h, --help             Show this text and exit.\n"
>  	    "\n"
>  	    "Environment:\n"
>  	    "  SINDEX_DATABASE        Database file location.\n"
> +	    "  SINDEX_BASEDIR         Project top directory.\n"
>  	    "\n"
>  	    "Report bugs to authors.\n"
>  	    "\n",
> @@ -125,9 +127,6 @@ static void show_help_add(int ret)
>  	    "  -v, --verbose          Show information about what is being done;\n"
>  	    "  -h, --help             Show this text and exit.\n"
>  	    "\n"
> -	    "Environment:\n"
> -	    "  SINDEX_BASEDIRE        Project top directory.\n"
> -	    "\n"
>  	    "Report bugs to authors.\n"
>  	    "\n",
>  	    progname);
> @@ -251,21 +250,26 @@ static void parse_cmdline(int argc, char **argv)
>  {
>  	static const struct option long_options[] = {
>  		{ "database", required_argument, NULL, 'D' },
> +		{ "basedir", required_argument, NULL, 'B' },
>  		{ "verbose", no_argument, NULL, 'v' },
>  		{ "help", no_argument, NULL, 'h' },
>  		{ NULL }
>  	};
>  	int c;
> +	char *basedir = getenv("SINDEX_BASEDIR");
>  	char *env;
>  
>  	if ((env = getenv("SINDEX_DATABASE")) != NULL)
>  		sindex_dbfile = env;
>  
> -	while ((c = getopt_long(argc, argv, "+D:vh", long_options, NULL)) != -1) {
> +	while ((c = getopt_long(argc, argv, "+B:D:vh", long_options, NULL)) != -1) {
>  		switch (c) {
>  			case 'D':
>  				sindex_dbfile = optarg;
>  				break;
> +			case 'B':
> +				basedir = optarg;
> +				break;
>  			case 'v':
>  				sindex_verbose++;
>  				break;
> @@ -278,6 +282,12 @@ static void parse_cmdline(int argc, char **argv)
>  		message("command required");
>  		show_usage();
>  	}
> +
> +	if (basedir) {
> +		if (!realpath(basedir, cwd))
> +			sindex_error(1, errno, "unable to get project base directory");
> +		n_cwd = strlen(cwd);
> +	}
>  }
>  
>  static void parse_cmdline_add(int argc, char **argv)
> @@ -1016,6 +1026,9 @@ static void command_search(int argc, char **argv)
>  	char *dberr = NULL;
>  	sqlite3_str *query = sqlite3_str_new(sindex_db);
>  
> +	if (chdir(cwd) < 0)
> +		sindex_error(1, errno, "unable to change directory: %s", cwd);
> +
>  	if (query_appendf(query,
>  	                  "SELECT"
>  	                  " file.name,"

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-30 13:20 [PATCH v1] sindex: allow indexing outside the project tree Alexey Gladkov
2020-07-30 15:22 ` Oleg Nesterov
2020-07-30 20:06 ` Luc Van Oostenryck
2020-07-30 21:02 ` Eric W. Biederman

Linux-Sparse Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-sparse/0 linux-sparse/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-sparse linux-sparse/ https://lore.kernel.org/linux-sparse \
		linux-sparse@vger.kernel.org
	public-inbox-index linux-sparse

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-sparse


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git