Skip to content

Commit

Permalink
src_ext: Remove unused/untested Makefile targets
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed May 27, 2024
1 parent 21305bb commit d5142f8
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 371 deletions.
5 changes: 2 additions & 3 deletions .github/scripts/main/hygiene.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ esac
###

(set +x ; echo -en "::group::check src_ext patches\r") 2>/dev/null
# Check that the lib-ext/lib-pkg patches are "simple"
# Check that the lib-ext patches are "simple"
make -C src_ext PATCH="busybox patch" clone
make -C src_ext PATCH="busybox patch" clone-pkg
# Check that the lib-ext/lib-pkg patches have been re-packaged
# Check that the lib-ext patches have been re-packaged
cd src_ext
../shell/re-patch.sh
if [[ $(find patches -name \*.old | wc -l) -ne 0 ]] ; then
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci.ml
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ let cold_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job ?
++ cache Archives
++ run "Cold" [
"make compiler";
"make lib-pkg";
"bash -exu .github/scripts/main/main.sh " ^ host]
++ run "Test (basic)" ["bash -exu .github/scripts/main/test.sh"]
++ end_job f
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ jobs:
- name: Cold
run: |
make compiler
make lib-pkg
bash -exu .github/scripts/main/main.sh x86_64-pc-linux-gnu
- name: Test (basic)
run: bash -exu .github/scripts/main/test.sh
Expand Down
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ tests/reftests/.merlin
.envrc
src_ext/*.*download
src_ext/*.*stamp
src_ext/*.pkgbuild
src_ext/*.tar.gz
src_ext/*.tbz
src_ext/0install-solver/
src_ext/archives/*
src_ext/base64/
src_ext/camlp4
src_ext/cmdliner/
src_ext/cppo/
src_ext/cudf/
Expand All @@ -28,7 +26,6 @@ src_ext/extlib/
src_ext/findlib
src_ext/lib
src_ext/mccs/
src_ext/ocamlbuild
src_ext/ocamlgraph/
src_ext/opam-0install-cudf/
src_ext/jsonm/
Expand All @@ -42,7 +39,6 @@ src_ext/sha/
src_ext/spdx_licenses/
src_ext/stdlib-shims/
src_ext/swhid_core/
src_ext/topkg/
Opam.Runtime.*/
*.tar.bz2
*.annot
Expand Down
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,9 @@ opam-admin.top: $(DUNE_DEP)
lib-ext:
$(MAKE) -j -C src_ext lib-ext

lib-pkg:
$(MAKE) -j -C src_ext lib-pkg

download-ext:
$(MAKE) -C src_ext cache-archives

download-pkg:
$(MAKE) -C src_ext archives-pkg

clean-ext:
$(MAKE) -C src_ext distclean

Expand Down
2 changes: 0 additions & 2 deletions Makefile.config.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ mandir = @mandir@
version = @PACKAGE_VERSION@
FETCH = @fetch@

PACKS = $(filter-out no,@OCAML_PKG_unix@ @OCAML_PKG_extlib@ @OCAML_PKG_re@ @OCAML_PKG_re_glob@ @OCAML_PKG_cmdliner@ @OCAML_PKG_ocamlgraph@ @OCAML_PKG_cudf@ @OCAML_PKG_dose3_common@ @OCAML_PKG_dose3_algo@ @OCAML_PKG_opam_file_format@ @OCAML_PKG_mccs@)

CONF_OCAMLFLAGS = @CONF_OCAMLFLAGS@

MCCS_ENABLED = @MCCS_ENABLED@
Expand Down
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,9 @@ The `OCAML_PORT` variable determines which flavour of Windows OCaml is compiled;
(i.e., the native C compiler *for Cygwin*), `OCAML_PORT` does not need to be
specified and `auto` will be assumed. Once the compiler is built, you may run:
```
make lib-pkg
./configure --with-vendored-deps
```
to install the dependencies as `findlib` packages to the compiler. Building `lib-pkg`
requires the ability to create native symbolic links (and the `CYGWIN` variable
*must* include `winsymlinks:native`). This means that either Cygwin must be run
elevated from an account with administrative privileges, or your user account must be
granted the _SeCreateSymbolicLinkPrivilege_ either by enabling Developer mode on
Windows 10 or using Local Security Policy on earlier versions of Windows.
Alternatively, you may run `configure` and use vendored deps, as advised.

You can then `configure` and build opam as above.
and build opam as above.

## Compiling Without OCaml

Expand Down
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ users)

## Build
* Upgrade vendored cmdliner to 1.3.0 [#5970 @kit-ty-kate]
* Remove unused/untested Makefile targets lib-pkg [#5494 @kit-ty-kate]

## Infrastructure
* Ensure GNU coreutils available on the macOS 14 CI runners [#5938 @dra27]
Expand Down
4 changes: 0 additions & 4 deletions shell/re-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ for package in $(cd patches ; find . -maxdepth 1 -mindepth 1 -type d | sed -e 's

# Determine which directories contain patches and which modes to test (lib-pkg/lib-ext)
locs=''
if [[ -d patches/$package.common ]] ; then
locs="../patches/$package.common/*.patch"
modes="stamp pkgstamp"
fi
if [[ -d patches/$package ]] ; then
modes=${modes:-stamp}
libext_locs="../patches/$package/*.patch"
Expand Down
23 changes: 10 additions & 13 deletions src_ext/HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,33 @@ Files related to the dependency vendoring are kept in the `src_ext` directory. T
- `shell/bootstrap-ocaml.sh` - assembles an OCaml compiler in `bootstrap/`
- `shell/re-patch.sh` - when run from the `src_ext/` directory, normalises all the patch files (eliminating git-specific features, etc.)

## lib-ext and lib-pkg
## Mode of operation

There are two modes of operation. `lib-ext` uses Dune vendoring and assembles the dependencies of opam in subdirectories of `src_ext/`, allowing Dune to build them with opam. In this mode, only the `opam` binary can then be installed: the libraries are not installable (as with all Dune vendoring with libraries). `lib-pkg` installs the libraries to a given compiler using either `dune install` (for dependencies which use Dune) or `ocamlfind install` for any others. This mode is typically used to install dependencies to the compiler built in `bootstrap/` by `shell/bootstrap-ocaml.sh`. In `lib-pkg`, the dependency's preferred build system is used, in `lib-ext`, the package must use Dune.
We use Dune vendoring and assembles the dependencies of opam in subdirectories of `src_ext/`, allowing Dune to build them with opam. Only the `opam` binary can then be installed: the libraries are not installable (as with all Dune vendoring with libraries).

## Patching

Package sources have patches applied from two places. For package `foo`, the patches in `src_ext/foo.common` and then patches in `src_ext/foo` (for `lib-ext` mode) or `src_ext/foo.pkg` (for `lib-pkg` mode) are applied (within those directories, patches apply in the order returned by shell globbing). Patches placed here are either to back-port the package to an older version of OCaml than upstream supports, or to back-port a fix from an unreleased version of package.
Package sources have patches applied from two places. For package `foo`, the patches in `src_ext/foo` are applied (within those directories, patches apply in the order returned by shell globbing). Patches placed here are either to back-port the package to an older version of OCaml than upstream supports, or to back-port a fix from an unreleased version of package.

In `lib-ext` mode, `dune` files can be dropped into the extracted package sources, after patching, by creating a file named `src_ext/dune-foo`. If the package needs dropping in a subdirectory, then these can be appended to the filename, using `-` instead of `/`. For example, `src_ext/dune-foo-src-lib` will be copied to `src/lib/dune` when package `foo` is extracted.
`dune` files can be dropped into the extracted package sources, after patching, by creating a file named `src_ext/dune-foo`. If the package needs dropping in a subdirectory, then these can be appended to the filename, using `-` instead of `/`. For example, `src_ext/dune-foo-src-lib` will be copied to `src/lib/dune` when package `foo` is extracted.

Finally, `src_ext/Makefile` provides an opportunity for package-specific commands to be run by adding specific commands to the `.stamp` targets. See, for example, the horrors in [f721385](https://github.com/ocaml/opam/commit/f721385).

## Updating the dependencies

`src_ext/update-sources.sh` will attempt to use repository data from your current opam switch to automatically update `src_ext/Makefile.sources`. For some packages, the script may make the wrong determination (e.g. cudf 0.9, where opam's sources stick with the original gforge source archive), so the changes suggested should be reviewed carefully! After updating the dependencies, it's important to check that the patches still work. These can be triggered manually with `make clone` (for `lib-ext`) or `make clone-pkg` (for `lib-pkg`). If a patch no longer applies, it needs to be updated or replaced (e.g. by rebasing a git commit and using `git format-patch` or by manually applying the changes to a clean worktree and using `diff -Naur`, etc.). Once the patches are correct and `make clone` is working, run `../shell/re-patch.sh` to normalise the patches. This script will apply the patches as given and then regenerate them using `diff`.
`src_ext/update-sources.sh` will attempt to use repository data from your current opam switch to automatically update `src_ext/Makefile.sources`. For some packages, the script may make the wrong determination (e.g. cudf 0.9, where opam's sources stick with the original gforge source archive), so the changes suggested should be reviewed carefully! After updating the dependencies, it's important to check that the patches still work. These can be triggered manually with `make clone`. If a patch no longer applies, it needs to be updated or replaced (e.g. by rebasing a git commit and using `git format-patch` or by manually applying the changes to a clean worktree and using `diff -Naur`, etc.). Once the patches are correct and `make clone` is working, run `../shell/re-patch.sh` to normalise the patches. This script will apply the patches as given and then regenerate them using `diff`.

## Dune and mccs

The Dune vendored dependency is a special case: firstly, in lib-ext mode it's optional and secondly the package is called `dune-local`. The name avoids conflict with a directory called `dune` (which Dune itself can't cope with). mccs is also a special case, because it's optional in lib-ext mode.
The Dune vendored dependency is a special case: firstly, it's optional and secondly the package is called `dune-local`. The name avoids conflict with a directory called `dune` (which Dune itself can't cope with). mccs is also a special case, because it's optional.

## Adding a new dependency

1. Add the tarball information to `src_ext/Makefile.sources`. If the package is used in `lib-ext` mode, define `URL_package` and `MD5_package`. If the same package is used in `lib-pkg` mode, add `$(call PKG_SAME,package)`, otherwise define `URL_PKG_package` and `MD5_PKG_package`. If a package is only used in `lib-pkg` mode, don't define `URL_package` and `MD5_package`.
2. Add `package` to `SRC_EXTS` or `PKG_EXTS in `src_ext/Makefile`.
3. Put any requires patches in `src_ext/patches/` (in `package.common/` for both modes, `package/` for `lib-ext` mode and `package.pkg/` for `lib-pkg` mode).
1. Add the tarball information to `src_ext/Makefile.sources`. Define `URL_package` and `MD5_package`.
2. Add `package` to `SRC_EXTS` in `src_ext/Makefile`.
3. Put any requires patches in `src_ext/patches/` (in `package/`).
4. If the package's build system is not Dune, create `src_ext/dune-package`. The build system `touch`es `package.opam` when assembling the sources.
5. Add a `package.pkgbuild:` entry to `src_ext/Makefile.packages` containing the dependencies of `package`.
6. Add a `package-pkg-build:` target with the build steps for building and installing `package`. Various utility variables are available in `src_ext/Makefile.packages`, in particular `$(OCAMLBIN)` is the compiler's `bin` directory and `$(SITELIB)` is the ocamlfind library root (effectively `%{lib}%` in opam) and `$(OCAMLROOT)` is the actual prefix of the compiler's installation.

## Testing

* For `lib-pkg` mode: run `make compiler`, backup `bootstrap` directory, and run `make lib-pkg`
* For `lib-ext` mode: run `./configure --with-vendored-deps`, then `make`
run `./configure --with-vendored-deps`, then `make`
111 changes: 7 additions & 104 deletions src_ext/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
ifneq ($(wildcard ../Makefile.config)$(filter-out archives cache-archives lib-pkg,$(MAKECMDGOALS)),)
ifneq ($(wildcard ../Makefile.config)$(filter-out archives cache-archives,$(MAKECMDGOALS)),)
-include ../Makefile.config
endif

ifneq ($(wildcard Makefile.config),)
include Makefile.config
CAN_PKG=1
else
CAN_PKG=0
endif

PATCH ?= patch
Expand All @@ -25,32 +22,18 @@ ifndef FETCH
endif
endif

# Shorthand for designating that lib-ext and lib-pkg use the same version of a library
PKG_SAME = $(eval $(call PKG_SAME_DEFS,$(1)))
define PKG_SAME_DEFS
URL_PKG_$(1) = $(URL_$(1))
MD5_PKG_$(1) = $(MD5_$(1))
endef

SRC_EXTS = cppo base64 extlib re cmdliner ocamlgraph cudf dose3 opam-file-format seq stdlib-shims spdx_licenses opam-0install-cudf 0install-solver uutf jsonm sha swhid_core
PKG_EXTS = $(SRC_EXTS) dune-local findlib ocamlbuild topkg mccs

ifeq ($(MCCS_ENABLED),true)
SRC_EXTS := $(SRC_EXTS) mccs
endif

include Makefile.sources
ifneq ($(shell PATH="$(PATH)" command -v ocamlc 2>/dev/null),)
include Makefile.packages
endif

ARCHIVES = $(foreach lib,$(SRC_EXTS),$(notdir $(URL_$(lib))))
lib_of = $(foreach lib,$(SRC_EXTS),$(if $(findstring $(1),$(URL_$(lib))),$(lib),,))

ARCHIVE_FILE = $(1)$(patsubst %.tbz,.tbz,$(patsubst %.tar.gz,.tar.gz,$(URL_$(2)$(1))))
DOWNLOAD_COOKIE = touch $(1).$(4)download && \
$(if $(filter $(MD5_$(2)$(1)),$(MD5_$(3)$(1))),touch,rm -f) $(1).$(5)download && \
rm -f $(call ARCHIVE_FILE,$(1),$(2)) $(1).stamp $(1).pkgbuild

SILENT ?=

Expand Down Expand Up @@ -82,25 +65,6 @@ else
$(error Re-run configure --with-vendored-deps)
endif

ifeq ($(CAN_PKG),1)
lib-pkg: clone-pkg build-pkg
@
else
lib-pkg:
@echo "Installation of packages is only permitted for the bootstrap compiler"
@echo "Run $(MAKE) [OCAML_PORT=auto|msvc|msvc64|mingw|mingw64] compiler first"
@false
endif

.PHONY: lib-pkg-urls
lib-pkg-urls:
@$(foreach i,$(PKG_EXTS),$(info $i $(URL_PKG_$i)))
@find patches -type f | grep '\.\(pkg\|common\)/' | xargs sha1sum

reset-lib-pkg:
@rm -f ../bootstrap/ocaml/bin/ocamlbuild* ../bootstrap/ocaml/bin/ocamlfind* `ls ../bootstrap/ocaml/bin/* | grep -v "flexlink\|\/ocaml[^\/]*$$"` ../bootstrap/ocaml/lib/topfind
@rm -rf ../bootstrap/ocaml/lib/ocaml/site-lib ../bootstrap/ocaml/etc *.pkgbuild

ifeq ($(DUNE),)
DUNE_DEP=dune-local/_boot/dune$(EXE)
DUNE_CLONE=dune-local.stamp
Expand All @@ -117,47 +81,24 @@ endif
dune-local/_boot/dune$(EXE): $(DUNE_CLONE)
cd dune-local && ocaml boot/bootstrap.ml

build-pkg: clone-pkg $(PKG_EXTS:=.pkgbuild)
@

%.pkgbuild: | %.pkgstamp
@rm -f $*.pkgstamp
$(MAKE) MAKEFLAGS= -f ../Makefile.packages -C $* $*-pkg-build && touch $@

.PHONY: def-ignore
def-ignore:
@echo "; This file is automatically generated" > dune
@echo "(dirs :standard \ $(SRC_EXTS),$(PKG_EXTS))" >> dune

.PHONY: ext-ignore
ext-ignore:
@echo "; This file is automatically generated" > dune
@echo "(dirs :standard \ dune-local $(filter-out dune-local $(SRC_EXTS),$(PKG_EXTS)))" >> dune
@echo "(dirs :standard \ dune-local)" >> dune
@echo "(vendored_dirs $(SRC_EXTS))" >> dune

.PHONY: clone
clone: $(DUNE_CLONE) $(SRC_EXTS:=.stamp) | ext-ignore
@true

.PHONY: pkg-ignore
pkg-ignore:
@echo "; This file is automatically generated" > dune
@echo "(dirs :standard \ $(PKG_EXTS))" >> dune

clone-pkg: $(PKG_EXTS:=.pkgstamp) | pkg-ignore
@

.PHONY: archives
archives: $(DUNE_CLONE:.stamp=.download) $(SRC_EXTS:=.download)
@true

archives-pkg: $(PKG_EXTS:=.pkgdownload)
cache-archives: $(SRC_EXTS:=.cache) ocaml.cache flexdll.cache
@

cache-archives: $(SRC_EXTS:=.cache) $(PKG_EXTS:=.pkgcache) ocaml.cache flexdll.cache
@

has-archives: $(addprefix archives/, $(notdir $(URL_ocaml)) $(notdir $(URL_flexdll)) $(ARCHIVES) $(filter-out $(ARCHIVES), $(foreach pkg,$(PKG_EXTS), $(notdir $(URL_PKG_$(pkg))))))
has-archives: $(addprefix archives/, $(notdir $(URL_ocaml)) $(notdir $(URL_flexdll)) $(ARCHIVES))
@

define cache_url
Expand All @@ -176,34 +117,17 @@ GET_ARCHIVE=\
@test -e archives/$(notdir $(URL_$*)) || \
{ $(call GET_ARCHIVE,$*) && mv $(call ARCHIVE_FILE,$*) archives/$(notdir $(URL_$*)); }

%.pkgcache:
@mkdir -p archives
@test -e archives/$(notdir $(URL_PKG_$*)) || \
{ $(call GET_ARCHIVE,$*,PKG_) && mv $(call ARCHIVE_FILE,$*,PKG_) archives/$(notdir $(URL_PKG_$*)); }

.PRECIOUS: %.download
%.download: Makefile.sources
@$(call DOWNLOAD_COOKIE,$*,,PKG_,,pkg)
$(SILENT)[ -e $(call ARCHIVE_FILE,$*) ] || \
cp archives/$(notdir $(URL_$*)) $(call ARCHIVE_FILE,$*) 2>/dev/null || $(call GET_ARCHIVE,$*)

%.pkgdownload: Makefile.sources
@$(call DOWNLOAD_COOKIE,$*,PKG_,,pkg)
[ -e $(call ARCHIVE_FILE,$*,PKG_) ] || \
cp archives/$(notdir $(URL_PKG_$*)) $(call ARCHIVE_FILE,$*,PKG_) 2>/dev/null || $(call GET_ARCHIVE,$*,PKG_)

%.stamp: %.download
$(SILENT)mkdir -p tmp-$*
$(SILENT)cd tmp-$* && $(if $(patsubst %.tar.gz,,$(URL_$*)),bunzip2,gunzip) -c ../$(call ARCHIVE_FILE,$*) | tar xf -
$(SILENT)rm -rf $*
@for ii in tmp-$*/*; do if [ -d $${ii} ]; then mv $${ii} $*; fi; done; \
rm -rf tmp-$*
@if [ -d patches/$*.common ]; then \
cd $* && \
for p in ../patches/$*.common/*.patch; do \
$(PATCH) -p1 < $$p $(if $(SILENT),> /dev/null); \
done; \
fi
@if [ -d patches/$* ]; then \
cd $* && \
for p in ../patches/$*/*.patch; do \
Expand All @@ -218,34 +142,13 @@ GET_ARCHIVE=\
touch $*/$*.opam; \
done; \
fi
@touch $@ && rm -f $*.pkgstamp $*.pkgbuild

%.pkgstamp: %.pkgdownload
mkdir -p tmp-$*
cd tmp-$* && tar xf$(if $(patsubst %.tar.gz,,$(call ARCHIVE_FILE,$*,PKG_)),j,z) ../$(call ARCHIVE_FILE,$*,PKG_)
rm -rf $*
# On Cygwin, the mv has a tedious habit of sometimes failing, hence the slightly odd repetition
@for ii in tmp-$*/*; do if [ -d $${ii} ]; then mv $${ii} $* || mv $${ii} $*; fi; done; \
rm -rf tmp-$*
@if [ -d patches/$*.common ]; then \
cd $* && \
for p in ../patches/$*.common/*.patch; do \
$(PATCH) -p1 < $$p; \
done; \
fi
@if [ -d patches/$*.pkg ]; then \
cd $* && \
for p in ../patches/$*.pkg/*.patch; do \
$(PATCH) -p1 < $$p; \
done; \
fi
@touch $@ && rm -f $*.stamp
@touch $@

clean:
@

distclean: clean
rm -rf dune-local secondary $(SRC_EXTS) $(PKG_EXTS)
rm -f *.tar.gz *.tbz *.*stamp *.*download *.pkgbuild dune \
rm -rf dune-local secondary $(SRC_EXTS)
rm -f *.tar.gz *.tbz *.*stamp *.*download dune \
Makefile.config
[ -d archives ] && ([ "$$(find archives -maxdepth 0 -type d -empty)" != "" ] && rmdir archives || echo "WARNING! $$(pwd)/archives/ not empty so left") || true
Loading

0 comments on commit d5142f8

Please sign in to comment.