gitignore pattern to include all directories with a specific sub directory - c++

I am trying to setup a .gitignore file for openFrameworks. I have a folder that contain project folders - each one has a src directory. I would like to include the folder itself and the src directory only for every project.
Here is my current .gitignore file
# ignore these files
# ignoring everything except spec items
*
# allow these files
!.gitignore
!/README.md
!/*/src
Any help would be greatly appreciated. Ideally I would like the committed folder structure to look something like this:
.
├── project_1
│   └── src
│   └── file.cpp
├── project_2
│   └── src
│   └── file.cpp
└── project_3
└── src
└── file.cpp
What am I missing? Thank you.

If you ignore files and folders (with '*'), you won't be able to exclude sub-folders.
The rule to remember remains:
It is not possible to re-include a file if a parent directory of that file is excluded.
Try instead ignoring files only.
**
Then you can exclude subfolders like src:
!.gitignore
!/README.md
!src/
# or, to be more specific
!/*/src
For any element that would be still ignored, check what rule is involved with:
git check-ignore -v -- an/ignored/element

Related

How do I import a package from the local filesystem using dub?

I have a project that uses dub. I want to use an external file vendored into my project, as a dependency. How do I do this? I don't want to have it in my project's source/ dir. I don't want to add it as a dub managed dependency, but I do want to be able to just import xxx.
The package is this one: https://github.com/gianm/d-json , it does not use dub or have a dub.json project file.
Alternative thing: make a third_party directory, put the file in there, then add that to the sourcePaths in your dub config (you'll probably specify both ["third_party", "source"] since the default source will be overridden if you don't list it too.
Convert the package to dub by adding a dub.json file in the root, with the following contents: {"name": "jsonx"}. Create a source folder, and move jsonx.d into it.
Put the folder anywhere you want, e.g. top-level next to your own project.
Add the following dependency to your dub.json:
"dependencies": {
...
"jsonx": {"path": "../jsonx/"}
}
You can now import the package anywhere using import jsonx;.
In conclusion, if your app is in a dir called app, your tree should look like this:
.
├── app
│   ├── dub.json
│   └── source
│      └── myapp.d
└── jsonx
├── dub.json
└── source
└── jsonx.d

Reason to add empty source file to a STATIC library?

I've seen this quite a lot in C++, that developers add an empty source file to the library in CMake. One example is here, with the empty source file found here.
The CMake file has this line:
# build the library
add_library(${PROJECT_NAME} STATIC src/dependency-tracker.cc)
This is only the case if there are no other source files in the src folder, so the library would be 'header only'. Why do they do this?
The directory structure i was referring to:
.
├── CMakeLists.txt
├── include
│   └── okvis
│   └── kinematics
│   ├── implementation
│   │   └── Transformation.hpp <- header only implementation
│   ├── operators.hpp
│   └── Transformation.hpp
├── src
│   └── dependency-tracker.cc <- empty source file
└── test
├── runTests.cpp
└── TestTransformation.cpp
The project specifies CMake 2.8.11 as a minimal requirement:
cmake_minimum_required(VERSION 2.8.11)
This version lacks for INTERFACE library type, which nowadays is a standard representation of a header-only library. (Support for INTERFACE libraries firstly appeared in CMake 3.0).
Without INTERFACE library available, a normal library with a single empty source file looks like a good alternative.
I don't know why dependency-tracker.cc name choosen for the empty source file. Probably, this name has some special meaning for the project's developers.

Sublime Linter with clang can't find header file in header

I'm using sublime text with the sublime linter plugin especially with clang.
When I open a folder, it use the root of the folder as a header location, so if I have
src
├── World
│   ├── Chunk.cpp
│   ├── Chunk.hpp
│   ├── World.cpp
│   └── World.hpp
└── main.cpp
In World.cpp I need to include "World/World.hpp".
But if in World.hpp I include Chunk.hpp the same way ("World/Chunk.hpp"), I get an error but
in World.hpp I have no error. Error are only in file I include that include other file.
I had the same issue. You need to tell clang where to look for the files, i.e. which directories you want to include. Go Preferences --> Package Settings --> SublimeLinter --> Settings and add a new section for clang++:
// SublimeLinter Settings - User
{
"linters":
{
"clang++": {
"I" : [
"${folder}/src",
"${file_path}",
]
}
}
}
In your case the two include directories will actually point to the same path but in general, the first version is to include your source directory (e.g. you have a unit test from a different folder open which accesses code from you src directory) and the second line includes the location of your current file.
If you need different directories, find some more variables you can use here.

How to ignore the parent "src" directory when transpiling using Babel watcher

My code has the directory structure:
project-root/
└── src/
└── main.js
When I run the default Babel file watcher, the code is transpiled into a dist folder, including the src directory in it's path, like so:
project-root/
└── src/
├── main.js
dist/
└── src
└── main.dist.js
What I want instead is for the src to be excluded from the path - in other words, for the transpiled code in src to be "unwrapped" and compiled straight into dist, like the following:
project-root/
└── src/
├── main.js
dist/
└── main.dist.js
Is it be possible to change the watcher config to achieve this? I can't figure it out! Any help is much appreciated.
it's the --out-dir Babel CLI option behavior - it recreates the source folder structure (relative to working dir) in the destination directory.
You have 2 options here:
use --out-file instead
set src as your working directory
Possible setup for the first option:
Arguments: $FilePathRelativeToProjectRoot$ --out-file dist/$FileNameWithoutExtension$.js --source-maps --presets env
Output paths to refresh: dist\$FileNameWithoutExtension$.js:dist\$FileNameWithoutExtension$.js.map
For the second:
Arguments: $FileDirPathFromParent(src)$$FileName$ --out-dir $ProjectFileDir$/dist --source-maps --presets env
Output paths to refresh: $ProjectFileDir$/dist/$FileDirPathFromParent(src)$FileNameWithoutExtension$.js:$ProjectFileDir$/dist/$FileDirPathFromParent(src)$FileNameWithoutExtension$.js.map
Working directory: $ContentRoot$\src

searching for tags in current directory only

If I have the following structure
.
├── main-one
│   ├── main.cpp
│   └── tags
├── main-two
│   ├── main.cpp
│   └── tags
└── tags
2 directories, 5 files
and I am in main.cpp in the main-one folder, suppose I want to search for the tag print, and two of them exist, one in each main.cpp file. How can I specify a maximum depth level of 1 to the :ta print function so that it only searches in the current working directory? Maybe an interactive tag search?
I ask this because I am trying to use ctags on a larger project and I would like the ability to search for common things like main without getting hundreds of results
You can't. :tag foo will jump to the first foo in your tags file, no matter where it is (and where you are) in your project.
Use :help :tselect instead.
lh-tags permits to filter tags results. I haven't implement a filter on the current directory, but it should be possible I guess.