For Gazelle, how can I drop src from the generated importpath? - go

Because of the GoPath convention, I have all the code under src directory in my repo. Hence, the generated BUILD.bazel files have src appended to the importpaths. But imports to the go code from within the repo need to not have src in them. Hence, I have to update the generated importpath each time I add a new go directory.
I believe the support for go-prefix is on its way out. So I don't want to use that.
I can always update the importpath and add a #keep at the end to prevent subsequent updates. But, I was wondering if there was a way of controlling the generated importpath.

You can set the import path prefix in a subtree by adding a comment like this (replacing example.com/repo with whatever you want) to the build file in that subtree:
# gazelle:prefix example.com/repo
In your repo, you can set an empty prefix in the src directory. So in src/BUILD.bazel, add this comment:
# gazelle:prefix

Related

clang:how can fdebug-prefix-map use new path relative to user home path `~`?

I try rewrite the source file path to ~/src/lib by using fdebug-prefix-map.
I can confirm DW_AT_decl_file is rewritten to something like ~/src/lib/path.
But the result is lldb can't find the source file. If I change to a absolute path, it works fine.
How can I solve this?
You can use the target.source-map setting to remap location of source files. From (lldb) apropos source-map:
Source path remappings are used to track the change of location between a source file when built, and where it exists on the current system. It consists of an array of duples, the first element of each duple is some part (starting at the root) of the path to the file when it was built, and the second is where the remainder of the original build hierarchy is rooted on the local system. Each element of the array is checked in order and the first one that results in a match wins.
The usage looks something like:
(lldb) settings append target.source-map /foo /bar
Note that you use append here instead of set, because otherwise you'd overwrite the mapping every time you add an entry. You can check the mapping with:
(lldb) settings show target.source-map

Failing to open a file which should be in the base path

I have a Go project (bazel-remote) that tries to read a yaml file passed in the command line, when built with bazel. This yaml file sits in the same location from where I run the bazel run command.
But it fails to run because os.Open fails with no such file or directory.
I printed the basePath using os.Getwd, because someone suggested that my basePath might be set wrong. But my basePath is set to a location in my /private/var/tmp/ where the bazel objects are created and stored:
/private/var/tmp/bazel/312feba8ddcde6737ae7dd7ef9bc2a5a/execroot/main/bazel-out/darwin-fastbuild/bin/darwin_amd64_static_pure_stripped/bazel-remote.runfiles/main'
How do I set my basePath correctly? Why is my basePath set to where it is?
Binaries started with bazel run are executed in an internal Bazel directory. They'll have access to "runfiles", which are files mentioned in the data attribute of the binary rule or its dependencies. For example, if you have a rule like the one below, you'll be able to read foo.txt, but not bar.txt or other files:
load("#io_bazel_rules_go//go:def.bzl", "go_binary")
go_binary(
name = "hello",
srcs = ["hello.go"],
data = ["foo.txt"],
)
Note that the working directory of the binary corresponds to the repository root directory, not the directory where the binary is defined. You can debug with os.Getwd and filepath.Walk.
You mentioned you wanted to access a yaml file passed in on the command line though. Presumably, you want to be able to access any file the user passes in, not just files mentioned in the data attribute. For this case, take a look at the BUILD_WORKING_DIRECTORY environment variable (bazel run sets this). That gives the path to the directory where bazel run was invoked. Also, BUILD_WORKSPACE_DIRECTORY is the path to the workspace root directory.

Create a directory structure from a path in gradle/groovy

I am implementing a diff package generation task in my project's gradle build from the git command line output. Currently I have a method which will give me a list of changed files from git diff --name-only. What I would like to do is create a directory structure in a new directory which matches the paths of each file. For example: inputting the string repo/dir/file.java would create in an output directory if not already created and inside it the directories head/repo/dir with the current file.java and prev/repo/dir with the previous file.java.
My current plan is to split the string repo/dir/file.java on the forward slash, and create directories until the last element of the split result, then write the file there. but nothing I have been able to come up with in gradle is nice or clean. I am wondering if there is a nicer way to create directories from a string like that.
My current plan is to split the string repo/dir/file.java on the forward slash, and create directories until the last element of the split result
Rather than splitting your string manually, you could try using File.mkdirs():
File newDirectoryStructureParent = new File('some/path/to/parent/dir')
def s = 'repo/dir/file.java'
def newContainer = new File(s, newDirectoryStructureParent).getParent()
newContainer.mkdirs()
everyone
In this part of my code you can just work around Path not File!
At the first you can define Path and second need check that path exist or not, if not mkdirs can make it ;)
Its help when you unknown about that path exist or not /
File fullPath = new File('/tmp/Test1')
if (!fullPath.exists())
fullPath.mkdirs()

How to include a directory of files with RST and Sphinx

I am trying to write documentation and want and have multiply files used by multiple toc trees. Previously I used an empty file with .. include:: <isonum.txt> however, this does not work for multiply files in a directory with sub directories. Another solution I have used was to use a relative file path to the index file I am linking to. However this messes up the sphinx nav tree. So my question is how to include a directory of files with RST and Sphinx?
It can't be done, unfortunately.
The toctree directive has a glob option, which you would use like so:
.. toctree::
:glob:
generated/*
But this option is not available in the include directive.
Maybe start an issue for it?
Perhaps indicate the start and end of the section where the files should go with a comment (.. START_GLOB_INCLUDE etc), and then have a build pre-process step that finds the files you want and rewrites that section of the master file.

Include path in makefile to include subdirectories

I have a directory which internal contains sub directories. I want to include the parent directory as include path in make file for header files. Is there a syntax so that all the sub directories are searched for the header files.
[EDIT] Posting the question in more detail
There are three sub folders in a parent folder
parentFolder/child1
parentFolder/child2
parentFolder/child3
There are header files in each all subfolders
Using -I option in makefile for header file path, i have to use
HEADER_PATH += -I./parentFolder
HEADER_PATH += -I./parentFolder/child1
HEADER_PATH += -I./parentFolder/child2
HEADER_PATH += -I./parentFolder/child3
Is there any way I can mention only the parent folder , but the search for header files will happen in all the subfolders also
http://www.gnu.org/software/make/manual/html_node/Recursion.html
Setup variable in first makefile and export it for sub-dirs. If you want to be able to invoke make in subdirs manually - i suppose best way to achieve this is either using configure-like systems to generate paths for you, or setting global variable (e.g. YOURPROJECT_DIR) in .profile or .bashrc and using it in makefiles.
I would like to see better solutions since i've encountered quite the same problem some time ago.

Resources