@@ -4,11 +4,12 @@ cd "$(dirname "${BASH_SOURCE[0]}")"
44
55# Script arguments with their default values
66repository=https://github.com/ocaml-flambda/flambda-backend
7- subdirectory=ocaml
7+ subdirectory=.
8+ old_subdirectory=.
89
910function usage () {
1011 cat << USAGE
11- Usage: $0 COMMITISH [REPO [SUBDIRECTORY]]
12+ Usage: $0 COMMITISH [REPO [SUBDIRECTORY [OLD_SUBDIRECTORY] ]]
1213
1314Fetch the new compiler sources and patch Merlin to keep Merlin's local copies of
1415things in sync. By default, this will pull the COMMITISH branch from
@@ -22,6 +23,12 @@ This attempts to import new files from the compiler by running the
2223try making matched pairs of files in this repository with the right names: one
2324in "upstream/ocaml_flambda/", and one in "src/ocaml". Then running the script
2425will pull in the named file(s).
26+
27+ The SUBDIRECTORY argument is useful when importing from a repository that buries
28+ the relevant compiler files inside a subdirectory. This used to be the case for
29+ flambda (files were under an "ocaml/" direcotry), although it is no longer the
30+ case. The OLD_SUBDIRECTORY argument is useful for when the directory structure
31+ has changed since the last import.
2532USAGE
2633}
2734
4754 exit 1
4855fi
4956
50- if [[ $# -le 3 ]]; then
57+ if [[ $# -le 4 ]]; then
5158 repository=" ${2-$repository } "
59+ # Although the subdirectory arguments are probably no longer useful, it doesn't hurt
60+ # to keep them around in case they ever are of use.
5261 subdirectory=" ${3-$subdirectory } "
62+ old_subdirectory=" ${4-$old_subdirectory } "
5363else
5464 usage >&2
5565 exit 1
@@ -68,7 +78,7 @@ old_base_rev="$(cat upstream/ocaml_flambda/base-rev.txt)"
6878current_head=" $( git symbolic-ref --short HEAD) "
6979
7080# First, add any files that have been added since the last import.
71- ./import-added-ocaml-source-files.sh " $commitish " " $repository " " $subdirectory "
81+ ./import-added-ocaml-source-files.sh " $commitish " " $repository " " $subdirectory " " $old_subdirectory "
7282
7383# Then, fetch the new flambda-backend sources (which include ocaml-jst) and
7484# copy into upstream/ocaml_flambda
@@ -77,7 +87,12 @@ rev=$(git rev-parse FETCH_HEAD)
7787cd upstream/ocaml_flambda
7888echo $rev > base-rev.txt
7989for file in $( git ls-tree --name-only -r HEAD | grep -v base-rev.txt) ; do
80- git show " FETCH_HEAD:$subdirectory /$file " > " $file " ;
90+ if [[ " $subdirectory " = " ." ]]; then
91+ git_file=" $file "
92+ else
93+ git_file=" $subdirectory /$file "
94+ fi
95+ git show " FETCH_HEAD:$git_file " > " $file "
8196done
8297git add -u .
8398cd ../..
0 commit comments