Can anyone advise on variable syntax in RPM patch? - rpm-spec

I have the following patch referenced in my spec file. It works with proxy hardcoded but I need to use a variable, which fails. Can anyone please advise on the correct syntax?
diff --git .yarnrc.yml .yarnrc.yml
index 6cc7483..b560e95 100644
--- .yarnrc.yml
+++ .yarnrc.yml
## -1,4 +1,8 ##
enableTelemetry: false
+enableStrictSsl: false
+networkConcurrency: 1
+httpProxy: %{http_proxy}
+httpsProxy: %{https_proxy}
nodeLinker: pnp
UPDATE:
Comments don't seem to format well so throwing latest incarnation taking onboard reply from Aaron here, which also fails to build (in jenkins). Edited patch verified in jenkins console.
From spec file
%prep
%setup -n %{name}-%{version}
sed -i 's|httpProxy:.*|httpProxy: "'$http_proxy'"|g' %{PATCH0}
sed -i 's|httpsProxy:.*|httpsProxy: "'$https_proxy'"|g' %{PATCH0}
%patch0
Revised patch
diff --git .yarnrc.yml .yarnrc.yml
index 6cc7483..7c3f6df 100644
--- .yarnrc.yml
+++ .yarnrc.yml
## -1,4 +1,9 ##
enableTelemetry: false
+enableStrictSsl: false
+networkConcurrency: 1
+httpProxy: ******
+httpsProxy: ******
nodeLinker: pnp

RPM isn't going to replace those lines in the diff file; you will need some script or something to do that for you before the build. Or you can put it in as part of your %build macro like sed -i -e "s/_HTTP_PROXY_/%{http_proxy}/g" .yarnrc.yml where the yml file you have in your source has a placeholder _HTTP_PROXY_ ...

Related

How to assign patch to specified git source?

In my foo_git.bb:
SRC_URI = "git://github.com/foo/foo.git;branch=main;protocol=https;name=${BPN};destsuffix=git \
git://github.com/foo2/foo2;branch=main;protocol=https;name=${FOO2};destsuffix=${FOO2} \
file://0001-Modify-A_value.patch\
"
I want my patch to apply to foo2 but it always applied to foo. ( patch failed )
I found patchdir appended after the patch can work.
ex:
file://0001-Modify-A_value.patch;patchdir=${WORKDIR}/${FOO2_path}
From the OE manual
Patch files will be copied to ${S}/patches and then applied to source from within the source directory, ${S}. so for your use case to work your patch filenames should include their base repo name.
For example let’s say 0001-Modify-A_value.patch is as follows:
diff --git a/my.txt b/my.txt
index fa5cb9a..59369cc 100644
--- a/my.txt
+++ b/my.txt
## -1 +1 ##
-I am foo who lives in bar
+I am bar who lives in foo
To make it apply to foo2 you must modify it as follows:
--- foo2/my.txt
+++ foo2/my.txt
## -1 +1 ##
-I am foo who lives in bar
+I am bar who lives in foo
Bitbake uses Quilt for patching so for errors and so on look at its manual.
Another handy tool by bitbake to help you further is the devtool which is designed to handle tasks like updating a recipe or patching it.

How to get release notes from Semantic Release output using grep command

I am trying to automate the release of software using semantic-release. Everything is working fine. I run this command npx semantic-release --no-ci --dry-run and get the following output in the terminal
...some other output
[1:01:55 pm] [semantic-release] › ⚠ Skip v0.1.1 tag creation in dry-run mode
[1:01:55 pm] [semantic-release] › ✔ Published release 0.1.1 on default channel
[1:01:55 pm] [semantic-release] › ℹ Release note for version 0.1.1:
## 0.1.1 (2021-01-24)
### Bug Fixes
* ravgeet is fixing things (92797f6)
* removed unwanted files (bdcc9ff)
* this is another fix (dbef2fd)
Now I need to get the release notes from the output
## 0.1.1 (2021-01-24)
### Bug Fixes
* ravgeet is fixing things (92797f6)
* removed unwanted files (bdcc9ff)
* this is another fix (dbef2fd)
How can I do so using grep command or any other means?
With GNU sed.
| sed -n '/^##/,$p'
-n: Do not output anything unless it is explicitly stated (here with command p)
x,yp: You can replace x and y with a regex (here: /^##/), a line number or a special character like $. $ matches here last line in input.
/^##/: regex for lines starting with two #
p output sed's pattern space (current line).
| sed '/^##/,$!d'is a more compact notation. I translate !d with don't delete.
See: man sed and The Stack Overflow Regular Expressions FAQ

How to update modules.conf for SELINUX in BUILDROOT?

looking to disable some SELinux modules (set to off) and create others in modules.conf. I don't see an obvious way of updating modules.conf as I tried adding my changes as a modules.conf patch but it failed given that the modules.conf file gets built and is not just downloaded by BR so it is not available for patching like other things under the refpolicy directory:
Build window output:
refpolicy 2.20190609 PatchingApplying 0001-refpolicy-update-modules-conf.patch using patch:
can't find file to patch at input line 3
I did see in the log that there is a support/sedoctool.py that autogenerates the policy/modules.conf file so that the file is NOT patchable like most other things in the ref policy.
The relevant section of the buildroot/output/build/refpolicy-2.20190609/Makefile:
# policy building support tools
support := support
genxml := $(PYTHON) $(support)/segenxml.py
gendoc := $(PYTHON) $(support)/sedoctool.py
<...snip...>
########################################
#
# Create config files
#
conf: $(mod_conf) $(booleans) generate$(booleans) $(mod_conf): conf.intermediate.INTERMEDIATE: conf.intermediate
conf.intermediate: $(polxml)
#echo "Updating $(booleans) and $(mod_conf)"
$(verbose) $(gendoc) -b $(booleans) -m $(mod_conf) -x $(polxml)
Part of the hsmlinux build.log showing the sedoctool.py (gendoc) being run:
Updating policy/booleans.conf and policy/modules.conf
.../build-buildroot-sawshark/buildroot/output/host/usr/bin/python3 support/sedoctool.py -b policy/booleans.conf -m policy/modules.conf -x doc/policy.xml
I'm sure there is a standard way of doing this, just doesn't seem to be documented anywhere I can find.
Thanks.
Turns out that the sedoctool.py script is reading the doc/policy.xml. Looking at sedoctool.py:
#modules enabled and disabled values
MOD_BASE = "base"
MOD_ENABLED = "module"
MOD_DISABLED = "off"
<...snip...>
def gen_module_conf(doc, file_name, namevalue_list):
"""
Generates the module configuration file using the XML provided and the
previous module configuration.
"""
# If file exists, preserve settings and modify if needed.
# Otherwise, create it.
<...snip...>
mod_name = node.getAttribute("name")
mod_layer = node.parentNode.getAttribute("name")
<...snip...>
if mod_name and mod_layer:
file_name.write("# Layer: %s\n# Module: %s\n" % (mod_layer,mod_name))
if required:
file_name.write("# Required in base\n")
file_name.write("#\n")
if [mod_name, MOD_DISABLED] in namevalue_list:
file_name.write("%s = %s\n\n" % (mod_name, MOD_DISABLED))
# If the module is set as enabled.
elif [mod_name, MOD_ENABLED] in namevalue_list:
file_name.write("%s = %s\n\n" % (mod_name, MOD_ENABLED))
# If the module is set as base.
elif [mod_name, MOD_BASE] in namevalue_list:
file_name.write("%s = %s\n\n" % (mod_name, MOD_BASE))
So sedoctool.py has the nice feature of: "# If file exists, preserve settings and modify if needed." and modules.conf can just be added whole here via a complete file patch and the modules that are not desired set as "off" : refpolicy-2.20190609/policy/modules.conf and the script will update as needed based on desired policy.
One more detail is that in the next stage of the refpolicy Makefile (Building) the modules.conf with the updates is deleted in the beginning which kind of clashes with the ability of sedoctool to preserve the patched version of modules.conf...so patched the removal in the Building stage of the Makefile.
[7m>>> refpolicy 2.20190609 Building^[
<...snip...>
rm -f policy/modules.conf
The Makefile in refpolicy-2.20190609 has this line that I patched out because we are patching in our own modules.conf:
bare: clean
<...snip...>
$(verbose) rm -f $(mod_conf)
That patch looks like:
--- BUILDROOT/Makefile 2020-08-17 13:25:06.963804709 -0400
+++ FIX/Makefile 2020-08-17 19:25:29.540607763 -0400
## -636,7 +636,6 ##
$(verbose) rm -f $(modxml)
$(verbose) rm -f $(tunxml)
$(verbose) rm -f $(boolxml)
- $(verbose) rm -f $(mod_conf)
$(verbose) rm -f $(booleans)
$(verbose) rm -fR $(htmldir)
$(verbose) rm -f $(tags)
BTW,
Creating a patch with a complete new file in pp1:q!:
diff -crB --new-file pp0 pp1 > pp0.patch

Mercurial - meaning of tokens?

Please see the attached image (courtesy HgInit's Mercurial tutorial).
What does it mean by
--- a
+++ b
## -1,4 +1,4 ##
--- a/guac - the outgoing file (the first version to be compared), in this case, since it is about two versions of the same file, a virtual path prefix a/ is prefixed, even when it doesn't exist actually
+++ b/guac - the incoming file (the second version to be compared)
## -1,4 +1,4 ## - the outgoing and incoming line ranges, meaning in this case -1,4 the outgoing/original/first version refers to line 1 and 4 following lines, while +1,4 the incoming/new/second version refers to the same range. Meaning that you'll end up with the same amount of lines (after taking out those with - prefix and putting in those with + prefix, in the rest of the diff chunk)

Patch semantics

I've made a patch by using diff:
diff -u /home/user/onderzoeksstage/omf/Rakefile /home/user/onderzoeksstage/Rakefile > rakefile2.patch
I've placed this rakefile2.patch in another directory: /home/user/onderzoeksstage/omf/confine/patches.
Now, I was under the assumption that I could go to that directory where all my patches are collected, call patch < rakefile2.patch and patch would known where to find the file to patch (the original file /home/user/onderzoeksstage/omf/Rakefile) by reading out the rakefile2.patch header.
But when doing that, patch says that it does not find the file to patch:
[user#localhost patches]$ patch < rakefile2.patch
can't find file to patch at input line 3
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|--- /home/user/onderzoeksstage/omf/Rakefile 2013-02-12 14:11:49.809792527 +0100
|+++ /home/user/onderzoeksstage/Rakefile 2013-02-12 12:17:50.314831492 +0100
--------------------------
File to patch: ...
...
So my assumption was obviously wrong, but so how does patch work?
When going to /home/user/onderzoeksstage/omf/ and calling patch < rakefile2.patch does work. Does patch only look at the header for the filename at the end of the path and not take in account the directory? And so what I try to accomplish will never work?
Why is this; is this because that way a patch could be applied to any file called Rakefile (e.g. in my case) and so make it a more "generic" patch?
Thanks
Does patch only look at the header for the filename at the end of the
path and not take in account the directory?
That's what it does by default. See the description of -p option in man patch. Looks like -p0 is what you want here.