I have a SwiftPM issue which is driving me nuts.
Let’s say I have swift package project (no Xcode project involved). And let’s call it SDK from here. The SDK is laying in its own git repository.
So I want to build a Showcase App for that SDK by adding the SDK as a dependency, managing swift packages via Xcode not via a Package.swift file. The showcase is deployed to our QA team and they should be able to always test the latest development version of the SDK with that showcase.
So naturally I would configure the package dependency in Xcode by defining the branch develop.
So now, when I change something inside the SDK, push it onto the develop branch, and want to have that change available inside the showcase, I simply need to right click on the package inside the showcase and click Update Package and this works great.
Here comes the catch: This approach does not work on our Jenkins CI. I don’t know what I’m doing wrong here, but the xcodebuild command line tool won’t notice something changed on the develop branch of the SDK and would checkout the older revision.
What I tried so far:
I removed Package.resolved from git index and added it to .gitignore so after the git clone/checkout there should be no Package.resolved file
I removed ~/Library/Cache/org.swift.swiftpm and ~/Library/org.swift.swiftpm prior to the build
I am deleting any previously created workspace of the Jenkins Build Job prior to each build
We’re using Fastlane and so I am also explicitly setting the cloned source packages path to something inside my workspace to make sure the cloned sources are deleted on workspace clean-up via cloned_source_packages_path: "SourcePackages"
The generated xcodebuild command by Fastlane looks like this: $ xcodebuild -resolvePackageDependencies -scheme ScannerShowcase -project ScannerShowcase.xcodeproj -configuration Release -clonedSourcePackagesDirPath SourcePackage
The Fastlane gym summary looks like this:
I'd expect that if I delete all that cached packages and not having any Package.resolved file present xcodebuild would resolve the swift package to the latest revision available. Instead it seems there still is something cached somewhere and xcodebuild is using that cache.
Nothing worked so far. Does anybody have experienced this same issue and is able to provide any suggestions and/or help?
As it turns out there seems to be now way to achieve the same results with xcodebuild command line tool as with Xcode's Update Package or Update to Latest Versions.
The command line tools rely on data stored inside derived data while updating packages. Thanks to Gregory Higley's answer here I was able to solve the issue by deleting the derived data for that specific build job by
Keeping Showcase.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved out of git index,
adding Package.resolved to .gitignoreto keep it that way,
and adding the following stage to the declarative pipeline inside the Jenkins file:
stage('Clean up') {
steps {
script { env.DERIVED_DATA_PATH=sh(returnStdout: true, script: "xcodebuild -showBuildSettings | grep -m 1 BUILD_DIR | grep -oE \"/.*\" | sed 's|/Build/Products||'") }
echo "Derived data path is: ${env.DERIVED_DATA_PATH}"
// The above will return a folder with a name like /Users/you/Library/Developer/Xcode/DerivedData/MyProject-ehdkocavaenextdcrsaszjdmyssx
sh script: "rm -rf ${env.DERIVED_DATA_PATH}", label: "Removing derived project data ..."
}
}
Any other step I mentioned when asking the question wasn't necessary to achieve my goal:
No need to remove ~/Library/Cache/org.swift.swiftpm nor ~/Library/org.swift.swiftpm
No need to delete any prior created workspace on the build node
No need to to explicitly specify the SPM cloned source packages path via Fastlane with. cloned_source_packages_path: "SourcePackages"
Again big shout out to Gregory Higley for their approach.
Related
I'm using a module for my angular app called angular-translate. However, I've had to make a few small modifications to the source code to get everything working the way I'd like, and now I want to persist those changes on npm install. A colleague suggested that I fork the repo of the source code and point to my forked repo as a dependency, which I've tried in these ways, e.g.
npm install https://github.com/myRepo/angular-translate
npm install https://github.com/myRepo/angular-translate/archive/master.tar.gz
The first gives me a directory like this with no build. Just a package.json, .npmignore, and some markdown files
-angular-translate
.npmignore
.nvmrc
CHANGELOG.md
package.json
etc
The second npm install gives me the full repo, but again I don't get a build like when I use the command npm install angular-translate. I've seen some dicussion of running the prepublish script, but I'm not sure how to do this when installing all the modules. I've also tried publishing the fork as my own module to the npm registry, but again I get no build, and I'm not sure that's the right thing to do...
I apologise for my ignorance on the topic. I don't have a huge amount of experience with npm. Would love to get some feedback on this issue. It seems like it could be a common enough issue when modifications need to be made to a package's source code? Maybe there's a better solution?
Try npm install <ghusername>/<repoName>, where <ghUsername> is your GitHub username (without the #) and <repoName> is the name of the repository. That should correctly install it. You will most likely want to use the --save or --save-dev flag with the install command to save dependency in your package.json.
If that isn't working correctly, check the contents of your .npmignore file.
Don't panic if the install command takes a long time; installing from a git repository is slower than installing from the npm registry.
Edit:
Your problem is that in your case, dist/ is not committed to the repo (since it is in the .gitignore). That is where the actual code lives. dist/ is built from the files in src/ before the package is published to the npm registry, but dist/ is never committed to the repo.
It's ugly, but in this case you will have to remove dist/ from the .gitignore and then run:
npm run build
git add .
git commit
git push
(Ensure that you have run npm install first)
You then should be able to install from github.
There might be another way to do this using a prepare script, but I'm not sure if that's possible; I've never tried it. Edit: Cameron Tacklind has written an excellent answer detailing how to do this: https://stackoverflow.com/a/57829251/7127751
TL;DR use a prepare script
and don't forget package.json#files or .npmignore
Code published to npmjs.com is often not what's in the repository for the package. It is common to "compile" JavaScript source files into versions meant for general consumption in libraries. That's what's usually published to npmjs.com.
It is so common that it's a feature of npm to automatically run a "build" step before publishing (npm publish). This was originally called prepublish. It seems that Npm thought it would be handy to also run the prepublish script on an npm install since that was the standard way to initialize a development environment.
This ended up leading to some major confusion in the community. There are very long issues on Github about this.
In the end, in an effort to not change old behavior, they decided to add two more automatic scripts: prepublishOnly and prepare.
prepublishOnly does what you expect. It does not run on npm install. Many package maintainers just blindly switched to this.
But there was also this problem that people wanted to not depend on npmjs.com to distribute versions of packages. Git repositories were the natural choice. However it's common practice to not commit "compiled" files to git. That's what prepare was added to handle...
prepare is the correct way
If you have a repository with source files but a "build" step is necessary to use it,
prepare does exactly what you want in all cases (as of npm 4).
prepare: Run both BEFORE the package is packed and published, on local npm install without any arguments, and when installing git dependencies.
You can even put your build dependencies into devDependencies and they will be installed before prepare is executed.
Here is an example of a package of mine that uses this method.
Problems with .gitignore
There is one issue with this option that gets many people.
When preparing a dependency, Npm and Yarn will keep only the files that are listed in the files section of package.json.
One might see that files defaults to all files being included and think they're done.
What is easily missed is that .npmignore mostly overrides the files directive and, if .npmignore does not exist, .gitignore is used instead.
So, if you have your built files listed in .gitignore, like a sane person, and don't do anything else, prepare will seem broken.
If you fix files to only include the built files or add an empty .npmignore, you're all set.
My recommendation
Set files (or, by inversion, .npmignore) such that the only files actually published are those needed by users of the published package. Imho, there is no need to include uncompiled sources in published packages.
Original answer: https://stackoverflow.com/a/57503862/4612476
Update for those using npm 5:
As of npm#5, prepublish scripts are deprecated.
Use prepare for build steps and prepublishOnly for upload-only.
I found adding a "prepare": "npm run build" to scripts fixed all my problems.
Just use the command npm install git+https://git#github.com/myRepo/angular-translate.git. Thanks.
To piggyback off of #RyanZim's excellent answer, postinstall is definitely a valid option for this.
Either do one of the following:
Update the package.json in your forked repo to add a postinstall element to scripts. In here, run whatever you need to get the compiled output (Preferred).
Update your package.json, and add a postinstall that updates the necessary directory in node_modules.
If you've forked another persons repository, then it might be worth raising an issue to illustrate the issue that installing their package through GitHub does not work as it does not provide the necessary means to build the script. From there, they can either accept a PR to resolve this with a postinstall, or they can reject it and you can do #2.
If you are using yarn like me. Imagine that you want to use a package like this:
yarn add ghasemikasra39/gridfs-easy --save where the ghasemikasra39 is the username and gridfs-easy is the name of the repo
I'm testing the current buildroot 2016.02-rc2 release. It contains gstreamer1 packages for version 1.6.3, but I would like to build 1.7.2 instead. I successfully updated package definitions for gstreamer1 and the most important plugins to use 1.7.2. However gst-omx has only a 19 months old release archive for the version 1.2.0 for the direct download (https://gstreamer.freedesktop.org/src/gst-omx/) and it fails to compile. So I would like to use the latest version from git repo.
How can I do it? git repository contains a "common" submodule which buildroot's build system cannot handle as it seems. I thought about creating a new release tar.xz package, that would contain everything for building it like all other gstreamer packages, but couldn't find out how those tar.xz packages on the server are generated...
There is indeed no support for submodule in Buildroot, since most of the time, submodules should be packaged as separate packages.
So, for your own testing, you have two options:
1/ You can do a quick test by creating yourself a tarball that contains all the gst-omx source code (including the contents of the common/) subdirectory.
2/ You can package the gstreamer common stuff as a separate package, make your gst-omx package depend on it, and in a pre-configure hook, create a symlink $(#D)/common -> $(GSTREAMER_COMMON_DIR)
When we do "yo webapp" (assuming webapp generator is installed), it scaffold projects which contains file relevant to bower, grunt and then there is app folder, which we all know what's it about.
My question is, out of this structure what are the files that needs to be maintained in SCM, Should it be only app directory or should it whole structure ?(assuming there are no additional grunt task or any build file changes from earlier scaffolding)
Yeoman webapp generator will produce a .gitignore file which includes files that should not be committed to a SCM. This file includes the following directories:
node_modules
dist
.tmp
.sass-cache
bower_components
test/bower_components
It is clear that .tmp and .sass-cache have no reason to be in the repo as they both are only temporary.
There is however a discussion whether bower (and rarely node) dependencies should be checked in. For most projects I recommend not to.
Please note that in either case one should never change the packages directly in the bower_components or node_modules folder as any change will be lost at next bower install or npm install. A fork of the original project (either as a independent repo or to folder in the project - e.g. lib) is a better idea - a follow up pull request would then add a lot of karma :)
The dist folder with the build of the application may be committed depending on your deployment method. There is a very good guide on deployment on Yeoman site.
As a start, you should put everything into SCM with the exception of app/bower_components, test/bower_components and node_modules. All files under these directories come from public repo, either node or bower repo.
In this setup, whenever another developer checkout from SCM, he needs to run 2 commands: npm install and bower install. What I typically do is I create a file called install.sh (install.bat on Windows) and have these 2 commands inside this script file. In this way, when you find that you need to run more commands for initialization, you can easily add to this script file and new developers can just checkout and run install.sh.
In some cases, I found that I need to perform small modification to a public library. In this case, I will check this library inside bower_components into SCM as well. This is not common, but it happens.
so I'm working with PhoneGap on Eclipse and I'm having some issues "building the directory" to start programming. I'm following the steps from the original page but I don't understand some points (I'm Spanish and maybe it's a language problem) I usually can manage with it but after some tries this time I don't have any other chance than asking.
So this is the tutorial page https://github.com/davejohnson/phonegap-plugin-facebook-connect I'm stuck on the Android part.
3.- You'll need to build + include the Facebook Android SDK and build + patch the Facebook JavaScript SDK:
-First run *git submodule update --init* to initialize and pull down the versions of the JS and Android Facebook SDKs that work with this plugin; they will end up under lib/.
-Next, build the JS file. cd lib/facebook-js-sdk and run php all.js.php >> ../facebook_js_sdk.js. This will create the JS SDK file under lib/facebook_js_sdk.js. Please note: the output filename is important as the patch assumes that filename!
-cd .. and apply the patch file by running patch < facebook-js-patch.
This is the command git submodule update --init. I'm not sure where to run it, i've tryied on the terminal in all the proyect directories but it's allways returning the same problem: fatal: Not a git repository (or any of the parent directories): .git
If someone knows about this and can help me, i'd be so gratefull!!
Thank you.
Unfortunately those build instructions are old and need to be updated as the remainder of the steps do not work. Also if you are using the latest phonegap (now cordova-1.5.0.js) you will again run into problems.
If you're on a mac, this will be easy. Just hit up the github link you supplied above. Click the "clone in mac" button. You must have github for mac installed first! Once you do so, choose the place where you want it cloned and begin the clone. Now you have the latest from master. Since I'm using the cordova (latest phonegap build), I need the cordovachanges branch. In the github app you should be able to click branches > drop down on the cordovachanges branch and switch to it. Now all the plugin code should be mainly up to date. They're still patching and fixing things.
Follow the new directions. When you get to the build + include part, just open terminal, cd to the place where the git project was cloned to and "git submodule update --init" which will update the submodules. From there, the directions should work.
Today I switched from XCode 3 to XCode 4 and now I have a lot of problems with my projects, which were under version control in XCode 3. If you install XCode 4, it will remember all your repositories. The problem is, that the projects don't know, that they belong to a specific repository. The instructions of Apple are easy, but do not work:
If you have a working copy of a project that was checked out of Subversion or cloned from Git using the command line or another tool, you can add it to your Xcode SCM repository support. To do so, click the Add button (+) at the bottom of the navigation pane in the repository organizer and choose Add Working Copy.
If I choose the project directory, I get this:
The working copy could not be added because its repository could not be located.
Does anybody know what the problem is?
To avoid confusion, I want to make a few things clear: my projects were under version control in XCode 3 and it worked. I am also aware of the fact, that I could delete all my projects and check them out (I don't want to do that). I already tried to checkout a project, and then this project is automatically added as a working copy. However if I remove the reference and try to add the same (!!) project as a working copy again, it does not work either.
The key for me was quitting Xcode then following Apple's instructions exactly. In Terminal:
$ cd project_folder # project containing the .xcodeproj file
$ git init
$ git add . # note the dot after "add"
$ git commit -m 'Initial version text'
Then get back into Xcode, open the Organizer, et voilà — instant repository.
I was able to resolve this by quitting Xcode and then opening the repository organizer before opening my workspace. Then it worked and I could open my workspace with SVN integration.
In Terminal, you may get the error:
-bash: git: command not found
This is because the git tool (and svn too) are contained inside the Xcode.app bundle in XCode 4.5 or later. In order to run the contained tools you need to use the xcrun command. For example, to run the git commands mentioned in the posts above:
$ xcrun git init
$ xcrun git add .
$ xcrun git commit -m 'Initial
version text'
For more info, see this link:
http://www.cocoanetics.com/2012/07/you-dont-need-the-xcode-command-line-tools/
What I had to do was, as Udi pointed out, close Xcode and open the organizer before opening any projects. But then I had to add the repository and it's credentials first (SVN, in this case) before following the Apple directions you (mowidev) posted. After doing this, the working copy then appeared inside the listing for the SVN repository I'd added.
That ultimately linked in the two (Xcode project source control settings with the existing working copy it was using). Anything out of order ended up with Xcode thinking it was a Git repo (that also didn't exist).