Skip to content

Commit

Permalink
dotnet: Add flags for dotnet version and freedesktop SDK branch. (#346)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
ProjectSynchro committed Feb 24, 2023
1 parent acb7a96 commit 773545e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
22 changes: 15 additions & 7 deletions dotnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ Tool to automatically generate a `flatpak-builder` sources file from a .NET Core

## Requirements

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

## Usage

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

Then, you can use the sources file like this:

```yaml
modules:
Expand All @@ -22,6 +23,13 @@ modules:
- my-output-sources.json
```

As you can see, the sources file generated will have flatpak-builder save everything into
the *nuget-sources* directory. If you want to change the directory name, run
`flatpak-dotnet-generator.py` with `--destdir=my-destdir`.
When using `dotnet build` or `dotnet publish` make sure you add the `--source nuget-sources` argument in order for `dotnet`
to pick up the source files generated by this tool.

If you want to change the directory name, run `flatpak-dotnet-generator.py` with `--destdir=my-destdir`.

## Arguments
- `--runtime` or `-r` The target [runtime](https://learn.microsoft.com/en-us/dotnet/core/rid-catalog#linux-rids) to restore packages for.
- `--dotnet` or `-d` The target version of dotnet to use. (Defaults to latest LTS version)
- `--freedesktop` or `-f` The target version of the freedesktop sdk to use. (Defaults to latest version)
- `--destdir` The directory the generated sources file will save sources to `nuget-sources` by default.
15 changes: 12 additions & 3 deletions dotnet/flatpak-dotnet-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@


def main():
# Bump this to latest freedesktop runtime version.
freedesktop_default = '22.08'
# Bump this to an LTS dotnet version.
dotnet_default = '6'

parser = argparse.ArgumentParser()
parser.add_argument('output', help='The output JSON sources file')
parser.add_argument('project', help='The project file')
parser.add_argument('--runtime', '-r', help='The target runtime to restore packages for')
parser.add_argument('--freedesktop', '-f', help='The target version of the freedesktop sdk to use',
default=freedesktop_default)
parser.add_argument('--dotnet', '-d', help='The target version of dotnet to use',
default=dotnet_default)
parser.add_argument('--destdir',
help='The directory the generated sources file will save sources to',
default='nuget-sources')
Expand All @@ -33,9 +42,9 @@ def main():
'flatpak', 'run',
'--env=DOTNET_CLI_TELEMETRY_OPTOUT=true',
'--env=DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true',
'--command=sh', '--runtime=org.freedesktop.Sdk//21.08', '--share=network',
'--filesystem=host', 'org.freedesktop.Sdk.Extension.dotnet6//21.08', '-c',
'PATH="${PATH}:/usr/lib/sdk/dotnet6/bin" LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib/sdk/dotnet6/lib" exec dotnet restore "$@"',
'--command=sh', f'--runtime=org.freedesktop.Sdk//{args.freedesktop}', '--share=network',
'--filesystem=host', f'org.freedesktop.Sdk.Extension.dotnet{args.dotnet}//{args.freedesktop}', '-c',
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 "$@"',
'--', '--packages', tmp, args.project] + runtime_args)

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

0 comments on commit 773545e

Please sign in to comment.