Tell ocamlbuild where to find module - linker

I have an OCaml project, for which I use ocamlbuild.
In this project, I have two subprojects, subproject1 and subproject2.
subproject2 needs to use a module called Module from subproject1.
To sum up, I have the following structure:
project/
|
|-- subproject1
| |
| |-- module.ml
|
|-- subproject2
|
|-- main.ml
If module.ml were located in subproject2, next to main.ml, I'd simply use the open directive in subproject2/main.ml:
(*subproject2/main.ml *)
open Module
But since module.ml is located in subproject1, how can I tell ocamlbuild to open subproject1/module.ml?

While I haven't found any straightforward way to include or directly link a source file, I've come up with a way to effectively include a module from a sibling directory.
Once again, here is the structure of the project:
project/
|
|-- subproject1
| |
| |-- module.ml
|
|-- subproject2
|
|-- main.ml
From the project directory, the following ocamlbuild command will compile the whole project, with subproject2/main.ml as target, and subproject2/_build/ as output build directory:
ocamlbuild -I subproject1 subproject2/_build/ subproject2/main.byte
The expected main.byte file will however be output as subproject2/_build/subproject2/main.byte, so manual link editing will be necessary to end up with the usual main.byte symlink in subproject2.
Since I like being able to use make, I wrote the following Makefile in subproject2/, so as to compile subproject2/ by simply running make from the inside, as make is supposed to work.
all:
# Move to project/
cd ..;\
# Run the ocamlbuild command
ocamlbuild -I subproject1 subproject2/_build/ subproject2/main.byte\
# Go back into subproject2
cd subproject2;\
# Try to remove the existing symlink, mute stderr, and continue on error
rm main.byte 2> /dev/null || true;\
# Create the desired symlink
ln -s _build/subproject2/main.byte main.byte

Related

How to move (mv) file by file starting from the last on macOS

I would like to move file by file from one folder to another starting with the last file and so on until there are no more files in the source folder.
I already managed to find and isolate the last file in the source folder with find and move to directory folder with mv:
find ~/Music/Music -not -path '*/\.*' -type f | gtac | head-1 | xargs -I '{}' mv {} ~/Music/iTunes/iTunes\ Media/Automatically\ Add\ to\ Music.localized
Is it also possible to add a rest time between the different mv?
Thank you in advance for your answers

How do I checkout then copy to all files at the destination of a symlink at once?

Background
I am following some instructions from a teammate. These instructions include a command to checkout, then copy .a files from a make command from one vob to another. The commands were given to me as such:
ct co -nc -unr /vobs/sbov/ABC/libs/qwert/*.a
find . -name '*.a' | grep -v ABCDE | xargs -I {} cp {} /vobs/sbov/ABC/libs/quert
This should have no problem working normally...except recently numerous .a files in that directory have changed from files to symlinks. Symlinks are not clearcase elements. Therefore, the commands attempted to checkout, then copy to, various non-clearcase entities as opposed to the actual files. Hence my question...
Question
How do I modify the commands above to manipulate the actual files the symlinks point to, as opposed to the symlinks themselves?
Try first a cp with a de reference option
find . -name '*.a' | grep -v ABCDE | xargs -I {} cp -L {} /vobs/sbov/ABC/libs/quert
^^^^^^^^
That should help getting actual files instead of symlinks.

NPM/React: copyfiles not running correctly

Django 2.0,
Node.js 8.11.4
I have a djanog project of the format:
reactify/
└── src/
├── reactify-ui/
| ├── build/
| | └── static/
| | └── js/
| | └── main.3425.js
| └── package.json
└── staticfiles/
└── js/
└── reactify-django-us.js
I want to replace the content of \reactify\src\staticfiles\js with what is in \reactify\src\reactify-ui\build\static\js\*
My packages.json looks like this
"scripts": {
...
"copy-build-js": "copyfiles -f 'build/static/js/*.js' '../staticfiles/js/'",,
...
}
When I run npm copy-build-js I get the following output:
> reactify-ui#0.1.0 copy-build-js C:\Users\Owner\dev\reactifydjango\src\reactify-ui
> copyfiles -f 'build/static/js/*.js' '../staticfiles/js/'
It looks like it works, but when I inspect the file in the target location ../staticfiles/js/, it hasn't changed.
I validate it by
changing the file before I run the command,
do an `ls -lrth` to get the timetamp,
wait a minute so the timestamp changes,
run the command `npm copy-build-js`,
and then doing an `ls -lrth` on the target location and seeing that the timestamp isn't post hasn't changed.
I also look at the file and it is the same.
Why would the copyfiles not work?
You have the structure correct, but the copyfiles package has some quirks that you missed. Use this as your script:
"copy-build-js": "del /F \"../staticfiles/js\" && copyfiles -E -f \"./build/static/js/*.js\" ../staticfiles/js"
The double quotes here are required, so you need black slashes before each to escape them.
The copyfiles package does not have an option to replace all files in a directory even if the filenames don't exist, so first you have to run del /F \"../staticfiles/js\" to delete all files in the src/staticfiles/js directory. This command assumes you're on Windows.
Then you run copyfiles -E -f \"./build/static/js/*.js\" ../staticfiles/js. What you missed was that when using wildcards/globs with this package (*), you have to double quote the location. If a location doesn't have a wildcard in it, you don't need quotes at all. I added in the -E flag that will throw an error if files aren't copied, which could potentially save you trouble later on.

change folder modified date based on most recent file modified date in folder

I have a number of project folders that all got their date modified set to the current date & time somehow, despite not having touched anything in the folders. I'm looking for a way to use either a batch applet or some other utility that will allow me to drop a folder/folders on it and have their date modified set to the date modified of the most recently modified file in the folder. Can anyone please tell me how I can do this?
In case it matters, I'm on OS X Mavericks 10.9.5. Thanks!
If you start a Terminal, and use stat you can get the modification times of all the files and their corresponding names, separated by a colon as follows:
stat -f "%m:%N" *
Sample Output
1476985161:1.png
1476985168:2.png
1476985178:3.png
1476985188:4.png
...
1476728459:Alpha.png
1476728459:AlphaEdges.png
You can now sort that and take the first line, and remove the timestamp so you have the name of the newest file:
stat -f "%m:%N" *png | sort -rn | head -1 | cut -f2 -d:
Sample Output
result.png
Now, you can put that in a variable, and use touch to set the modification times of all the other files to match its modification time:
newest=$(stat -f "%m:%N" *png | sort -rn | head -1 | cut -f2 -d:)
touch -r "$newest" *
So, if you wanted to be able to do that for any given directory name, you could make a little script in your HOME directory called setMod like this:
#!/bin/bash
# Check that exactly one parameter has been specified - the directory
if [ $# -eq 1 ]; then
# Go to that directory or give up and die
cd "$1" || exit 1
# Get name of newest file
newest=$(stat -f "%m:%N" * | sort -rn | head -1 | cut -f2 -d:)
# Set modification times of all other files to match
touch -r "$newest" *
fi
Then make that executable, just necessary one time, with:
chmod +x $HOME/setMod
Now, you can set the modification times of all files in /tmp/freddyFrog like this:
$HOME/setMod /tmp/freddyFrog
Or, if you prefer, you can call that from Applescript with a:
do shell script "$HOME/setMod " & nameOfDirectory
The nameOfDirectory will need to look Unix-y (like /Users/mark/tmp) rather than Apple-y (like Macintosh HD:Users:mark:tmp).

Cmake - Want to see intermediate .i files

I want to know how to make Cmake give me a target that will allow me to save the .i files from my C program with the macro expansion, etc completed.
Will I need to make a custom target to do this?
If your are using the Makefile generator, then there are already targets for .i files. Type make help, and you will see all the targets, including those suffixed by .i, .s, and .o.
If you don't want to manually run the make targets and filter for .i extensions, you could do it like this:
for subdir in */
do
(cd $subdir && make $(make help |& grep \\.i$ | cut -c4-))
done
Alternatively, I sometimes used compile_command.json with npm's command line tool for json:
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON # ...
json < compile_commands.json -ga "command" | sed 's/.cpp.o -c/.cpp.ii -E/' | sh -
Note however that there might be edge cases (like target directories that have not been created yet).

Resources