Skip to content

Commit

Permalink
Merge pull request #4402 from rjbou/opamfile-loc-var
Browse files Browse the repository at this point in the history
New package variable: `opamfile`
  • Loading branch information
rjbou committed Oct 27, 2020
2 parents d0ea615 + 70bbe1b commit 15e9a7a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/pages/Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ the package being defined.
- <a id="pkgvar-build-id">`build-id`</a>:
a hash identifying the precise package version and metadata, and that of all
its dependencies
- <a id="pkgvar-opamfile">`opamfile`</a>:
if the package is installed, path of its opam file, from opam internals,
otherwise not defined

Extra variables can be defined by any package at installation time, using a
[`<pkgname>.config`](#lt-pkgname-gt-config) file with a
Expand Down
2 changes: 1 addition & 1 deletion master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ New option/command/subcommand are prefixed with ◈.
*

## Var
*
* Add `opamfile-loc` as a package variable, containing the location of installed package opam file [#4402 @rjbou]

## Option

Expand Down
16 changes: 16 additions & 0 deletions src/state/opamPackageVar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ let package_variable_names = [
"dev", "True if this is a development package";
"build-id", "A hash identifying the precise package version with all its \
dependencies";
"opamfile", "Path of the curent opam file";
]

let predefined_depends_variables =
Expand Down Expand Up @@ -305,6 +306,21 @@ let resolve st ?opam:opam_arg ?(local=OpamVariable.Map.empty) v =
with Not_found -> Some (string ""))
| "dev", Some opam -> Some (bool (is_dev_package st opam))
| "build-id", Some opam -> OpamStd.Option.map string (build_id st opam)
| "opamfile", Some opam ->
(* Opamfile path is retrieved from overlay directory for pinned packages,
or from temporary repository in /tmp *)
let repos_roots reponame =
match Hashtbl.find st.switch_repos.repos_tmp reponame with
| lazy repo_root -> repo_root
| exception Not_found ->
OpamRepositoryPath.root st.switch_global.root reponame
in
OpamFile.OPAM.get_metadata_dir ~repos_roots opam
|> OpamStd.Option.map (fun d ->
OpamFilename.Op.(d//"opam")
|> OpamFilename.to_string
|> string
)
| _, _ -> None
in
let make_package_local v =
Expand Down

0 comments on commit 15e9a7a

Please sign in to comment.