Is there a way to run shake assuming some rule is up-to-date? - shake-build-system

We would like to run a Shake build while assuming some target is built, e.g. something like
./Build.hs --dont-rebuild my-target
Reading the docs it seems there should be a way to do that but I can't find it.

The ShakeOptions setting you are looking for is shakeRebuild=[(RebuildLater,"my-target")]. This setting causes Shake to not rebuild my-target in this run. From the documentation of RebuildLater:
This assumption is unsafe, and may lead to incorrect build results in this run. Assume these files are clean in this run, but test them normally in future runs.
This setting can be applied using the command line --skip=my-target. A few caveats:
my-target won't rebuild in this run, by things it depends on might, if they need to.
If you next run without skipping my-target, it will rebuild if it needs to (the --skip is not sticky).

Related

Runing a makefile list of target with wait

I've a make file which runs several of targets , now I want to add new target that will run after some timeout, how can I do it ?
e.g.
execbin: build start run
This is running ok, however I want to add new target called test which will run after two seconds
(some timeout) , how can I do that ?
execbin: build start run test
test should execute after the run has finished and also wait 2 seconds before it start , is it possible ?
The lazy solution would be to add a new target called 'sleep-2', and a pattern rule do:
execbin: build start run sleep-2 test
sleep-%:
sleep $(#:sleep-%=%)
This creates a pattern rule that takes the value after the hyphen in a sleep-<> target, and uses it as the amount of time to sleep.
I will echo #MadScientists's answer that this probably will not work if you do make -j, which really does require changing the targets to depend on each other.
Adding more prerequisites to the list relies on make's behavior that it always tries to build prerequisites in order. While that is a documented requirement of POSIX, so it will always be true, it only works well if you don't use parallelism in your builds (you don't run with -j). If you do, then make can run all of those targets at the same time.
If you want to be sure that a given target does not start until another target finishes, the correct way to do it is declare a prerequisite relationship between them, not add them to the end of a different target's prerequisite list.
So, for example, if you want the test target to not start until the run target is complete, you should declare that:
test: run
run my tests
Now, test cannot be started until run is complete. The simplest way to introduce a sleep is just to put it into the recipe for test like this:
test: run
sleep 2
run my tests
If you want to be more fancy and use a separate target then you need to link the prerequisites, like this:
test: sleep-2
run my tests
sleep-2: run
sleep 2
Unless you have lots of these I think the simple way above is easier to understand.

Is it possible for Shake to change a source file?

When running tools such as formatters and linting tools with "auto-correction" options, it can be that the input and output for a Rule are the same file; for example:
"//*.hs" %> \out ->
cmd_ "ormolu" "-m" "inplace" out
-- OR
batch 10 ("//*.hs" %>)
( \out -> do
cmd_ "ormolu" "-m" "inplace" out
pure out
)
(cmd_ "hlint")
This seems to work "correctly" (the rule is re-run if the source file is needed and has changed), but we're unsure if this is a happy coincidence or shake working as designed - especially when we start thinking about cached results from shakeShare or in the future Cloud Shake. Is this the best way to handle this type of rule, or is there something better?
There is no principled way to generate a rule that replaces a source file in Shake. Given a source code formatter, anything else isn't very usfeul. Shake makes the assumption that inputs don't change while the compilation is ongoing. It's likely that passing --lint will lead to a lint error and that it would be incompatible with Cloud Shake. The official advice would be to make such changes in a separate non-Shake pass before you call shake.
However, if it works for you, and is useful, I wouldn't overly worry. The pattern has tests in Shake, it's something plenty of people do. You can turn off Cloud caching on a per file basis with historyDisable.

Syntastic C make checker not reporting errors

I'm writing C code and was initially using the gcc checker. Errors were reported in the C file. Lots of errors that didn't matter were being reported due to, for instance, no include directory switches on the gcc command line in the checker. Because we're using icc and it feels unwieldy to setup all of the parameters that are already setup in our makefile, I decided to switch over to using the make checker.
Upon switching to the make checker, I did not get any results. Looking at the makeprg command in make.vim, it is make -sk. I realized that our makefile was not setup to do syntax checking, so I created a new target called syntax_check that added the -fsyntax-only and -c flags. I then changed the make.vim makeprg command to make -sk clean syntax-check so that the appropriate target is run.
When I save the file I watched top in another window and saw that the build is occuring. However, I'm still getting no errors. By this, I mean I don't see the green sidebar indicating lines that did not have errors. Running :Errors does not bring up the location list.
Any ideas? And is my understanding of how to look at the generated errors in syntastic wrong (which it may very well be)?
As a side note for the question here, I've also got this question in on the Syntastic github page here.
It turns out that the errorformat was wrong for handling icc. This, of course, makes total sense.
The errorformat for icc that I've got so far is:
let errorformat = '%W%f(%l): %tarning #%n: %m,%E%f(%l): %trror: %m'
I will add more to this as I find errors that aren't covered by this format or find that I need different formatting.

Vim autocomplete from ctags for system headers only works when popup is triggered manually

On OS X, I generated a set of ctags for the system includes using the following command:
ctags -f c -h ".h" -R --c-kinds=+p --fields=+iaS --extra=+q /usr/include
This was run inside of a ~/.vim/ctags/ directory, where I put all of the ctags I generate for system-wide header files (I also have stuff for ROS and CPP that I load conditionally, but that's neither here nor there).
Anyway. The ctags file is set correctly in my .vimrc, and vim can definitely see the ctags, but for some reason the autocomplete popup will only display results from #included header files if I write out the entire symbol and then start backspacing. As an example, if I #include <string.h> in a project, and then I want to call strlen(), and I start to type str in to the active vim buffer, I will only get results for symbols that are currently in the vim buffer. But, if I type out strlen and then start backspacing one or two characters and hit <C-n>, the popup menu will be populated with matches from any other included header files.
EDIT: Turns out, if I just hit "s" then <C-n>, it works as well. So the problem seems to be that it only works if the popup menu is launched manually. Which makes me think that it's a plugin problem (see below)
Additional information:
completeopt is set to completeopt=menuone,menu,preview,longest
I have OmniCppComplete, which I suppose could be interfering with the behavior. It is currently not being conditionally loaded for C++ files only. If you want me to edit and post my OmniCppComplete settings from my .vimrc, just ask.
I also have AutoComplPop installed, but I haven't done anything to configure it, so it's running with its default settings. Haven't really researched the plugin, so no idea if some of it's behavior could be interfering with the results.
I have AutoTag and TagBar installed, but those should only be fiddling with the current directory's local tagfile.
I'm honestly pretty new to Vim, and I just have no idea where to start debugging this issue, whether it be with a random plugin or with my .vimrc settings.
Vim has many specific completion mechanisms.
<C-n> and <C-p> use many sources defined by the complete option. By default, they will provide completion using the current and all loaded and unloaded buffers, tags and included files. While you can usually get quite useful suggestions with these, it is a bit of a "catch-all" solution: it is not reliable at all if you work on reasonably large projects.
<C-x><C-]> uses only tags so it may be a little more useful to you.
And there are many more, see :h ins-completion.
Omni completion is smarter: it typically runs a custom filetype-specific script that tries hard to provide meaningful completion. It is triggered by <C-x><C-o> and you can read about it in :h ft-c-omni. Omni completion is often a better choice when working with code.
Because you have two overlaping "auto"-completion plugins it's hard to say what completion mechanism is at work. You should disable those plugins and play around with the different completion mechanisms available to you.
I have not mastered this yet, but I do think the following observation may be of help.
Vim's default auto complete which can be quite noisy, often gets in the way of what you call with <C-x><C-o>. Specifically, I found myself calling up my tags based completions with <C-x><C-o> only to have them replaced with continued typing with Vim's default suggestions using my open buffers.
The suggestion of shutting off one of the plugins makes sense. In my case the key was how to shut down Vim's default behavior. I have seen several people (and to which I now include myself), set the length of the expression to a high number before triggering Vim's default. For me that is:
let g:deoplete#auto_complete_start_length = 99
... this way you eliminate the default layer of completions that comes and goes regardless of the commands you intended to inform your work.
This still feels like a hack but it helps keep my work focused on the tag-based completions.
FYI: I use NVIM on a Mac.

Compiling Programs from Within Emacs?

What is the best way to compile programs inside emacs? I am currently opening a separate buffer with C-x 3 and running eshell inside it using M-x eshell then invoking either make or clang directly; most of the time I do have a Makefile set up.
Is there any advantage with running the compilation process using M-x compile vs running make inside eshell? Any other ways to do it and what are the advantages/disadvantages of those?
The easiest way to do this is to use the Emacs built-in compile command. M-x compile should do you fine. You can then edit the command that will be run (by default make -k) and then hit return to run the compilation. Emacs will then parse the output and if it finds any errors they will link to the source files so you can open them in a buffer.
Positives about it are:
Parsing of the output buffer
Memorisation of the compile command between invocations
Compilation output is shown in a non-selected buffer, you can quickly edit the file you were working on and fix any silly errors.
M-n and M-p scroll by error messages
Most of these features are provided by the compilation-minor-mode minor mode though not the actual compilation command and buffer. Once you have run a compilation command in eshell you could probably get similar results by setting the minor mode to compilation-minor-mode.
I personally prefer to run make or whatever command you're using to
compile within a multi-term
for the following reasons:
it works like M-xcompileRET if you activate
compilation-shell-minor-mode (M-p, C-`, …).
but you can, obviously, use other commands like
mkdir build
cd build
./configure --with-another-option
Of course you can do this from Emacs but I prefer the shell
interaction for this kind of stuff.
And imo, the main drawback of M-xcompile is that if
you're editing a file located in another directory than your
Makefile then you have to use M-xcompile in the correct
directory and then M-xrecompile. But if you want, say to
make clean && make, then you'll have to switch to the correct
directory, do it, switch back.
However term.el has its own drawback, it uses a non-portable hacky
way to track the current directory.

Resources