-
Notifications
You must be signed in to change notification settings - Fork 30
Allow to build runtime from custom sdk #364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sergio-costas
wants to merge
3
commits into
ubuntu:gnome-42-2204
Choose a base branch
from
sergio-costas:allow-to-build-runtime-from-custom-sdk
base: gnome-42-2204
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,29 @@ | ||
| git clone -b gnome-42-2204 https://github.com/ubuntu/gnome-sdk.git gnome-42-2204 | ||
| # GNOME-42-2204 runtime | ||
|
|
||
| This snap builds the GNOME-42-2204 runtime from the corresponding GNOME-42-2204-SDK | ||
| snap. | ||
|
|
||
| By default, it will get the SDK from the store, from the CANDIDATE branch; but it is | ||
| possible to use a different SDK (for example, one built locally), by creating a folder | ||
| called `base-gnome-sdk`, putting it inside, and launching the | ||
| `local-build.py` script. It will create a new, modified `snapcraft.yaml` file in the, | ||
| project's root, clean the snapcraft build environment, build the new snap, and restore | ||
| the `snapcraft.yaml` file. This is useful if you do a change in the SDK and want | ||
| to test it, to ensure that everything works as expected and nothing breaks. | ||
|
|
||
| If the script finds several `snap` files inside the `base-gnome-sdk` folder, it will | ||
| use the most recent one, based on the modification time of the file. | ||
|
|
||
| Also, if the build must be done by an external script (like when using Github's CI), | ||
|
sergio-costas marked this conversation as resolved.
|
||
| then it is possible to call the `local-build.py` script with the `--prepare-only` | ||
| parameter. With it, it will just generate the modified `snapcraft.yaml` file in the | ||
| project folder, nothing else. | ||
|
|
||
| ## Getting the repository | ||
|
|
||
| To get the repository, just run: | ||
|
|
||
| git clone -b gnome-42-2204 https://github.com/ubuntu/gnome-sdk.git gnome-42-2204 | ||
|
|
||
| This branch is used to build [the gnome-42-2204 snap](https://launchpad.net/~desktop-snappers/+snap/gnome-42-2204), | ||
| which in turn uses the [the gnome-42-2204-sdk snap](https://launchpad.net/~desktop-snappers/+snap/gnome-42-2204-sdk). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # This script builds the gnome runtime snap using a local SDK snap. | ||
|
|
||
| import sys | ||
| import os | ||
| import subprocess | ||
| import yaml | ||
| import glob | ||
|
|
||
| def str_presenter(dumper, data): | ||
| """configures yaml for dumping multiline strings | ||
| Ref: https://stackoverflow.com/questions/8640959/how-can-i-control-what-scalar-form-pyyaml-uses-for-my-data | ||
| Ensures that the scripts are dumped in the right multiline format """ | ||
| if len(data.splitlines()) > 1: # check for multiline string | ||
| return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|') | ||
| return dumper.represent_scalar('tag:yaml.org,2002:str', data) | ||
|
|
||
| yaml.add_representer(str, str_presenter) | ||
| yaml.representer.SafeRepresenter.add_representer(str, str_presenter) # to use with safe_dum | ||
|
|
||
| BASE_CONFIG = 'snap/snapcraft.yaml' | ||
| MODIFIED_CONFIG = 'snapcraft.yaml' | ||
| BASE_SNAP_FOLDER = 'base-gnome-sdk' | ||
| SDK_FILE = None | ||
| PREPARE_ONLY_OPTION = '--prepare-only' | ||
|
|
||
| # If there is a modified snapcraft.yaml, delete it before re-generating it | ||
| if os.path.exists(f'./{MODIFIED_CONFIG}'): | ||
| os.remove(f'./{MODIFIED_CONFIG}') | ||
|
sergio-costas marked this conversation as resolved.
|
||
|
|
||
| last_time = None | ||
| # If there are more than one snap, use the most recent one | ||
| for fullpath in glob.glob(os.path.join(BASE_SNAP_FOLDER, "*.snap")): | ||
| now_time = os.path.getmtime(fullpath) | ||
| if (last_time is None) or (now_time > last_time): | ||
| SDK_FILE = fullpath | ||
| last_time = now_time | ||
|
|
||
| if SDK_FILE is None: | ||
| print(f'There is no valid SDK file in the {BASE_SNAP_FOLDER} folder. Aborting.', file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
| with open(f'./{BASE_CONFIG}', "r") as config_file: | ||
| config = yaml.load(config_file, Loader=yaml.Loader) | ||
|
|
||
|
sergio-costas marked this conversation as resolved.
|
||
| gnome_part = config['parts']['gnome-sdk'] | ||
|
|
||
| # remove the stage-snaps entry | ||
| del gnome_part['stage-snaps'] | ||
|
|
||
| version = config['name'].split('-')[1] | ||
| gnome_part['build-environment'] = gnome_part.get('build-environment', []) + [ | ||
| {'LOCAL_SDK_SNAP': SDK_FILE}, | ||
| {'sdk_version': version} | ||
| ] | ||
|
sergio-costas marked this conversation as resolved.
|
||
|
|
||
| try: | ||
| with open(f'./{MODIFIED_CONFIG}', "w") as config_file: | ||
| config_file.write(yaml.dump(config, Dumper=yaml.Dumper)) | ||
| if PREPARE_ONLY_OPTION not in sys.argv: | ||
| subprocess.call('snapcraft clean', shell=True) | ||
| subprocess.call('snapcraft pack -v', shell=True) | ||
|
sergio-costas marked this conversation as resolved.
Outdated
|
||
| finally: | ||
| if PREPARE_ONLY_OPTION not in sys.argv: | ||
|
sergio-costas marked this conversation as resolved.
|
||
| os.remove(f'./{MODIFIED_CONFIG}') | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.