Bazel. Is there any way of running script under the same directory without `--run_under`? - bazel

Summary
I'd like to reduce the number of types when formatting.
Status quo
I am using Bazel to manage C++ project. Below is the simplified structure of the project.
❯ tree
.
├── bin
│ ├── BUILD.bazel
│ └── format.sh
├── README.md
├── src
└── WORKSPACE
Now, I'd like to format all files in src (off course, I have test in my real project) by bin/format.sh.
However, it really bothers me to type the long command below. Do you know how to make it easier?(If it is possible to change the command tobazel run bin:format, that's perfect.)
I think adding some codes in bin/BUILD.bazel would help, but I don't have any idea.
bazel run --run_under="cd $PWD &&" bin:format # format source codes
contents of files
sh_binary(
name = "format",
srcs = ["format.sh"],
)
#!/usr/bin/env sh
buildifier -r .
find . -iname *.h -o -iname *.cc | xargs clang-format -i -style=Google

I think what you are doing is fine. I would just define an alias as in
alias clang-fmt='bazel run --run_under="${PWD}" //bin:format'
You could also not use the --run_under option, and pass the directory to the program:
alias clang-fmt='bazel run //bin:format -- "${PWD}"'
and update the script
find $1 -iname *.h -o -iname *.cc | xargs clang-format -i -style=Google

Related

Clarify file/dir list to include in duply profile

I have defined /tmp/ as my source directory. I want to backup only in1/ and in2/ subfolders from it. What lines do I need in profile's exclude file?
/tmp/a
├── in1
│   └── in.txt
├── in2
│   └── in.txt
└── out.txt
According to duplicity man page's dir/foo example, I tried:
+ in1/
+ in2/
- **
But that did not work and I got error as:
Reading globbing filelist /path/to/duply_profile/exclude
Fatal Error: The file specification
in1/
cannot match any files in the base directory
/tmp
Useful file specifications begin with the base directory or some
pattern (such as '**') which matches the base directory.
better use up-to-date man page from duplicity's website https://duplicity.us/stable/duplicity.1.html#file-selection
not sure why the example relative paths is in there, but as the error states you will need something along the lines
+ /tmp/in1/
+ /tmp/in2/
- **
feel free to post a bug ticket on https://gitlab.com/duplicity/duplicity/-/issues so maybe someday some kind soul would make it work with relative paths.
I figured that the following specification work:
+ **in1/
+ **in2/
- **

Copying all the contents of an xcode program to one document

I have a project where I have to submit all the code comprising my program.
However, I am using xcode and an MVC architecture, so my code is split into different files/folders plus the storyboard itself.
I am wondering if there is anyway for me to see all the lines of code in one document so I can copy and paste my CR easily instead of going through each page and copying its content.
Try to run these commands in the working directory using terminal
find . -name "*.swift" -type f -exec cat {} + > "combined.swift"
If you just wanted to copy all of them
find . -name "*.swift" -type f -exec cat {} + | pbcopy

waf cross-project dependencies

I have a trivial waf project:
$ root
|-- a
| `-- wscript
|-- b
| `-- wscript
`-- wscript
Root wscript is
def configure(conf):
pass
def build(bld):
bld.recurse('a b')
a wscript is
def build(bld):
bld (rule = 'touch ${TGT}', target = 'a.target' )
b wscript is
def build(bld):
bld (rule = 'cp ${SRC} ${TGT}', source='a.target', target='b.target')
What I'm trying to achieve is have a build system that first touches a.target, then copies it to b.target. I want to have rules for a.target and b.target to stay in their respective wscript files.
When I'm trying to launch it, I get the following error instead:
source not found: 'a.target' in bld(target=['b.target'], idx=1, tg_idx_count=2, meths=['process_rule', 'process_source'], rule='cp ${SRC} ${TGT}', _name='b.target', source='a.target', path=/<skip>/waf_playground/b, posted=True, features=[]) in /<skip>/waf_playground/b
If I put both rules into a single wscript file, everything works like a charm.
Is there a way for a target to depend on a another target defined in other wscript?
When you specify source/target, that is expressed relative to the current wscript file.
$ waf configure build
...
source not found: 'a.target' in bld(source='a.target, ...)
...
$ tree build
build/
├── a
│ └── a.target
...
Knowing that, the fix is to refer to the a.target source file correctly in b/wscript:
def build(bld):
bld (rule = 'cp ${SRC} ${TGT}', source='../a/a.target', target='b.target')
The task now correctly finds the source file:
$ waf build
Waf: Entering directory `.../build'
[1/2] Creating build/a/a.target
[2/2] Compiling build/a/a.target
Waf: Leaving directory `.../build'
'build' finished successfully (0.055s)
$ tree build
build/
├── a
│   └── a.target
├── b
│   └── b.target
...

massaging packages that install files outside of nix-store

I'm using nix package-manager on macOS (Sierra).
My intention is to write a nix expression that will install the existing fish nix package along with the Bass fish plugin.
There are no existing expressions in nixpkgs for Bass, but the git repo contains a Makefile. This Makefile attempts to copy files to the $HOME dir. This is a problem as installing files outside of the nix-store is clearly not desirable and $HOME is not set when I build my package.
I can recognise why it's not desirable for nix packages to install files outside of the nix-store - in functional programming terms it's akin to a side-effect. But I'm also not clear on how to solve my problem:
By default Fish requires plugins such as Bass to be installed under $HOME/.config/fish/. Fish does provide a means to customise the config path by specifying the environment variable XDG_CONFIG_HOME. So I was thinking of doing something like this:
Create an expression for Bass patching the Makefile to install the files under $out.
Create an expression that installs fish and uses Bass as a build input. Use wrapProgram to set XDG_CONFIG_HOME pointing to the Bass install path in the nix-store.
Does this sound like the right approach? Are there alternative/better ways of solving this?
Thanks
This is the solution that I have gone with:
Expression for bass:
nix_local/pkgs/fish_plugins/bass/default.nix
{stdenv, fetchFromGitHub}:
let
version = "0.0.1";
in
stdenv.mkDerivation rec {
name = "bass-${version}";
src = fetchFromGitHub {
owner = "edc";
repo = "bass";
rev = "1fbf1b66f52026644818016015b8fa9e0f639364";
sha256 = "12bp8zipjbikasx20yz29ci3hikw0ksqlbxbvi2xgi4g6rmj7pxp";
};
patchPhase = ''
substituteInPlace Makefile --replace \
"~/.config/fish" \
$out/.config/fish
'';
}
Expression for fish_with_config:
nix_local/pkgs/fish_with_config/default.nix
{stdenv, fish, bass, makeWrapper}:
let
version = "0.0.1";
in
stdenv.mkDerivation rec {
name = "fish-with-config-${version}";
src = ./.;
buildInputs = [fish bass makeWrapper];
installPhase = ''
mkdir -p $out/.config/fish/functions
cp -r $src/.config/* $out/.config
cp -r ${bass}/.config/fish/functions/* \
$out/.config/fish/functions/
mkdir -p $out/bin
ln -s ${fish}/bin/fish $out/bin/fish
wrapProgram $out/bin/fish --set XDG_CONFIG_HOME "$out/.config"
'';
}
The Fish program is wrapped in order for it's config to be stored in the nix-store. This enables us to symlink the functions from Bass and also copy any additional config files from the local $src dir. Additional plugins could be symlinked in the same way.
The local src dir for the derivation contains the following files:
pkgs/fish_with_config
├── .config
│   └── fish
│   ├── fishd.8c8590486f8c
│   └── functions
└── default.nix
The .config/fish/fishd.8c8590486f8c file is a "universal variable file" which Fish requires in order to operate. In a standard Fish installation this file is stored under ~/config/fish/ and is created the first time you enter interactive mode. The contents of this file would typically change over time as users interact with Fish settings.
The fish_with_config derivation stores the Fish config in the nix-store, which means it can't be modified at a latter date (not writable). This means all the config settings need to be done upfront as any attempts by the user to modify the settings will result in permission errors - this is obviously a little inconvenient, but not a show stopper for me.
It's probably worth noting that the universal variable file may change with different releases of Fish and as such if I was to build fish_with_config with a newer version of Fish I would first determine it's default content by running fish in a nix-shell and inspecting the auto generated file under ~/config/fish/.
In summary the above works nicely, I have access to bass and any additional user defined functions I choose to "bake in" (pkgs/fish_with_config/.config/fish/functions).
If you see anything that could be improved or handled more idiomatically let me know.

script for finding all UI elements in code

I have a script line find . -name \*.m | xargs genstrings -o en.lproj -o base.lproj
to find all localized strings in the code text.
Is it possible to write a script to find all :UI elements
and write them to a file?

Resources