Skip to content

Commit 9a89dec

Browse files
committed
CP-51479: [maintenance]: install SDK files using dune rules
Avoid copying twice, get dune to install the files to the correct destination in one go. Also add a copy of XE_SR_ERRORCODES.xml, by default 'make install' would look for this in /opt/xensource, and writing there requires root. (This can be overriden with `./configure --share`). Since we are using `dune` to install the files now we need the file to always be present. Had to adjust the paths used by the CI. Uses dune directory targets, and the directory must be entirely under the control of these rules. There are some static files in autogen/ though, so move the generated ones to autogen-out, and then use 'cp -r' to copy over the static ones (there is no builtin dune action for the copy, there are individual copy actions, or a copy_files rule, but neither is suitable here) Signed-off-by: Edwin Török <[email protected]>
1 parent 5ae3648 commit 9a89dec

25 files changed

+1034
-70
lines changed

.github/workflows/generate-and-build-sdks.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,34 @@ jobs:
3232
with:
3333
name: SDK_Source_C
3434
path: |
35-
_build/install/default/xapi/sdk/c/*
36-
!_build/install/default/xapi/sdk/c/dune
35+
_build/install/default/share/c/*
36+
!_build/install/default/share/c/dune
3737
3838
- name: Store C# SDK source
3939
uses: actions/upload-artifact@v4
4040
with:
4141
name: SDK_Source_CSharp
42-
path: _build/install/default/xapi/sdk/csharp/*
42+
path: _build/install/default/share/csharp/*
4343

4444
- name: Store PowerShell SDK source
4545
uses: actions/upload-artifact@v4
4646
with:
4747
name: SDK_Source_PowerShell
48-
path: _build/install/default/xapi/sdk/powershell/*
48+
path: _build/install/default/share/powershell/*
4949

5050
- name: Store Go SDK Artifacts
5151
uses: actions/upload-artifact@v4
5252
with:
5353
name: SDK_Artifacts_Go
5454
path: |
55-
_build/install/default/xapi/sdk/go/*
56-
!_build/install/default/xapi/sdk/go/dune
55+
_build/install/default/share/go/*
56+
!_build/install/default/share/go/dune
5757
5858
- name: Store Java SDK source
5959
uses: actions/upload-artifact@v4
6060
with:
6161
name: SDK_Source_Java
62-
path: _build/install/default/xapi/sdk/java/*
62+
path: _build/install/default/share/java/*
6363

6464
- name: Trim dune cache
6565
run: opam exec -- dune cache trim --size=2GiB

.github/workflows/go-ci/action.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ runs:
1111
uses: golangci/golangci-lint-action@v4
1212
with:
1313
version: v1.57.2
14-
working-directory: ${{ github.workspace }}/_build/install/default/xapi/sdk/go/src
14+
working-directory: ${{ github.workspace }}/_build/install/default/share/go/src
1515
args: --config=${{ github.workspace }}/.golangci.yml
1616

1717
- name: Run CI for Go SDK
1818
shell: bash
1919
run: |
2020
cd ./ocaml/sdk-gen/component-test/
21-
cp -r ${{ github.workspace }}/_build/install/default/xapi/sdk/go/src jsonrpc-client/go/goSDK
22-
bash run-tests.sh
21+
cp -r ${{ github.workspace }}/_build/install/default/share/go/src jsonrpc-client/go/goSDK
22+
bash run-tests.sh

.github/workflows/sdk-ci/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ runs:
1717
- name: Run CI for Go SDK
1818
uses: ./.github/workflows/go-ci
1919

20-
# Run other tests here
20+
# Run other tests here

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ python3/examples/XenAPI.egg-info/
2121
python3/examples/build/
2222
python3/examples/dist/
2323

24-
# ignore file needed for building the SDK
25-
ocaml/sdk-gen/csharp/XE_SR_ERRORCODES.xml
26-
2724
# configure-generated files
2825
ocaml/xenopsd/scripts/vif
2926
ocaml/xenopsd/scripts/xen-backend.rules

Makefile

+8-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
include config.mk
22

3-
XAPIDOC=_build/install/default/xapi/doc
4-
XAPISDK=_build/install/default/xapi/sdk
3+
XAPIDOC=_build/install/default/usr/share/xapi/doc
4+
XAPISDK=_build/install/default/usr/share/xapi/sdk
55
JOBS = $(shell getconf _NPROCESSORS_ONLN)
66
PROFILE=release
77
OPTMANDIR ?= $(OPTDIR)/man/man1/
@@ -12,6 +12,8 @@ OPTMANDIR ?= $(OPTDIR)/man/man1/
1212
# this is typically used when we're not building from a git repo
1313
build:
1414
[ -z "${XAPI_VERSION}" ] || (sed -i '/(version.*)/d' dune-project && echo "(version ${XAPI_VERSION})" >> dune-project)
15+
# if available use external file, otherwise use built-in, this allows building XAPI without being root
16+
! test -f $(SHAREDIR)/sm/XE_SR_ERRORCODES.xml || cp $(SHAREDIR)/sm/XE_SR_ERRORCODES.xml ocaml/sdk-gen/csharp/XE_SR_ERRORCODES.xml
1517
dune build @ocaml/idl/update-dm-lifecycle -j $(JOBS) --profile=$(PROFILE) --auto-promote || dune build @ocaml/idl/update-dm-lifecycle -j $(JOBS) --profile=$(PROFILE) --auto-promote
1618
dune build @install -j $(JOBS) --profile=$(PROFILE)
1719
dune build @ocaml/xapi-storage/python/xapi/storage/api/v5/python --profile=$(PROFILE)
@@ -96,33 +98,17 @@ doc:
9698
dune build --profile=$(PROFILE) -f @man
9799

98100
sdk:
99-
cp $(SHAREDIR)/sm/XE_SR_ERRORCODES.xml ocaml/sdk-gen/csharp/XE_SR_ERRORCODES.xml
100-
dune build --profile=$(PROFILE) -f @sdkgen
101-
rm -rf $(XAPISDK)
102-
mkdir -p $(XAPISDK)/c
103-
mkdir -p $(XAPISDK)/csharp
104-
mkdir -p $(XAPISDK)/java
105-
mkdir -p $(XAPISDK)/powershell
106-
mkdir -p $(XAPISDK)/python
107-
mkdir -p $(XAPISDK)/go
108-
cp -r _build/default/ocaml/sdk-gen/c/autogen/* $(XAPISDK)/c
109-
cp -r _build/default/ocaml/sdk-gen/csharp/autogen/* $(XAPISDK)/csharp
110-
cp -r _build/default/ocaml/sdk-gen/java/autogen/* $(XAPISDK)/java
111-
cp -r _build/default/ocaml/sdk-gen/powershell/autogen/* $(XAPISDK)/powershell
112-
cp -r _build/default/ocaml/sdk-gen/go/autogen/* $(XAPISDK)/go
113-
cp python3/examples/XenAPI/XenAPI.py $(XAPISDK)/python
114-
sh ocaml/sdk-gen/windows-line-endings.sh $(XAPISDK)/csharp
115-
sh ocaml/sdk-gen/windows-line-endings.sh $(XAPISDK)/powershell
101+
dune build --profile=$(PROFILE) @sdkgen xapi-sdk.install @ocaml/sdk-gen/install
116102

117103
.PHONY: sdk-build-c
118104

119105
sdk-build-c: sdk
120-
cd _build/install/default/xapi/sdk/c && make clean && make -j $(JOBS)
106+
cd _build/install/default/share/c && make clean && make -j $(JOBS)
121107

122108
.PHONY: sdk-build-java
123109

124110
sdk-build-java: sdk
125-
cd _build/install/default/xapi/sdk/java && mvn -f xen-api/pom.xml -B clean package install -Drevision=0.0
111+
cd _build/install/default/share/java && mvn -f xen-api/pom.xml -B clean package install -Drevision=0.0
126112

127113
python:
128114
$(MAKE) -C python3/examples build
@@ -260,9 +246,7 @@ install: build doc sdk doc-json
260246
cp -r $(XAPIDOC)/markdown $(DESTDIR)$(DOCDIR)
261247
cp $(XAPIDOC)/*.dot $(XAPIDOC)/doc-convert.sh $(DESTDIR)$(DOCDIR)
262248
# sdk
263-
mkdir -p $(DESTDIR)$(SDKDIR)
264-
cp -r $(XAPISDK)/* $(DESTDIR)$(SDKDIR)
265-
find $(DESTDIR)$(SDKDIR) -type f -exec chmod 644 {} \;
249+
dune install --destdir=$(DESTDIR) --datadir=$(SDKDIR) xapi-sdk
266250
find $(DESTDIR) -name '*.cmxs' -delete
267251

268252
uninstall:

dune

+6
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@
1717
; Can still be used for dependencies, but dune won't scan these dirs
1818
; for dune files
1919
(data_only_dirs doc scripts python3 .vscode)
20+
21+
(install
22+
(package xapi-sdk)
23+
(section share_root)
24+
(files (python3/examples/XenAPI/XenAPI.py as python/XenAPI.py))
25+
)

dune-project

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
(formatting (enabled_for ocaml))
44
(using menhir 2.0)
5+
(using directory-targets 0.1)
56

67
(cram enable)
78
(implicit_transitive_deps false)

ocaml/doc/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# A note on generating locally the API reference
22

33
Run `make doc` in the repo root. This will output the API reference in html and
4-
markdown formats in `_build/install/default/xapi/doc`.
4+
markdown formats in `_build/install/default/usr/share/xapi/doc`.
55

66
Both html and markdown reference images which need to be generated as a separate
77
step from the `.dot` files. This requires `graphviz` to be installed.
88

99
To generate the images, run `sh doc-convert.sh` in
10-
`_build/install/default/xapi/doc`. Now you can view the API reference by opening
11-
`_build/install/default/xapi/doc/html/index.html` in your browser.
10+
`_build/install/default/usr/share/xapi/doc`. Now you can view the API reference by opening
11+
`_build/install/default/usr/share/xapi/doc/html/index.html` in your browser.

ocaml/sdk-gen/c/dune

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,23 @@
1212

1313
(rule
1414
(alias generate)
15+
(package xapi-sdk)
16+
(targets (dir autogen-out))
1517
(deps
1618
(:x gen_c_binding.exe)
1719
(source_tree templates)
20+
(source_tree autogen)
1821
)
19-
(action (run %{x}))
22+
(action (concurrent
23+
(bash "cp -r autogen/ autogen-out/")
24+
(run %{x})
25+
))
2026
)
2127

2228
(data_only_dirs templates)
29+
30+
(install
31+
(package xapi-sdk)
32+
(section share_root)
33+
(dirs (autogen-out as c))
34+
)

ocaml/sdk-gen/c/gen_c_binding.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module TypeSet = Set.Make (struct
1616
let compare = compare
1717
end)
1818

19-
let destdir = "autogen"
19+
let destdir = "autogen-out"
2020

2121
let templates_dir = "templates"
2222

ocaml/sdk-gen/component-test/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jsonrpc-client is a client that imports the SDK and runs the functions, followin
5151

5252
5. To support the SDK component test, it recommended to move the SDK generated to a sub directory as a local module for import purposes, eg:
5353
```
54-
cp -r ${{ github.workspace }}/_build/install/default/xapi/sdk/go/src jsonrpc-client/go/goSDK
54+
cp -r ${{ github.workspace }}/_build/install/default/share/go/src jsonrpc-client/go/goSDK
5555
```
5656
then, import the local module.
5757
```

0 commit comments

Comments
 (0)