Skip to content

Commit 773545e

Browse files
dotnet: Add flags for dotnet version and freedesktop SDK branch. (#346)
* dotnet: Add flags for dotnet and freedesktop sdk Adds the --freedesktop, -f, --dotnet, -d arguments to the script. Allows you to specify the dotnet version and which freedesktop sdk branch to use. * dotnet: update docs for arguments, usage. Adds section detailing arguments, updating some of the README to clarify usage. * Use f-strings instead of str.format. * Remove choices, add variables to ease bumping versions. * docs: Moved arguments section to bottom of README.
1 parent acb7a96 commit 773545e

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

dotnet/README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ Tool to automatically generate a `flatpak-builder` sources file from a .NET Core
44

55
## Requirements
66

7-
You need to have `org.freedesktop.Sdk` and `org.freedesktop.Sdk.Extension.dotnet` installed,
8-
both branch 18.08.
7+
You need to have `org.freedesktop.Sdk` and `org.freedesktop.Sdk.Extension.dotnet` installed.
8+
both branch 22.08 (21.08 is selectable by passing it in via the `--dotnet` or `-d` arguments)
99

1010
## Usage
1111

12-
Run `flatpak-dotnet-generator.py my-output-sources.json my.input.Desktop.csproj`. Then,
13-
you can use the sources file like this:
12+
Run `flatpak-dotnet-generator.py my-output-sources.json my.input.Desktop.csproj`.
13+
14+
Then, you can use the sources file like this:
1415

1516
```yaml
1617
modules:
@@ -22,6 +23,13 @@ modules:
2223
- my-output-sources.json
2324
```
2425
25-
As you can see, the sources file generated will have flatpak-builder save everything into
26-
the *nuget-sources* directory. If you want to change the directory name, run
27-
`flatpak-dotnet-generator.py` with `--destdir=my-destdir`.
26+
When using `dotnet build` or `dotnet publish` make sure you add the `--source nuget-sources` argument in order for `dotnet`
27+
to pick up the source files generated by this tool.
28+
29+
If you want to change the directory name, run `flatpak-dotnet-generator.py` with `--destdir=my-destdir`.
30+
31+
## Arguments
32+
- `--runtime` or `-r` The target [runtime](https://learn.microsoft.com/en-us/dotnet/core/rid-catalog#linux-rids) to restore packages for.
33+
- `--dotnet` or `-d` The target version of dotnet to use. (Defaults to latest LTS version)
34+
- `--freedesktop` or `-f` The target version of the freedesktop sdk to use. (Defaults to latest version)
35+
- `--destdir` The directory the generated sources file will save sources to `nuget-sources` by default.

dotnet/flatpak-dotnet-generator.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@
1313

1414

1515
def main():
16+
# Bump this to latest freedesktop runtime version.
17+
freedesktop_default = '22.08'
18+
# Bump this to an LTS dotnet version.
19+
dotnet_default = '6'
20+
1621
parser = argparse.ArgumentParser()
1722
parser.add_argument('output', help='The output JSON sources file')
1823
parser.add_argument('project', help='The project file')
1924
parser.add_argument('--runtime', '-r', help='The target runtime to restore packages for')
25+
parser.add_argument('--freedesktop', '-f', help='The target version of the freedesktop sdk to use',
26+
default=freedesktop_default)
27+
parser.add_argument('--dotnet', '-d', help='The target version of dotnet to use',
28+
default=dotnet_default)
2029
parser.add_argument('--destdir',
2130
help='The directory the generated sources file will save sources to',
2231
default='nuget-sources')
@@ -33,9 +42,9 @@ def main():
3342
'flatpak', 'run',
3443
'--env=DOTNET_CLI_TELEMETRY_OPTOUT=true',
3544
'--env=DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true',
36-
'--command=sh', '--runtime=org.freedesktop.Sdk//21.08', '--share=network',
37-
'--filesystem=host', 'org.freedesktop.Sdk.Extension.dotnet6//21.08', '-c',
38-
'PATH="${PATH}:/usr/lib/sdk/dotnet6/bin" LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib/sdk/dotnet6/lib" exec dotnet restore "$@"',
45+
'--command=sh', f'--runtime=org.freedesktop.Sdk//{args.freedesktop}', '--share=network',
46+
'--filesystem=host', f'org.freedesktop.Sdk.Extension.dotnet{args.dotnet}//{args.freedesktop}', '-c',
47+
f'PATH="${{PATH}}:/usr/lib/sdk/dotnet{args.dotnet}/bin" LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib/sdk/dotnet{args.dotnet}/lib" exec dotnet restore "$@"',
3948
'--', '--packages', tmp, args.project] + runtime_args)
4049

4150
for path in Path(tmp).glob('**/*.nupkg.sha512'):

0 commit comments

Comments
 (0)