How to update git subproject that is configured to head revision? - meson-build

In Meson, subprojects can be defined using wrap-files. The manual shows an example of a wrap-git file:
[wrap-git]
url = https://github.com/libfoobar/libfoobar.git
revision = head
I've set-up a local test project that sets up a subproject like the example above. All works well and Meson pulls in the subproject's repository, builds it, and links it with the test project executable.
However, when I push a new change to the subproject repository, Meson fails to pull in these changes automatically even though revision = head is specified in the wrap-file. To be clear, I did not really expect this to work.
What does work is manually removing the subproject's source code and then letting Meson reconfigure the project. This clones the subproject repository and thus pulls in updates. But sadly this is a manual action...
My question: when tracking the head revision in a git wrap-file of a subproject, how to pull updates automatically?

This is expected behavior. As per reference doc:
Once a subproject has been fetched, Meson will not update it
automatically. For example if the wrap file tracks a git branch, it
won't pull latest commits.
To pull latest version of all your subprojects at once, just run the
command:
$ meson subprojects update
If only selected are needed, add names after command:
$ meson subprojects update libfoo libbar
(this is in short, more details in the link)

Related

How to print all dependencies in meson?

I checked out a gtk project inside a docker and during meson build found many dependencies are missing eg. libwayland-dev, libxrandr-dev...
Because meson fails at the first missing dependency, I had to redo this over and over to get install the entire list of dependencies that will be looked for using pkg-config. And, in projects with multiple git submodules, this becomes a lengthy process.
Wondering if I'm doing this whole thing wrong or if there is a way to get to the complete list of dependencies.
To get dependencies for your project, from build directory run:
meson introspect --dependencies

Unable to get the wrap-file option in meson build system working

I was trying to cross compile glib for arm. It has a dependency on libffi, but found that a meson build for libffi was last updated 2 yrs back and there is a problem with what is available.
Therefore i had to define a wrap file to take the latest source of libffi.
My first idea was to use a wrap file as below -
[wrap-git]
directory=libffi
url=https://github.com/libffi/libffi
revision=head
p.s its the head revision that has the right source code for libffi. But it needed a meson revision and doesn't seem to take the head.
Therefore i went for the [wrap-file] option,
[wrap-file]
directory = libffi-3.3
source_url = https://github.com/libffi/libffi/releases/download/v3.3/libffi-3.3.tar.gz
source_filename = libffi-3.3.tar.gz
source_hash = 72fba7922703ddfa7a028d513ac15a85c8d54c8d67f55fa5a4802885dc652056
But still i get this error "Subproject exists but has no meson.build file" when doing a meson build.
This is the original wrap file that came alongwith glib.
[wrap-git]
directory=libffi
url=https://github.com/centricular/libffi.git
revision=meson
what is the easiest way to get a wrap file working.
As far I can see, someone forked project and added support for meson, named that branch meson, so revision is just a name of branch containing meson.build
Official project does not have support for meson.build. What is really happening is when you build your project that uses wrap git/file, that project is fetched/downloaded&unzip and it searches for meson.build to build that dependency for your project.
You have couple options:
Fork project and add support for meson (optionally: make PR to official project)
Install and use it as dependency
Use conan package manager to get your dependency, you can even integrate it with meson (https://conan.io/center/libffi/3.3/?user=&channel=)

How to increase a version of an npm package using Azure Devops pipeline

The pipeline is triggered by new commits to a master branch and publishes the package
Currently, the version is set manually and I'de be happy to have it set automatically.
What I thought at first was adding the following tasks to the pipeline:
checkout $Build.SourceBranch
run version patch --force
git push
This works and the version is really incremented properly, the thing is, it triggers another run of the pipeline, which will increment again, which will.. you get the idea, endless loop.
Is there a better way for doing that?
I've added the same tasks as mentioned in the question with a small change.
Apparently there is a way to skip the pipeline triggering, see here
So the npm version task looks like this:
version patch -m "Bump version to %s [skip ci]" --force
which prevents the next build from being triggered.
TIP: remember to give the 'author' (Azure DevOps user) permissions to Bypass policies when pushing if any.
Don't use the files in the source repo to keep track of the current/next version. I don't think you can break the loop easily, if you do.
You might be able to get away with running npm --no-git-tag-version version to increment the package.json version inside the build agent without the commit, so that you don't have a change you would have to push back to the origin. It should just change package.json and leave it dirty.
Wait until after the build has succeeded. Use a custom script task to extract the version from package.json, then git reset --hard (there is no reason to keep anything that has changed on the build server). While this will undo the change in package.json, you can now create a tag on the head that contains that version, then do a git push origin {tag-name} which should not introduce a new commit on the origin which would then re-trigger your pipeline.
Actually, I don't think a pipeline will be triggered just because a tag was added, but I honestly haven't tested it. I'm pretty sure it won't.
Sequence of tasks in your pipeline:
[Given a source repo where you have made sure to set the major and minor versions in package.json to reflect the current state of the code according to the rules of Semantic Versioning, and leave the patch value always set to 0, and, if desired, using pre-* values to describe the quality of the major/minor value:]
(This is not really a task, but just describing the start of the execution:) The job starts. Automatically, the code is pulled from the source repo into the build agent.
Using a utility command-line task and code or script that you write, run git describe --tags to find the most recent tag with a tagname matching the pattern you use (see below). (I prefer this sequence over calling npm version from-git because npm will just use the latest tag, which might not be a version number, depending on how much control you have over the branch.) Use string or regular expression operations to extract the major, minor, patch, and whatever pre-* value you might have. This is the previous version that we'll use to compare with what's in the package.json file. Note that you may have to follow these instructions to run a git command. Save it to a pipeline variable.
Using a utility command-line task and code or script that you write, run npm version to get the current major/minor/pre version out of the package.json file and save it to a different pipeline variable. I'm using PowerShell Core, so my command would look something like this to create a "currentPackageVersion" pipeline variable:
& npm.cmd version | ConvertFrom-Json | Select-Object -ExpandProperty {name-of-your-package} | Set-Variable -Name 'packageVersion' | Write-Output "#vso[task.setvariable variable=currentPackageVersion]$packageVersion"
Using a utility command-line task and code or script that you write, compare the previous version's major, minor, and pre-* values to determine whether any of them have changed. Set a new pipeline variable to reflect whether it has changed or not. I'll use the name "restartVersionPatchNumber", which is true if the current major, minor, or pre-* values are different from the previous version's major, minor, or pre-* values.
The npm Task conditionally runs a custom command: npm --no-git-tag-version version patch, which updates package.json in the build agent but does not commit the change, leaving your Working Area modified (dirty) (which might cause issues on subsequent builds if you are using your own build agents instead of hosted agents). The condition expression of the Task uses a custom condition that evaluates to the variable that I just set in the previous step ("restartVersionPatchNumber"). Note that if this task does not run, it should just use the value of the version that is in the package.json file (the current version that is now in the "currentPackageVersion" pipeline variable).
Using a utility command-line task and code or script that you write, run npm version to extract the new version that the npm version command set. Save it to a new pipeline variable; I'll call it "newVersionNumber".
The regular build tasks run, producing artifacts and possibly publishing them
Using a utility command-line task, run git reset --hard. You'll need to do this even if you're using a hosted build agent, because of the next step.
Using a utility command-line task, create a variable from the saved version number ("newVersionNumber") that contains the value of the tag's tagname that you want to use. Use a distinctive patter, like "AzPipelineBuild-PipelineName-PackageVersion-1.0.0" but using your version instead of 1.0.0.
Using a utility command-line task, run git tag {*tagname*}. For PowerShell, the syntax would be & git.exe tag $env:newVersionNumber
Using a utility command-line task, run git push origin {*tagname*}
Profit
You could (and maybe should) combine the command-line steps. I'm really partial to the PowerShell task running PowerShellCore (pwsh) as you may have guessed.
The package that got created as an artifact of the job will have the updated version as it was created in the build, and it will match the tag that is now in your original source code repo.
Alternately, use an external source (an Azure Function, etc.) or a different (second) git repo or even another branch that isn't tied to your CI trigger in your project that you use just for tracking build numbers, then use token replacement tasks to set the version just before you start the build. I don't like this idea much, but it would prevent re-triggering a new build.
Also, you're hopefully building just one package with that repo. The next thing to do is to publish that package to your Azure Artifacts feed, or npmjs.org or wherever. Don't rely on having the version baked into the original source code; anything that depends on that package should be pulling it out of that feed you published it to, not relying on it being built earlier in the build steps with a new version number.
Here's my implementation in Powershell which is a complete step based on the accepted answer. Note that this also handles some of the git issues such as the detached head that comes with this type of approach.
steps:
- checkout: self
persistCredentials: true
.
.
.
- task: PowerShell#2
displayName: 'Bump the version'
inputs:
targetType: 'inline'
script: |
$BranchName = "$(Build.SourceBranch)" -replace "refs/heads/"
git checkout $BranchName
git config --global user.email "anymail#anycompany.com"
git config --global user.name "Your name"
npm version prerelease -m "Auto increment pre-release version to %s [skip ci]" --force
git push

update location scm url for maven multi module project

I have a maven multi module project. If I need to branch, I use the maven-versions plugin to go through my project and update the parent version number rather easily. Is there a similar plugin to update my scm location in all of my poms?
Why don't you use the Maven Release Plugin and its release:branch mojo for that? From the Create a branch page:
Creating a branch executes the
following steps:
Check that there are no uncommitted changes in the sources
Change the version in the poms if you want to change it in the branch
(you will be prompted for the versions
to use)
Transform the SCM information in the POM to include the final destination
of the tag
Commit the modified POMs
Tag the code in the SCM as a new branch with a version name (this will
be prompted for)
Bump the version in the POMs if you want to change it to a new value
y-SNAPSHOT (these values will also be
prompted for)
Commit the modified POMs

CMake build fails if it can't reach dependency repo

I have a CMake project (myapp) that depends on another CMake project (integrator). The integrator project is declared via the ExternalProject_Add and I use the GIT_TAG parameter to indicate what version of the integrator code to build. This works great while online. But, I run into build fail problems if I'm ever offline. It always fails the build if it can't reach the git repo, even if it had previously downloaded a copy of the repo. Can I make CMake stop reaching out to the GIT_TAG repo and just build with the code it had previously downloaded when I was last online?
Based on the documentation of ExternalProject, there is an option named UPDATE_DISCONNECTED.
If UPDATE_DISCONNECTED is set, the update step is not executed
automatically when building the main target. The update step can still
be added as a step target and called manually. This is useful if you
want to allow to build the project when you are disconnected from the
network (you might still need the network for the download step). This
is disabled by default.
Therefore, you should add the option setting
UPDATE_DISCONNECTED 1
to your ExternalProject_Add declaration in order to be able to work offline.